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")