From 227a0054001fc2dbbb65520fc354d2323c653459 Mon Sep 17 00:00:00 2001 From: Zaid Humaimidi Date: Thu, 7 Mar 2024 13:27:06 -0800 Subject: [PATCH] Fix exception when URL has two trailing slashes --- lib/ui.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/ui.ts b/lib/ui.ts index 11f4e9d..f7f5e04 100644 --- a/lib/ui.ts +++ b/lib/ui.ts @@ -45,6 +45,10 @@ koa.on("error", (err, ctx) => { setTimeout(() => { // Ignored errors resulting from aborted requests if (ctx?.req.aborted) return; + + // Ignore client errors (e.g. malicious path) + if (err.status === 400) return; + throw err; }); }); @@ -203,6 +207,10 @@ router.post("/init", async (ctx) => { }); router.get("/", async (ctx) => { + // koa-router seems to tolerate double slashes in the URL but that can + // be problematic when using relatives asset paths in HTML + if (ctx.path.endsWith("//")) return; + const permissionSets: PermissionSet[] = ctx.state.authorizer.getPermissionSets();