audit-labs/gh-attest

GitHub Audit Evidence Extractor

clone: git clone https://gitbay.org/audit-labs/gh-attest.git

v1.0.4: src/cookies.ts · raw

 1export function parseCookies(request: Request): Record<string, string> {
 2  const header = request.headers.get("Cookie");
 3  if (!header) return {};
 4
 5  const out: Record<string, string> = {};
 6  for (const part of header.split(";")) {
 7    const separatorIndex = part.indexOf("=");
 8    if (separatorIndex === -1) continue;
 9    const key = part.slice(0, separatorIndex).trim();
10    const value = part.slice(separatorIndex + 1).trim();
11    if (key) out[key] = decodeURIComponent(value);
12  }
13  return out;
14}
15
16export function setCookieHeader(name: string, value: string, maxAgeSeconds: number): string {
17  return `${name}=${encodeURIComponent(value)}; Path=/; HttpOnly; Secure; SameSite=Lax; Max-Age=${maxAgeSeconds}`;
18}
19
20export function clearCookieHeader(name: string): string {
21  return `${name}=; Path=/; HttpOnly; Secure; SameSite=Lax; Max-Age=0`;
22}