Review JWT verification and session cookies before merge
Run on auth PRs that touch sign/verify, Set-Cookie, or refresh flows. You inventory algorithms and claims, cookie transport flags, and refresh storage — distinct from CSRF/CORS browser API review.
Cursor, Claude Code · Coding · 40 min · Deep
Outcome
A token and cookie table in the PR comment (artifact — transport — flags — claims checked), Blocks on alg confusion and refresh tokens readable from JavaScript, and explicit refresh rotation behavior.
Steps
- 1
List verify options beside each call
Copy the algorithms array, clockTolerance, and requiredClaims from jose/jsonwebtoken config into the PR comment. Defaults are not policy.
- 2
Diff Set-Cookie in preview login
Log in once on preview and capture response headers. Compare to production — flag regressions the diff did not show.
- 3
Replay a refresh token twice
Second use should fail when rotation is enabled. Paste status code and error shape into the comment.
Copy prompt
The prompt to paste
Review this PR's JWT/session authentication: verify paths, Set-Cookie flags, and refresh token lifecycle. Repository facts: [sign/verify libraries: jose, jsonwebtoken, next-auth/jwt — names from imports] [session shape: JWT in cookie, opaque id in cookie, Bearer only] [cookie names in diff — names only] [refresh storage: httpOnly cookie, Postgres/Redis row — path in code] PR context: [PR link or diff] ## Sign and verify inventory List each call in the diff: | site | sign or verify | allowed algs | key source | claims checked | - Block jwt.decode or parse without verify on request paths. - Block verify without explicit algorithms option / allowlist (jose allows multiple algs by default). - Block kid or jku header choosing keys without pinned mapping to known public keys. - Block ignoreExpiration, clockTolerance without documented max skew, or missing exp/nbf/iss/aud when team policy requires them. - Block accepting alg none or asymmetric/symmetric confusion (HS256 verified with RSA public key material, etc.). ## Login and Set-Cookie Quote every Set-Cookie the diff adds or changes: Name, Secure, HttpOnly, SameSite, Path, Domain, Max-Age. - Block session secrets without HttpOnly on HTTPS deployments. - Block SameSite=None without Secure. - Warn on broad Domain= or Path=/ when product only needs a subdomain. - Block refresh or access tokens in JSON body destined for localStorage/sessionStorage. ## Request authentication order - Trace cookie vs Authorization header precedence when both could be present. - Block trusting client-sent user id claim without signature verification on that same token. ## Refresh and logout - Quote where refresh tokens are stored and whether rotation invalidates the previous token. - Block refresh reuse without server-side revocation or rotation record. - On logout: cookies cleared? refresh rows deleted? note whether access JWT remains valid until exp. ## Cross-case (do not duplicate CSRF/CORS) - If SameSite or cookie flags change, note whether csrf-origin-token-validation-review-skill-md should run on the same PR — do not re-audit every POST route here unless the diff only touches cookies with no mutation routes. ## Findings table [Block | Warn | Note] file — issue — one-line fix ## Merge recommendation Rules: - Never paste private keys, HMAC secrets, or live JWT strings. - Not for OAuth redirect_uri allowlists — use open-redirect-validation-review-skill-md. - Not for route matchers without token logic — use nextjs-middleware-auth-bypass-review-skill-md.
OAuth id_token acceptance is still JWT verify — Block if the diff adds social login and verifies only aud without iss/exp or uses the client secret as HMAC key for a token meant for RS256.
Sample case written by Hidden Logic Lab. Not affiliated with Cursor or Claude Code.
More in Coding
Get new cases in your inbox
Weekly notes on new use cases and agent workflows. No product pitches.