From 2ec1e2de34671dd01dc5fd0d1f96bc99120bcc8c Mon Sep 17 00:00:00 2001 From: Rafael Calpena Rodrigues Date: Wed, 10 Aug 2022 21:05:49 -0300 Subject: [PATCH] fix: authentication check in path proxy (#5442) `proxy` should `await` for result of `authenticated` call otherwise since otherwise it will always appear to be authenticated as the promise is truthy. Co-authored-by: Asher --- src/node/routes/index.ts | 8 ++++---- src/node/routes/pathProxy.ts | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/node/routes/index.ts b/src/node/routes/index.ts index 13d53df86..a2046b6a7 100644 --- a/src/node/routes/index.ts +++ b/src/node/routes/index.ts @@ -94,8 +94,8 @@ export const register = async (app: App, args: DefaultedArgs): Promise { - pathProxy.proxy(req, res) + app.router.all("/proxy/(:port)(/*)?", async (req, res) => { + await pathProxy.proxy(req, res) }) app.wsRouter.get("/proxy/(:port)(/*)?", async (req) => { await pathProxy.wsProxy(req as pluginapi.WebsocketRequest) @@ -103,8 +103,8 @@ export const register = async (app: App, args: DefaultedArgs): Promise/ - app.router.all("/absproxy/(:port)(/*)?", (req, res) => { - pathProxy.proxy(req, res, { + app.router.all("/absproxy/(:port)(/*)?", async (req, res) => { + await pathProxy.proxy(req, res, { passthroughPath: true, }) }) diff --git a/src/node/routes/pathProxy.ts b/src/node/routes/pathProxy.ts index 6c20ab6b3..e21b849ec 100644 --- a/src/node/routes/pathProxy.ts +++ b/src/node/routes/pathProxy.ts @@ -14,14 +14,14 @@ const getProxyTarget = (req: Request, passthroughPath?: boolean): string => { return `http://0.0.0.0:${req.params.port}/${req.params[0] || ""}${query ? `?${query}` : ""}` } -export function proxy( +export async function proxy( req: Request, res: Response, opts?: { passthroughPath?: boolean }, -): void { - if (!authenticated(req)) { +): Promise { + if (!(await authenticated(req))) { // If visiting the root (/:port only) redirect to the login page. if (!req.params[0] || req.params[0] === "/") { const to = self(req)