Skip to content

Commit 2ec1e2d

Browse files
Rafael Calpena Rodriguescode-asher
Rafael Calpena Rodrigues
andauthored
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 <ash@coder.com>
1 parent c69f2c6 commit 2ec1e2d

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/node/routes/index.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,17 @@ export const register = async (app: App, args: DefaultedArgs): Promise<Disposabl
9494
app.router.use("/", domainProxy.router)
9595
app.wsRouter.use("/", domainProxy.wsRouter.router)
9696

97-
app.router.all("/proxy/(:port)(/*)?", (req, res) => {
98-
pathProxy.proxy(req, res)
97+
app.router.all("/proxy/(:port)(/*)?", async (req, res) => {
98+
await pathProxy.proxy(req, res)
9999
})
100100
app.wsRouter.get("/proxy/(:port)(/*)?", async (req) => {
101101
await pathProxy.wsProxy(req as pluginapi.WebsocketRequest)
102102
})
103103
// These two routes pass through the path directly.
104104
// So the proxied app must be aware it is running
105105
// under /absproxy/<someport>/
106-
app.router.all("/absproxy/(:port)(/*)?", (req, res) => {
107-
pathProxy.proxy(req, res, {
106+
app.router.all("/absproxy/(:port)(/*)?", async (req, res) => {
107+
await pathProxy.proxy(req, res, {
108108
passthroughPath: true,
109109
})
110110
})

src/node/routes/pathProxy.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ const getProxyTarget = (req: Request, passthroughPath?: boolean): string => {
1414
return `http://0.0.0.0:${req.params.port}/${req.params[0] || ""}${query ? `?${query}` : ""}`
1515
}
1616

17-
export function proxy(
17+
export async function proxy(
1818
req: Request,
1919
res: Response,
2020
opts?: {
2121
passthroughPath?: boolean
2222
},
23-
): void {
24-
if (!authenticated(req)) {
23+
): Promise<void> {
24+
if (!(await authenticated(req))) {
2525
// If visiting the root (/:port only) redirect to the login page.
2626
if (!req.params[0] || req.params[0] === "/") {
2727
const to = self(req)

0 commit comments

Comments
 (0)