From bcd9cd3f3fbdd8cf58ab1dca11b878d7057ea40b Mon Sep 17 00:00:00 2001 From: adityajai119 Date: Thu, 12 Nov 2026 23:15:59 +0530 Subject: [PATCH] Split proxy request paths on / instead of path.sep The base path of /proxy/ requests was computed by splitting the request path on path.sep, which is a backslash on Windows, so the whole path became the base. Requests were proxied to / on the target port and redirects were rewritten against the wrong base. URL paths always use /. Fixes #8122 --- src/node/routes/pathProxy.ts | 5 ++--- test/unit/node/proxy.test.ts | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/node/routes/pathProxy.ts b/src/node/routes/pathProxy.ts index 4f84b3f87e71..ebe88b56f32c 100644 --- a/src/node/routes/pathProxy.ts +++ b/src/node/routes/pathProxy.ts @@ -1,5 +1,4 @@ import { Request, Response } from "express" -import * as path from "path" import { HttpCode, HttpError } from "../../common/http" import { ensureProxyEnabled, authenticated, ensureAuthenticated, ensureOrigin, redirect, self } from "../http" import { proxy as _proxy } from "../proxy" @@ -46,7 +45,7 @@ export async function proxy( // The base is used for rewriting (redirects, target). if (!opts?.passthroughPath) { - ;(req as any).base = req.path.split(path.sep).slice(0, 3).join(path.sep) + ;(req as any).base = req.path.split("/").slice(0, 3).join("/") } _proxy.web(req, res, { @@ -68,7 +67,7 @@ export async function wsProxy( // The base is used for rewriting (redirects, target). if (!opts?.passthroughPath) { - ;(req as any).base = req.path.split(path.sep).slice(0, 3).join(path.sep) + ;(req as any).base = req.path.split("/").slice(0, 3).join("/") } _proxy.ws(req, req.ws, req.head, { diff --git a/test/unit/node/proxy.test.ts b/test/unit/node/proxy.test.ts index 3807fe77e0a0..b1cf90612a2e 100644 --- a/test/unit/node/proxy.test.ts +++ b/test/unit/node/proxy.test.ts @@ -64,6 +64,24 @@ describe("proxy", () => { expect(json).toBe("asher is the best") }) + it("should rewrite the base path when the path separator is a backslash", async () => { + const nodePath = jest.requireActual("path") + const sep = nodePath.sep + nodePath.sep = "\\" + try { + e.get("/wsup", (req, res) => { + res.json("asher is the best") + }) + codeServer = await integration.setup(["--auth=none"], "") + const resp = await codeServer.fetch(proxyPath) + expect(resp.status).toBe(200) + const json = await resp.json() + expect(json).toBe("asher is the best") + } finally { + nodePath.sep = sep + } + }) + it("should not rewrite the base path", async () => { e.get(absProxyPath, (req, res) => { res.json("joe is the best")