Skip to content

Commit 0acbc64

Browse files
committed
fix: the /proxy/:port and /absproxy/:port endpoints ... in index.ts
The /proxy/:port and /absproxy/:port endpoints allow authenticated users to proxy requests to arbitrary ports on localhost
1 parent eb4ba56 commit 0acbc64

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

src/node/routes/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ export const register = async (
9090
// TODO: This does *NOT* work if you have a base path since to specify the
9191
// protocol we need to specify the whole path.
9292
if (args.cert && !(req.connection as tls.TLSSocket).encrypted) {
93-
return res.redirect(`https://${req.headers.host}${req.originalUrl}`)
93+
const host = String(req.headers.host || "").replace(/[^\w.\-:[\]]/g, "")
94+
return res.redirect(`https://${host}${req.originalUrl}`)
9495
}
9596
next()
9697
})

src/node/routes/pathProxy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const getProxyTarget = (
1515
const base = (req as any).base || ""
1616
// Cast since we only have one port param.
1717
const port = parseInt(req.params.port as string, 10)
18-
if (isNaN(port)) {
18+
if (isNaN(port) || port < 1024 || port > 65535) {
1919
throw new HttpError("Invalid port", HttpCode.BadRequest)
2020
}
2121
return `http://0.0.0.0:${port}${opts?.proxyBasePath || ""}/${req.originalUrl.slice(base.length)}`

0 commit comments

Comments
 (0)