MCPcopy Index your code
hub / github.com/coder/code-server / isCookieValid

Function isCookieValid

src/node/util.ts:272–291  ·  view source on GitHub ↗
({
  passwordFromArgs = "",
  cookieKey,
  hashedPasswordFromArgs = "",
  passwordMethod,
}: IsCookieValidArgs)

Source from the content-addressed store, hash-verified

270
271/** Checks if a req.cookies.key is valid using the PasswordMethod */
272export async function isCookieValid({
273 passwordFromArgs = "",
274 cookieKey,
275 hashedPasswordFromArgs = "",
276 passwordMethod,
277}: IsCookieValidArgs): Promise<boolean> {
278 let isValid = false
279 switch (passwordMethod) {
280 case "PLAIN_TEXT":
281 isValid = await isHashMatch(passwordFromArgs, cookieKey)
282 break
283 case "ARGON2":
284 case "SHA256":
285 isValid = safeCompare(cookieKey, hashedPasswordFromArgs)
286 break
287 default:
288 break
289 }
290 return isValid
291}
292
293/** Ensures that the input is sanitized by checking
294 * - it's a string

Callers 1

authenticatedFunction · 0.90

Calls 1

isHashMatchFunction · 0.85

Tested by

no test coverage detected