mirror of
https://github.com/coder/code-server.git
synced 2026-09-02 08:30:17 +02:00
Fix mistakenly encoding cookies to proxy
We use the cookie parser to remove the code-server token but by default it encodes using encodeURIComponent, which encodes more than is strictly necessary and can break proxied applications. Now we pass the cookies through unchanged (other than removing the code-server token). Fixes #7927.
This commit is contained in:
@@ -20,17 +20,31 @@ proxy.on("error", (error, _, res) => {
|
||||
}
|
||||
})
|
||||
|
||||
function identity<T>(val: T): T {
|
||||
return val
|
||||
}
|
||||
|
||||
// Strip the code-server cookie if it exists to avoid transmitting the cookie
|
||||
// to potentially malicious local ports.
|
||||
proxy.on("proxyReq", (preq, req) => {
|
||||
const cookieSessionName = getCookieSessionName((req as Request).args["cookie-suffix"])
|
||||
preq.setHeader(
|
||||
"Cookie",
|
||||
cookie.stringifyCookie({
|
||||
...(req as Request).cookies,
|
||||
[cookieSessionName]: undefined,
|
||||
}),
|
||||
)
|
||||
if (req.headers.cookie) {
|
||||
const cookieSessionName = getCookieSessionName((req as Request).args["cookie-suffix"])
|
||||
// Encoding and decoding are no-ops; we just want to remove the token
|
||||
// without changing anything else about the cookies because not all
|
||||
// applications encode/decode the same way `cookie` here does.
|
||||
preq.setHeader(
|
||||
"Cookie",
|
||||
cookie.stringifyCookie(
|
||||
{
|
||||
...cookie.parseCookie(req.headers.cookie, { decode: identity }),
|
||||
[cookieSessionName]: undefined,
|
||||
},
|
||||
{
|
||||
encode: identity,
|
||||
},
|
||||
),
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
// Intercept the response to rewrite absolute redirects against the base path.
|
||||
|
||||
Reference in New Issue
Block a user