From 00838d0bcd5f36b5c85cbef0507d67514cbc2271 Mon Sep 17 00:00:00 2001 From: "Timon.dev" Date: Wed, 3 Dec 2025 21:11:28 +0100 Subject: [PATCH] Added the cookie-suffix flag and environment variable. Fixes #7544 but is it the best way? --- src/common/http.ts | 4 ++-- src/node/cli.ts | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/common/http.ts b/src/common/http.ts index 5f94c2cd0..b780c3285 100644 --- a/src/common/http.ts +++ b/src/common/http.ts @@ -24,6 +24,6 @@ export class HttpError extends Error { } } -export enum CookieKeys { - Session = "code-server-session", +export const CookieKeys = { + Session: `code-server-session${process.env?.COOKIE_SUFFIX ? "-" + process.env?.COOKIE_SUFFIX : ""}`, } diff --git a/src/node/cli.ts b/src/node/cli.ts index 0fce9cfbf..8c88445ae 100644 --- a/src/node/cli.ts +++ b/src/node/cli.ts @@ -53,6 +53,7 @@ export interface UserProvidedCodeArgs { "disable-getting-started-override"?: boolean "disable-proxy"?: boolean "session-socket"?: string + "cookie-suffix"?: string "link-protection-trusted-domains"?: string[] // locale is used by both VS Code and code-server. locale?: string @@ -172,6 +173,12 @@ export const options: Options> = { "session-socket": { type: "string", }, + "cookie-suffix": { + type: "string", + description: + "Adds a suffix to the cookie. This can prevent a collision of cookies for subdomains, making them explixit. \n" + + "Without this flag, no suffix is used. This can also be set with COOKIE_SUFFIX set to any string.", + }, "disable-file-downloads": { type: "boolean", description: @@ -616,6 +623,10 @@ export async function setDefaults(cliArgs: UserProvidedArgs, configArgs?: Config usingEnvPassword = false } + if (process.env.COOKIE_SUFFIX) { + args["cookie-suffix"] = process.env.COOKIE_SUFFIX + } + if (process.env.GITHUB_TOKEN) { args["github-auth"] = process.env.GITHUB_TOKEN }