Public: anyone can read this; the crew can change it.
A session idle for 14 days ends, and an active one is renewed, proven by a test with a moved clock #14621
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/14586-a-session-idle-for-14-days-ends-and-an-a → main 4 commits fork 2 threads · 2 unresolved
5 files
changed +269
−13
src/core/sessions.ts +54 −12
| @@ -13,6 +13,20 @@ import { quietly } from "./write_clock.ts"; | ||
| 13 | 13 | const SESSION_TTL_MS = 30 * 24 * 60 * 60 * 1000; |
| 14 | 14 | /** How stale a session's last-seen time may get before a request moves it. */ |
| 15 | 15 | const SEEN_EVERY_MS = 60 * 1000; |
| 16 | /** | |
| 17 | * How long a browser may go unused before its session ends (#14586): a | |
| 18 | * forgotten browser stops being a key. Use renews the expiry, still capped at | |
| 19 | * the TTL from that use. | |
| 20 | */ | |
| 21 | export const SESSION_IDLE_MS = 14 * 24 * 60 * 60 * 1000; | |
| 22 | ||
| 23 | /** How far a renewal must move the expiry before the cookie is re-set. */ | |
| 24 | const RESET_COOKIE_AFTER_MS = 24 * 60 * 60 * 1000; | |
| 25 | ||
| 26 | /** The instant before which a session's last use makes it idle. */ | |
| 27 | function idleSince(now: Date): string { | |
| 28 | return new Date(now.getTime() - SESSION_IDLE_MS).toISOString(); | |
| 29 | } | |
| 16 | 30 | |
| 17 | 31 | /** A signed-in browser, as its person sees it: never its secret. */ |
| 18 | 32 | export interface SessionInfo { |
| @@ -57,7 +71,10 @@ export function sessionOf( | ||
| 57 | 71 | token: string, |
| 58 | 72 | address?: string, |
| 59 | 73 | browser?: string | null, |
| 60 | ): Result<{ user: User; id: string; notice: boolean }, "invalid_session"> { | |
| 74 | ): Result< | |
| 75 | { user: User; id: string; notice: boolean; renewed?: Date }, | |
| 76 | "invalid_session" | |
| 77 | > { | |
| 61 | 78 | const hash = sha256(token); |
| 62 | 79 | const row = db |
| 63 | 80 | .query< |
| @@ -66,11 +83,12 @@ export function sessionOf( | ||
| 66 | 83 | user_id: string; |
| 67 | 84 | expires_at: string; |
| 68 | 85 | last_seen_at: string | null; |
| 86 | created_at: string; | |
| 69 | 87 | notice: number; |
| 70 | 88 | }, |
| 71 | 89 | [string] |
| 72 | 90 | >( |
| 73 | `SELECT id, user_id, expires_at, last_seen_at, | |
| 91 | `SELECT id, user_id, expires_at, last_seen_at, created_at, | |
| 74 | 92 | EXISTS (SELECT 1 FROM account_notice n WHERE n.user_id = session.user_id AND n.seen_at IS NULL) AS notice |
| 75 | 93 | FROM session WHERE token_hash = ?1`, |
| 76 | 94 | ) |
| @@ -78,24 +96,43 @@ export function sessionOf( | ||
| 78 | 96 | const now = new Date(); |
| 79 | 97 | if (!row || row.expires_at <= now.toISOString()) |
| 80 | 98 | return err("invalid_session"); |
| 99 | if ((row.last_seen_at ?? row.created_at) < idleSince(now)) { | |
| 100 | // Idle too long: the same signed-out answer, and the key is gone. | |
| 101 | db.query("DELETE FROM session WHERE token_hash = ?1").run(hash); | |
| 102 | return err("invalid_session"); | |
| 103 | } | |
| 81 | 104 | const user = getUserById(db, row.user_id); |
| 82 | 105 | if (!user || !isActive(user)) return err("invalid_session"); |
| 83 | // At most one write a minute per browser, however busy it is. | |
| 106 | // At most one write a minute per browser, however busy it is; each one | |
| 107 | // renews the expiry to the TTL from this use. | |
| 84 | 108 | const stale = new Date(now.getTime() - SEEN_EVERY_MS).toISOString(); |
| 85 | if (row.last_seen_at === null || row.last_seen_at < stale) | |
| 109 | let renewed: Date | undefined; | |
| 110 | if (row.last_seen_at === null || row.last_seen_at < stale) { | |
| 111 | const until = new Date(now.getTime() + SESSION_TTL_MS); | |
| 112 | // The cookie is re-set only when this moves the end by over a day: at | |
| 113 | // most once a day per browser, and never on the first use after sign-in. | |
| 114 | if (until.getTime() - Date.parse(row.expires_at) > RESET_COOKIE_AFTER_MS) renewed = until; | |
| 86 | 115 | quietly(db, () => |
| 87 | 116 | db |
| 88 | 117 | .query( |
| 89 | "UPDATE session SET last_seen_at = ?1, address = COALESCE(address, ?3), browser = COALESCE(browser, ?4) WHERE token_hash = ?2", | |
| 118 | "UPDATE session SET last_seen_at = ?1, expires_at = ?5, address = COALESCE(address, ?3), browser = COALESCE(browser, ?4) WHERE token_hash = ?2", | |
| 90 | 119 | ) |
| 91 | 120 | .run( |
| 92 | 121 | now.toISOString(), |
| 93 | 122 | hash, |
| 94 | 123 | address === undefined || address === "unknown" ? null : address, |
| 95 | 124 | browser === undefined || browser === null ? null : browser.slice(0, 64), |
| 125 | until.toISOString(), | |
| 96 | 126 | ), |
| 97 | 127 | ); |
| 98 | return ok({ user, id: row.id, notice: row.notice === 1 }); | |
| 128 | } | |
| 129 | // The caller re-sets the cookie with this expiry (`http/session_renewal.ts`). | |
| 130 | return ok({ | |
| 131 | user, | |
| 132 | id: row.id, | |
| 133 | notice: row.notice === 1, | |
| 134 | ...(renewed === undefined ? {} : { renewed }), | |
| 135 | }); | |
| 99 | 136 | } |
| 100 | 137 | |
| 101 | 138 | export function destroySession(db: Database, token: string): void { |
| @@ -112,6 +149,7 @@ export function listSessions( | ||
| 112 | 149 | current?: string, |
| 113 | 150 | ): SessionInfo[] { |
| 114 | 151 | const mine = current === undefined ? undefined : sha256(current); |
outdated
Two separate new Date() calls; take one now and use it for both bounds. |
||
| 152 | const now = new Date(); | |
| 115 | 153 | return db |
| 116 | 154 | .query< |
| 117 | 155 | { |
| @@ -123,12 +161,13 @@ export function listSessions( | ||
| 123 | 161 | address: string | null; |
| 124 | 162 | browser: string | null; |
| 125 | 163 | }, |
| 126 | [string, string] | |
| 164 | [string, string, string] | |
| 127 | 165 | >( |
| 128 | 166 | `SELECT id, token_hash, created_at, last_seen_at, expires_at, address, browser FROM session |
| 129 | WHERE user_id = ?1 AND expires_at > ?2 ORDER BY created_at DESC, id`, | |
| 167 | WHERE user_id = ?1 AND expires_at > ?2 AND COALESCE(last_seen_at, created_at) >= ?3 | |
| 168 | ORDER BY created_at DESC, id`, | |
| 130 | 169 | ) |
| 131 | .all(userId, new Date().toISOString()) | |
| 170 | .all(userId, now.toISOString(), idleSince(now)) | |
| 132 | 171 | .map((r) => ({ |
| 133 | 172 | id: r.id, |
| 134 | 173 | createdAt: r.created_at, |
| @@ -149,9 +188,12 @@ export function endSession(db: Database, userId: string, id: string): boolean { | ||
| 149 | 188 | ); |
| 150 | 189 | } |
| 151 | 190 | |
| 152 | /** Housekeeping for the background worker. */ | |
| 191 | /** Housekeeping for the background worker: expired and idle sessions go. */ | |
| 153 | 192 | export function pruneSessions(db: Database): number { |
| 193 | const now = new Date(); | |
| 154 | 194 | return db |
| 155 | .query("DELETE FROM session WHERE expires_at <= ?1") | |
| 156 | .run(new Date().toISOString()).changes; | |
| 195 | .query( | |
| 196 | "DELETE FROM session WHERE expires_at <= ?1 OR COALESCE(last_seen_at, created_at) < ?2", | |
| 197 | ) | |
| 198 | .run(now.toISOString(), idleSince(now)).changes; | |
| 157 | 199 | } |
src/http/server.ts +4 −1
| @@ -23,6 +23,7 @@ import { | ||
| 23 | 23 | followUpstreamUpdate, |
| 24 | 24 | } from "../web/pages/upstream-follow.ts"; |
| 25 | 25 | import { secureFor } from "./cookie_secure.ts"; |
| 26 | import { noteRenewal, withRenewal } from "./session_renewal.ts"; | |
| 26 | 27 | import { refusedByDatabase, shownRefusal } from "./refusal.ts"; |
| 27 | 28 | import { NOT_A_MEMBER } from "../core/roles.ts"; |
| 28 | 29 | import { privacyPage } from "../web/pages/privacy.ts"; |
| @@ -747,6 +748,8 @@ async function resolveAuth(app: App, request: Request): Promise<Auth> { | ||
| 747 | 748 | const session = cookieValue(request, "forge_session"); |
| 748 | 749 | if (session !== undefined) { |
| 749 | 750 | const found = sessionOf(app.db, session, clientAddress(request), browserName(request.headers.get("user-agent"))); |
| 751 | if (found.ok && found.value.renewed !== undefined) | |
| 752 | noteRenewal(request, session, found.value.renewed, publicUrl(request, app.config.url), app.config.url); | |
| 750 | 753 | if (found.ok) |
| 751 | 754 | return { |
| 752 | 755 | user: found.value.user, |
| @@ -2977,7 +2980,7 @@ export async function serve(app: App): Promise<Servers> { | ||
| 2977 | 2980 | if (url.pathname.startsWith("/api/v1/")) |
| 2978 | 2981 | response.headers.set("www-authenticate", bearerChallenge(url.origin, request)); |
| 2979 | 2982 | } |
| 2980 | const whole = await compress(request, response).then((r) => securityFloor(resourcePolicy(request, r))).then((r) => privateWhenSignedIn(request, r)); | |
| 2983 | const whole = await compress(request, response).then((r) => securityFloor(resourcePolicy(request, r))).then((r) => privateWhenSignedIn(request, r)).then((r) => withRenewal(request, r)); | |
| 2981 | 2984 | const done = request.method === "HEAD" ? await headOf(whole) : whole; |
| 2982 | 2985 | if (namesFrame(request)) notePhase(request, "compress", performance.now() - compressing); |
| 2983 | 2986 | return done; |
src/http/session_renewal.ts added +32
| @@ -0,0 +1,32 @@ | ||
| 1 | /** | |
| 2 | * A renewed session reaches the browser (#14586). When a request's session | |
| 3 | * row is renewed (at most once a minute, `core/sessions.ts`), the answer | |
| 4 | * re-sets the session cookie with the new expiry, so an active browser is not | |
| 5 | * dropped at the Expires it was given at sign-in. | |
| 6 | */ | |
| 7 | import { setCookie } from "../auth/cookies.ts"; | |
| 8 | import { secureFor } from "./cookie_secure.ts"; | |
| 9 | ||
| 10 | const renewed = new WeakMap<Request, string>(); | |
| 11 | ||
| 12 | /** Remember that `request`'s session `token` now lasts until `expires`. */ | |
| 13 | export function noteRenewal(request: Request, token: string, expires: Date, url: URL, forgeUrl?: string): void { | |
| 14 | renewed.set(request, setCookie("forge_session", token, { expires, secure: secureFor(url, forgeUrl) })); | |
| 15 | } | |
| 16 | ||
| 17 | /** | |
| 18 | * The answer with the renewed cookie, on a read only (a refused cross-site | |
| 19 | * POST sets no cookie; a browser in use reads often), and unless the handler | |
| 20 | * set the session cookie itself (a sign-in or a sign-out decides it). | |
| 21 | */ | |
| 22 | export function withRenewal(request: Request, response: Response): Response { | |
| 23 | const cookie = renewed.get(request); | |
| 24 | if (cookie === undefined || (request.method !== "GET" && request.method !== "HEAD")) return response; | |
| 25 | try { | |
| 26 | if (response.headers.getSetCookie().some((c) => c.startsWith("forge_session="))) return response; | |
| 27 | response.headers.append("set-cookie", cookie); | |
| 28 | } catch { | |
| 29 | // An immutable header set keeps the headers it came with. | |
| 30 | } | |
| 31 | return response; | |
| 32 | } |
test/cookie-flags.test.ts +9
| @@ -55,6 +55,7 @@ const COOKIES: Record<string, Spelled> = { | ||
| 55 | 55 | "src/web/pages/site.ts forge_theme": { name: "forge_theme", lines: 2, door: "theme" }, |
| 56 | 56 | "src/web/flash.ts FLASH_COOKIE": { name: "forge_flash", lines: 2, door: "parent link callback" }, |
| 57 | 57 | "src/http/server.ts forge_mode": { name: "forge_mode", lines: 1, door: "mode switch" }, |
| 58 | "src/http/session_renewal.ts forge_session": { name: "forge_session", lines: 1, door: "session renewal" }, | |
| 58 | 59 | "src/http/rp.ts STATE_COOKIE": { |
| 59 | 60 | name: "forge_rp", |
| 60 | 61 | lines: 1, |
| @@ -100,6 +101,7 @@ const WALKED: Record<string, number> = { | ||
| 100 | 101 | "src/auth/cookies.ts": 2, // the doc comments of setCookie and expireCookie, which every builder calls |
| 101 | 102 | "src/http/api/tokens.ts": 4, // password sign-in, sign-out: a set-cookie header and a sessionCookie() call each |
| 102 | 103 | "src/http/server.ts": 1, // the mode switch |
| 104 | "src/http/session_renewal.ts": 1, // a renewed session re-set on a page read | |
| 103 | 105 | "src/http/rp.ts": 6, // parent sign-in and link: state cookie set and cleared |
| 104 | 106 | "src/apps/proxy.ts": 2, // app grant, app sign-out |
| 105 | 107 | "src/apps/feedback.ts": 2, // a stranger's note on an app host, both answers that may carry the visitor cookie |
| @@ -227,6 +229,13 @@ for (const https of [false, true]) { | ||
| 227 | 229 | take("form sign-up", signedUpForm, "forge_session"); |
| 228 | 230 | const out = await post("/logout", { cookie: `forge_session=${createSession(child.db, carol.id).token}` }); |
| 229 | 231 | take("sign-out", out, "forge_session"); |
| 232 | // A page read renews the session and re-sets its cookie (#14586). | |
| 233 | const aging = createSession(child.db, carol.id).token; | |
| 234 | // Signed in a while ago: its end is more than a day short of 30 days out. | |
| 235 | child.db.query("UPDATE session SET expires_at = ?1, last_seen_at = ?2 WHERE user_id = ?3").run(new Date(Date.now() + 20 * 86_400_000).toISOString(), new Date(Date.now() - 10 * 86_400_000).toISOString(), carol.id); | |
| 236 | const renewed = await fetch(`${cs.url}/`, { redirect: "manual", headers: { cookie: `forge_session=${aging}` } }); | |
| 237 | await renewed.text(); | |
| 238 | take("session renewal", renewed, "forge_session"); | |
| 230 | 239 | |
| 231 | 240 | // The mode switch lets go of forge_mode. |
| 232 | 241 | const mode = await fetch(`${cs.url}/?mode=dev`, { redirect: "manual" }); |
test/sessions-idle.test.ts added +170
| @@ -0,0 +1,170 @@ | ||
| 1 | /** | |
| 2 | * A session idle for 14 days ends; one in use renews its expiry, capped at | |
| 3 | * the 30-day TTL from its last use (#14586). The clock is moved, not waited. | |
| 4 | */ | |
| 5 | import { afterAll, afterEach, beforeAll, describe, expect, setSystemTime, test } from "bun:test"; | |
| 6 | import { mkdtemp, rm } from "node:fs/promises"; | |
| 7 | import { tmpdir } from "node:os"; | |
| 8 | import { join } from "node:path"; | |
| 9 | import { createApp, type App } from "../src/app.ts"; | |
| 10 | import { | |
| 11 | createSession, | |
| 12 | listSessions, | |
| 13 | pruneSessions, | |
| 14 | sessionOf, | |
| 15 | sessionUser, | |
| 16 | } from "../src/core/sessions.ts"; | |
| 17 | import { createUser } from "../src/core/users.ts"; | |
| 18 | import { sha256 } from "../src/kernel/hash.ts"; | |
| 19 | import { serve, type Servers } from "../src/http/server.ts"; | |
| 20 | import { noteRenewal, withRenewal } from "../src/http/session_renewal.ts"; | |
| 21 | import { quietLogs } from "./helpers/globals.ts"; | |
| 22 | ||
| 23 | quietLogs(); | |
| 24 | ||
| 25 | const DAY = 24 * 60 * 60 * 1000; | |
| 26 | let dataDir: string; | |
| 27 | let app: App; | |
| 28 | let userId: string; | |
| 29 | ||
| 30 | beforeAll(async () => { | |
| 31 | dataDir = await mkdtemp(join(tmpdir(), "forge-sessions-idle-")); | |
| 32 | app = createApp({ dataDir, port: 0 }); | |
| 33 | const made = await createUser(app.db, { | |
| 34 | origin: "seed", | |
| 35 | trusted: true, | |
| 36 | username: "idler", | |
| 37 | email: "[email protected]", | |
| 38 | password: "a-good-passphrase", | |
| 39 | adminIfFirst: true, | |
| 40 | }); | |
| 41 | if (!made.ok) throw new Error(String(made.error)); | |
| 42 | userId = made.value.id; | |
| 43 | }); | |
| 44 | afterEach(() => setSystemTime()); | |
| 45 | afterAll(async () => { | |
| 46 | app.close(); | |
| 47 | await rm(dataDir, { recursive: true, force: true }); | |
| 48 | }); | |
| 49 | ||
| 50 | function row(token: string) { | |
| 51 | return app.db | |
| 52 | .query<{ expires_at: string; last_seen_at: string | null }, [string]>( | |
| 53 | "SELECT expires_at, last_seen_at FROM session WHERE token_hash = ?1", | |
| 54 | ) | |
| 55 | .get(sha256(token)); | |
| 56 | } | |
| 57 | ||
| 58 | test("a session unused for 14 days is refused as signed out and its row deleted", () => { | |
| 59 | const start = Date.now(); | |
| 60 | const { token } = createSession(app.db, userId); | |
| 61 | expect(sessionOf(app.db, token).ok).toBe(true); | |
| 62 | ||
| 63 | setSystemTime(new Date(start + 14 * DAY + 60_000)); | |
| 64 | const got = sessionUser(app.db, token); | |
| 65 | expect(got.ok).toBe(false); | |
| 66 | if (!got.ok) expect(got.error).toBe("invalid_session"); | |
| 67 | expect(row(token)).toBeNull(); | |
| 68 | }); | |
| 69 | ||
| 70 | test("a session never used after sign-in idles from its creation", () => { | |
| 71 | const start = Date.now(); | |
| 72 | const { token } = createSession(app.db, userId); | |
| 73 | setSystemTime(new Date(start + 15 * DAY)); | |
| 74 | expect(sessionOf(app.db, token).ok).toBe(false); | |
| 75 | expect(row(token)).toBeNull(); | |
| 76 | }); | |
| 77 | ||
| 78 | test("a session used since renews its expiry to 30 days from that use", () => { | |
| 79 | const start = Date.now(); | |
| 80 | const { token, expiresAt } = createSession(app.db, userId); | |
| 81 | // Used every ten days: never idle, and past the 30 days from sign-in. | |
| 82 | for (const day of [10, 20, 29, 38]) { | |
| 83 | const now = start + day * DAY; | |
| 84 | setSystemTime(new Date(now)); | |
| 85 | expect(sessionOf(app.db, token).ok).toBe(true); | |
| 86 | expect(row(token)?.expires_at).toBe(new Date(now + 30 * DAY).toISOString()); | |
| 87 | } | |
| 88 | expect(row(token)!.expires_at > expiresAt.toISOString()).toBe(true); | |
| 89 | }); | |
| 90 | ||
| 91 | test("renewal writes at most once a minute", () => { | |
| 92 | const start = Date.now(); | |
| 93 | const { token } = createSession(app.db, userId); | |
| 94 | setSystemTime(new Date(start + DAY)); | |
| 95 | sessionOf(app.db, token); | |
| 96 | const first = row(token)!; | |
| 97 | setSystemTime(new Date(start + DAY + 30_000)); | |
| 98 | sessionOf(app.db, token); | |
| 99 | expect(row(token)).toEqual(first); | |
| 100 | setSystemTime(new Date(start + DAY + 61_000)); | |
| 101 | sessionOf(app.db, token); | |
| 102 | expect(row(token)!.expires_at > first.expires_at).toBe(true); | |
| 103 | }); | |
| 104 | ||
| 105 | test("housekeeping and the list of browsers drop idle sessions", () => { | |
| 106 | const start = Date.now(); | |
| 107 | const { token } = createSession(app.db, userId); | |
| 108 | setSystemTime(new Date(start + 14 * DAY + 60_000)); | |
| 109 | expect(listSessions(app.db, userId, token).some((s) => s.current)).toBe(false); | |
| 110 | expect(pruneSessions(app.db)).toBeGreaterThan(0); | |
| 111 | expect(row(token)).toBeNull(); | |
| 112 | }); | |
| 113 | ||
| 114 | describe("the renewed expiry reaches the browser", () => { | |
| 115 | let servers: Servers; | |
| 116 | const cells = process.env["FORGE_CELLS"]; | |
| 117 | beforeAll(async () => { | |
| 118 | process.env["FORGE_CELLS"] = "off"; | |
| 119 | servers = await serve(app); | |
| 120 | }); | |
| 121 | afterAll(async () => { | |
| 122 | await servers.stop(); | |
| 123 | if (cells === undefined) delete process.env["FORGE_CELLS"]; | |
| 124 | else process.env["FORGE_CELLS"] = cells; | |
| 125 | }); | |
| 126 | ||
| 127 | async function sessionCookieOf(token: string): Promise<string | undefined> { | |
| 128 | const res = await fetch(`${servers.url}/`, { headers: { cookie: `forge_session=${token}` }, redirect: "manual" }); | |
| 129 | await res.text(); | |
| 130 | return res.headers.getSetCookie().find((c) => c.startsWith("forge_session=")); | |
| 131 | } | |
| 132 | ||
| 133 | test("a renewing request re-sets the cookie with the new expiry; the next within a minute does not", async () => { | |
| 134 | const start = Date.now(); | |
| 135 | const { token } = createSession(app.db, userId); | |
| 136 | // Just signed in: the cookie already carries its 30 days. | |
| 137 | expect(await sessionCookieOf(token)).toBeUndefined(); | |
| 138 | setSystemTime(new Date(start + 2 * DAY)); | |
| 139 | const set = await sessionCookieOf(token); | |
| 140 | expect(set).toBeDefined(); | |
| 141 | expect(set).toContain(`forge_session=${token};`); | |
| 142 | expect(set).toContain("HttpOnly"); | |
| 143 | const expires = /Expires=([^;]+)/.exec(set!)?.[1]; | |
| 144 | expect(new Date(expires!).toISOString().slice(0, 19)).toBe(row(token)!.expires_at.slice(0, 19)); | |
| 145 | expect(await sessionCookieOf(token)).toBeUndefined(); | |
| 146 | }); | |
| 147 | ||
| 148 | test("an idle session gets no renewed cookie", async () => { | |
| 149 | const start = Date.now(); | |
| 150 | const { token } = createSession(app.db, userId); | |
| 151 | setSystemTime(new Date(start + 15 * DAY)); | |
| 152 | expect(await sessionCookieOf(token)).toBeUndefined(); | |
| 153 | expect(row(token)).toBeNull(); | |
| 154 | }); | |
| 155 | ||
| 156 | test("a handler's own session cookie (a sign-out) is not overridden", () => { | |
| 157 | const request = new Request("http://forge.test/"); | |
| 158 | noteRenewal(request, "abc", new Date(Date.now() + DAY), new URL(request.url)); | |
| 159 | const cleared = new Response("", { headers: { "set-cookie": "forge_session=; Path=/; Max-Age=0" } }); | |
| 160 | expect(withRenewal(request, cleared).headers.getSetCookie()).toEqual(["forge_session=; Path=/; Max-Age=0"]); | |
| 161 | const plain = withRenewal(request, new Response("")); | |
| 162 | expect(plain.headers.getSetCookie()[0]).toStartWith("forge_session=abc;"); | |
| 163 | }); | |
| 164 | }); | |
| 165 | ||
| 166 | test("a renewal answering a POST sets no cookie", () => { | |
| 167 | const request = new Request("http://forge.test/", { method: "POST" }); | |
| 168 | noteRenewal(request, "abc", new Date(Date.now() + DAY), new URL(request.url)); | |
| 169 | expect(withRenewal(request, new Response("")).headers.getSetCookie()).toEqual([]); | |
| 170 | }); |
new above
offline
Renewal is written to the row only; the response never refreshes the cookie, so the browser drops it at the original Expires. Surface the new expiry to the caller so the request path re-sets the cookie, and test it.