Skip to content

chore(deps,middleware): bump cookie to 2.0.1 and migrate to parseCookie - #659

Merged
Weegy merged 1 commit into
mainfrom
chore/cookie-v2
Aug 11, 2026
Merged

chore(deps,middleware): bump cookie to 2.0.1 and migrate to parseCookie#659
Weegy merged 1 commit into
mainfrom
chore/cookie-v2

Conversation

@Weegy

@Weegy Weegy commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Split out of the consolidated batch #658, because this is not a version bump — it needs a source change, and it touches the session-verification path.

Supersedes #652.

Why it could not ride along in the batch

cookie v2.0.0 made two breaking changes:

  1. Removed the deprecated parse / serialize exports. They were renamed in
    v1.1.0 (parseparseCookie, serializestringifySetCookie) with the old
    names kept as aliases, and v2.0.0 dropped the aliases.
  2. ESM-only. Node 22+ can require(esm); older Node is unsupported.

We import exactly the removed symbol:

// middleware/src/auth/operatorAuthAccessor.ts
import { parse as parseCookieHeader } from 'cookie';

So #652 as raised does not compile.

The ESM half is a non-issue here: middleware is already "type": "module", and
the whole stack is pinned to Node 22 (engines ">=22.13.0 <23", .nvmrc
22.22.3, CI node-version: '22', Dockerfiles on node:22.23.2).

The change

cookie ^0.7.2^2.0.1, plus the one-line rename at the single call site:

-import { parse as parseCookieHeader } from 'cookie';
+import { parseCookie as parseCookieHeader } from 'cookie';

parseCookie returns Cookies = Record<string, string | undefined>, which is
exactly the type the call site already declares for the result, so nothing else
in the function changes.

@types/cookie is dropped. cookie v2 ships its own dist/index.d.ts
alongside its export target, so TypeScript resolves types from the package itself
and the @types/cookie stub is never consulted. Nothing else in the tree depends
on it (verified against the lockfile) — leaving it would keep a types package
describing an API we no longer use.

Blast radius

One import, one function, in the operator-session path — createOperatorAuthAccessor
is the thin adapter from a raw Cookie header to evaluateSessionToken, which is
the single code path deciding session validity for gated /api/v1/* routes and for
plugins using ctx.operatorAuth.

express and cookie-parser are unaffected: they declare cookie@^0.7.1 and
cookie@0.7.2 respectively, so npm nests their own 0.7.2 copies. Only our direct
import resolves to 2.0.1. The lockfile diff shows exactly that — 27 added / 5
removed lines, with node_modules/cookie at 2.0.1 and
node_modules/express/node_modules/cookie plus
node_modules/cookie-parser/node_modules/cookie at 0.7.2.

Verification

Run locally on Node 22.22.3 in CI job order (npm ci → build → lint → typecheck
→ test). Results are in the PR checks; the suites that exercise this accessor are
test/channelApi/adminKeysRouter.test.ts,
test/channelApi/publicPathsExemption.test.ts and
test/publicMcp/publicMcpKeyBindingsAdmin.test.ts.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

Supersedes #652, which does not compile as raised. Split out of the
consolidated batch #658 because this needs a source change and sits in the
session-verification path.

cookie v2.0.0 dropped the deprecated `parse`/`serialize` aliases (renamed to
`parseCookie`/`stringifySetCookie` back in v1.1.0) and moved the package to
ESM-only. We import exactly the removed `parse` symbol in
src/auth/operatorAuthAccessor.ts, so the bump requires the rename.

The ESM half is a non-issue: middleware is already "type": "module" and the
stack is pinned to Node 22 throughout (engines ">=22.13.0 <23", .nvmrc
22.22.3, CI node 22, Dockerfiles node:22.23.2).

parseCookie returns Cookies = Record<string, string | undefined>, exactly the
type the call site already declares, so the function body is unchanged.

Also drops @types/cookie: cookie v2 ships its own dist/index.d.ts next to its
export target, so TypeScript never consults the stub, and nothing else in the
lockfile depends on it.

express and cookie-parser are unaffected — they declare cookie@^0.7.1 and
cookie@0.7.2, so npm nests their own 0.7.2 copies; only our direct import
resolves to 2.0.1.

Verified on Node 22.22.3 in CI job order: build, lint (0 errors), typecheck and
6094 pass / 0 fail / 4 skipped, including the suites that exercise this
accessor (adminKeysRouter operator-session auth with real verification,
publicPathsExemption, publicMcpKeyBindingsAdmin).
@Weegy Weegy added deps Dependency updates (Dependabot) middleware middleware/ workspace labels Aug 11, 2026
@Weegy
Weegy merged commit c40af1f into main Aug 11, 2026
9 checks passed
@Weegy
Weegy deleted the chore/cookie-v2 branch August 14, 2026 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deps Dependency updates (Dependabot) middleware middleware/ workspace

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant