Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/common/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 : ""}`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pulls off the environment variable, but if someone sets --cookie-suffix then this will not pick up anything since it is on the flag and not in the env.

What if we made this a function? Something like:

function cookieKey(suffix) {
 // return the key name here
}

And then where we need it we can call it like:

cookieKey(req.args["cookie-suffix"]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, yeah your right... I somehow thought this would adress that (but it is the other way around XD):

if (process.env.COOKIE_SUFFIX) {
  args["cookie-suffix"] = process.env.COOKIE_SUFFIX
}

But I dont quite get what you want to do with the function.

Do you want to do something like this:

// From 
export const CookieKeys = {
  Session: `code-server-session${process.env?.CODE_SERVER_COOKIE_SUFFIX? "-" + process.env?.CODE_SERVER_COOKIE_SUFFIX : ""}`,
}


// To
export function CookieKeys(suffix: string) {
  ...
  return { Session: "..." }
}

Or more like this:

function getCookieSessionName(): string {
  if (process.env?.CODE_SERVER_COOKIE_SUFFIX) {
    return `code-server-session-${process.env.CODE_SERVER_COOKIE_SUFFIX}`
  } 

  if (args["cookie-suffix"]) {
    return .....
  }

  return "code-server-session";
}

export const CookieKeys = {
  Session: getCookieSessionName(),
}

Because from what I understand, it seems like you want to do something like the first example which does not make a lot of sense to me. This should be set one time at start up and then not be changed and also a function would mean that you had to replace every call to this to a function.

Lastly, how could i get the cli-arguments? Is there also something like process.cliArgs or a variabel that i have to import from somewhere?

}
11 changes: 11 additions & 0 deletions src/node/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -172,6 +173,12 @@ export const options: Options<Required<UserProvidedArgs>> = {
"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:
Expand Down Expand Up @@ -616,6 +623,10 @@ export async function setDefaults(cliArgs: UserProvidedArgs, configArgs?: Config
usingEnvPassword = false
}

if (process.env.COOKIE_SUFFIX) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We started prefixing our environment variables to avoid collision so we should call this CODE_SERVER_COOKIE_SUFFIX.

args["cookie-suffix"] = process.env.COOKIE_SUFFIX
}

if (process.env.GITHUB_TOKEN) {
args["github-auth"] = process.env.GITHUB_TOKEN
}
Expand Down
Loading