Skip to content

Commit a43d2d7

Browse files
fix: V-006 security vulnerability
Automated security fix generated by Orbis Security AI
1 parent 02f4d6e commit a43d2d7

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/node/routes/index.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { App } from "../app"
1111
import { AuthType, DefaultedArgs } from "../cli"
1212
import { commit, rootPath } from "../constants"
1313
import { Heart } from "../heart"
14-
import { redirect } from "../http"
14+
import { redirect, ensureAuthenticated } from "../http"
1515
import { CoderSettings, SettingsProvider } from "../settings"
1616
import { UpdateProvider } from "../update"
1717
import { getMediaMime, paths } from "../util"
@@ -58,7 +58,7 @@ export const register = async (
5858
app.router.use(cookieParser())
5959
app.wsRouter.use(cookieParser())
6060

61-
const settings = new SettingsProvider<CoderSettings>(path.join(args["user-data-dir"], "coder.json"))
61+
const settings = new SettingsProvider<CoderSettings>(args["user-data-dir"] + path.sep + "coder.json")
6262
const updater = new UpdateProvider("https://api.github.com/repos/coder/code-server/releases/latest", settings)
6363

6464
const cookieSessionName = getCookieSessionName(args["cookie-suffix"])
@@ -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(/[^a-zA-Z0-9.:\-[\]]/g, "")
94+
return res.redirect(`https://${host}${req.originalUrl}`)
9495
}
9596
next()
9697
})
@@ -114,6 +115,7 @@ export const register = async (
114115
await pathProxy.proxy(req, res)
115116
})
116117
app.wsRouter.get("/proxy/:port{/*path}", async (req) => {
118+
await ensureAuthenticated(req)
117119
await pathProxy.wsProxy(req as unknown as WebsocketRequest)
118120
})
119121
// These two routes pass through the path directly.
@@ -126,6 +128,7 @@ export const register = async (
126128
})
127129
})
128130
app.wsRouter.get("/absproxy/:port{/*path}", async (req) => {
131+
await ensureAuthenticated(req)
129132
await pathProxy.wsProxy(req as unknown as WebsocketRequest, {
130133
passthroughPath: true,
131134
proxyBasePath: args["abs-proxy-base-path"],

0 commit comments

Comments
 (0)