Chunk the Nuxt session cookie instead of trimming its payload - #74
Conversation
|
Important Review available on request
Reviews should be triggered manually for repositories with fewer than 10 stars. Select Trigger review above or comment ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📝 WalkthroughWalkthroughNuxt now stores oversized session tokens across numbered cookies. Session reads, refreshes, and sign-out operations use chunked-cookie utilities. Unit tests cover writing, reading, stale-cookie cleanup, deletion, and token refresh behavior. ChangesChunked session cookies
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant issueSessionCookie
participant setChunkedCookie
participant BrowserCookies
participant getChunkedCookie
participant useServerSession
issueSessionCookie->>setChunkedCookie: Write session token
setChunkedCookie->>BrowserCookies: Set base or numbered cookies
BrowserCookies->>getChunkedCookie: Provide request cookies
getChunkedCookie->>useServerSession: Return session token
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/nuxt/src/runtime/server/utils/chunkedCookie.ts`:
- Around line 33-37: Update findExistingCookieNames to match the base cookie
name and only names with a decimal numeric suffix after `${name}.`; exclude
prefixed cookies such as `${name}.metadata` from the returned cleanup list.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 1fdf493e-1ea9-4904-9393-3e6e5b282198
📒 Files selected for processing (7)
packages/nuxt/src/runtime/server/routes/auth/session/signout.post.tspackages/nuxt/src/runtime/server/utils/chunkedCookie.tspackages/nuxt/src/runtime/server/utils/serverSession.tspackages/nuxt/src/runtime/server/utils/session.tspackages/nuxt/src/runtime/server/utils/token-refresh.tspackages/nuxt/tests/unit/chunked-cookie.test.tspackages/nuxt/tests/unit/token-refresh.test.ts
4dba7b8 to
03a99bf
Compare
03a99bf to
ac47919
Compare
ac47919 to
bd6cb03
Compare
…ding 4KB browser limits Signed-off-by: janithjay <janithjayashan018@gmail.com>
bd6cb03 to
9c8688c
Compare
Purpose
The Nuxt quickstart's redirect-flow sign-in silently fails: the OAuth exchange completes successfully end-to-end (confirmed via backend logs - authorize, credential submission, code exchange, and JWKS fetch all return 200/302 as expected), but the user is bounced back to a signed-out state instead of landing on the authenticated page.
Root cause: createSessionToken (packages/nuxt/src/runtime/server/utils/session.ts) embedded the full access token, ID token, and refresh token - all JWTs themselves - as fields inside the session cookie's own JWT payload. With ThunderID's token claim set, the resulting cookie value routinely exceeds the browser's hard ~4096-byte per-cookie limit. The browser silently drops any Set-Cookie over that limit (confirmed in Chrome DevTools under "Malformed Response Cookies"), so the session is never actually established despite the server doing everything correctly.
Approach
Rather than trimming the payload, this changes splits the session cookie across numbered
name.0,name.1, ... chunk cookies once it would exceed the per-cookie limit, and reassembles them transparently on read. The approach suggested in review #69 (comment), modeled on next-auth's own session cookie chunking.idTokenis not removed - unlike the alternative fix in #69, this branch keeps the full session payload (accessToken+idToken+refreshToken) intact.Chunking absorbs the size instead of reducing it, so
useServerSession()'ssession.idTokenkeeps working exactly as it did before the bug was ever introduced.The chunk name/size math itself (
split/join/filterChunkNames) is framework-agnostic, so it now lives in@thunderid/nodeas a newCookieChunkingutility rather than inside the Nuxt package.packages/nuxt/src/runtime/server/utils/chunkedCookie.tsis now a thin h3 adapter over it (getChunkedCookie/setChunkedCookie/deleteChunkedCookie), wired into all 5 session-cookie touchpoints.session.ts)token-refresh.ts)serverSession.ts)signout.post.ts).@thunderid/nextjsbuilds its session cookie the same way and hits the same 4KB ceiling. it can adoptCookieChunkingthe same way in a follow-up.The temp session cookie is untouched, it's always small and never needs chunking.
After the fix how __thunderid__session cookie was accepted
Related Issues
Related PRs
Checklist
breaking changelabel added.Security checks
Summary by CodeRabbit
New Features
Bug Fixes
Tests