Skip to content

Drop ID token from Nuxt session cookie to fix oversized-cookie login failure - #69

Closed
janithjay wants to merge 1 commit into
thunder-id:mainfrom
janithjay:fix-nuxt-quicksample
Closed

Drop ID token from Nuxt session cookie to fix oversized-cookie login failure#69
janithjay wants to merge 1 commit into
thunder-id:mainfrom
janithjay:fix-nuxt-quicksample

Conversation

@janithjay

@janithjay janithjay commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

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

Stop embedding idToken in the session cookie payload. It's only used transiently at issuance time (getDecodedIdToken for sub / user_org) and doesn't need to be persisted.

This matches @thunderid/nextjs's SessionManager.createSessionToken, which already excludes idToken from its session cookie and only stores accessToken + refreshToken. Nuxt was the only SDK in the monorepo embedding the full ID token client-side. This brings it in line with the Next.js precedent without a larger architectural change.

After the fix __thunderid__session cookie was accepted

image

Related Issues

Related PRs

  • N/A

Checklist

  • Followed the contribution guidelines.
  • Manual test round performed and verified.
  • Documentation provided. (Add links if there are any)
  • Tests provided. (Add links if there are any)
    • Unit Tests
    • Integration Tests
  • Breaking changes. (Fill if applicable)
    • Breaking changes section filled.
    • breaking change label added.

Security checks

  • Followed secure coding standards.
  • Confirmed that this PR doesn't commit any keys, passwords, tokens, usernames, or other secrets.

Summary by CodeRabbit

  • Bug Fixes
    • Improved session security by ensuring raw identity tokens are no longer included in generated session cookies.
    • Session handling now relies on the session’s access and refresh token data.
  • Tests
    • Updated session-token coverage to reflect the streamlined token contents and maintain backward-compatibility checks.

Copilot AI lite review requested due to automatic review settings August 12, 2026 10:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The Nuxt session token no longer accepts, stores, or receives the raw idToken. Unit tests now validate session tokens using only accessTokenExpiresAt and refreshToken.

Changes

Nuxt session token handling

Layer / File(s) Summary
Remove raw ID token from session tokens
packages/nuxt/src/runtime/server/utils/session.ts
createSessionToken no longer accepts or embeds idToken. issueSessionCookie no longer passes it.
Update session token coverage
packages/nuxt/tests/unit/session-manager.test.ts
Phase 2 tests now cover accessTokenExpiresAt and refreshToken without idToken fixtures or assertions.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: senthalan

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies removing the ID token from the Nuxt session cookie to fix oversized-cookie login failures.
Description check ✅ Passed The description explains the failure, root cause, implementation, related issue, validation, and security checks; only optional documentation and test checklist items remain unchecked.
Linked Issues check ✅ Passed The changes address issue #4881 by removing the ID token from the session cookie payload and updating related tests.
Out of Scope Changes check ✅ Passed The modified session implementation and tests are directly related to fixing the oversized-cookie sign-in failure described in issue #4881.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/nuxt/tests/unit/session-manager.test.ts

ESLint skipped: missing config or dependency (missing-dependency). The ESLint configuration references a package that is not available in the sandbox.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
packages/nuxt/tests/unit/session-manager.test.ts (1)

200-200: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick win

Assert that new session tokens omit idToken.

The PR removes the raw ID token to reduce session-cookie size. The updated combined test checks only accessTokenExpiresAt and refreshToken, so a regression could re-add idToken without failing this suite.

Add an explicit absence assertion.

Proposed test assertion
+    expect(payload).not.toHaveProperty('idToken');
🤖 Prompt for 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.

In `@packages/nuxt/tests/unit/session-manager.test.ts` at line 200, Add an
explicit assertion in the combined new-session token test that the returned
payload does not contain idToken, alongside the existing accessTokenExpiresAt
and refreshToken checks. Use the same payload produced by the session-token flow
so regressions that reintroduce the raw ID token fail the test.
🔇 Additional comments (2)
packages/nuxt/tests/unit/session-manager.test.ts (2)

179-179: 🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

⚠️ Unverified finding
Sandbox verification was unavailable.

Remove idToken from the refresh call.

createSessionToken in packages/nuxt/src/runtime/server/utils/session.ts:39-70 no longer declares idToken. The call in packages/nuxt/src/runtime/server/utils/token-refresh.ts:51-126 still passes it. TypeScript excess-property checking will reject this object literal.

Remove the stale property before merge.

Proposed fix
-      idToken: refreshed.id_token ?? session.idToken,

Verify all call sites:


144-144: LGTM!

Also applies to: 160-160, 189-189, 212-212

🤖 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.

Nitpick comments:
In `@packages/nuxt/tests/unit/session-manager.test.ts`:
- Line 200: Add an explicit assertion in the combined new-session token test
that the returned payload does not contain idToken, alongside the existing
accessTokenExpiresAt and refreshToken checks. Use the same payload produced by
the session-token flow so regressions that reintroduce the raw ID token fail the
test.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 2fba35ba-c85c-4e2d-a2d3-bb36b89b5e2f

📥 Commits

Reviewing files that changed from the base of the PR and between 372a59a and 6300f03.

📒 Files selected for processing (2)
  • packages/nuxt/src/runtime/server/utils/session.ts
  • packages/nuxt/tests/unit/session-manager.test.ts
💤 Files with no reviewable changes (1)
  • packages/nuxt/src/runtime/server/utils/session.ts

@brionmario

Copy link
Copy Markdown
Member

IMO, the ideal fix for this is to implement session cookie chunking.
Next-Auth does this approach: https://next-auth.js.org/configuration/options

@janithjay

Copy link
Copy Markdown
Contributor Author

IMO, the ideal fix for this is to implement session cookie chunking. Next-Auth does this approach: https://next-auth.js.org/configuration/options

By PR #74, Supersedes this PR by fixing this issue with session cookie chunking as above suggested approach.

@janithjay janithjay closed this Aug 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nuxt quickstart: sign-in doesn't complete - redirects back to sign-in page

3 participants