Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/node/routes/pathProxy.ts
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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, {
Expand All @@ -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, {
Expand Down
18 changes: 18 additions & 0 deletions test/unit/node/proxy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading