Repository navigation
feat: mint the id_token at the token exchange for an authoritative sid - #3200
Conversation
response_type=code is now the only supported response type (OAuth 2.1 / RFC 9700 posture): - the code-request validator requires response_type to be exactly 'code'; token / id_token / none / hybrid combos are rejected - OAuth2Authorization.authorize() is code-only (defense in depth) — the TOKEN/ID_TOKEN issuance branches, at_hash computation and the authorize-response accessToken/idToken outputs are gone; an openid-scoped code still carries its id_token on the code blob for the /token exchange - AuthorizeController.confirm() no longer writes access_token / id_token into the redirect URL (tokens leaked via history, proxy logs and Referer - the fix at source is to not produce them at all) - discovery response_types_supported now advertises only 'code' - the code-request verifier requires PKCE + state for public clients unconditionally (the willIssueCode gate is dead with code-only) - client-web's client URL generator emits response_type=code BREAKING: RPs using the implicit or hybrid flow must migrate to the authorization code flow with PKCE.
…d (plan 042) The id_token was minted at authorize time from options.sessionId, so its `sid` could reference a stale session (the #3191 session-reuse-vs-fallback path) and the session-less federated IdP flow produced no id_token at all. Move minting into the authorization_code grant, after resolveSession: - OAuth2AuthorizeGrant.runWith mints the openid-scoped id_token with sid = the real backing session (reuse, fallback, and federated flows alike); at_hash (over the fresh access token) and c_hash are recomputed, nonce and auth_time ride from the code - the authentication instant is carried on the auth-code blob as OAuth2AuthorizationCode.auth_time (replacing the removed id_token field — cache blob, no migration); OAuth2Authorization stamps it and drops its openIdTokenIssuer / identityResolver dependencies and id_token minting - openIdTokenIssuer is wired into the TokenController authorize grant; codeIssuer.updateIdToken is removed Fixes the plan-041 stale-sid residual; the federated openid flow now returns an id_token whose sid matches the access token's session.
|
Warning Review limit reached
Next review available in: 54 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR restricts OAuth2 authorization to ChangesCode-only OAuth2/OIDC flow
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant AuthorizeController
participant OAuth2Authorization
participant OAuth2AuthorizationCodeIssuer
Client->>AuthorizeController: GET /authorize?response_type=code
AuthorizeController->>OAuth2Authorization: authorize(request)
OAuth2Authorization->>OAuth2Authorization: validate response_type == code
OAuth2Authorization->>OAuth2AuthorizationCodeIssuer: issue({sessionId, authTime})
OAuth2AuthorizationCodeIssuer-->>OAuth2Authorization: authorizationCode
OAuth2Authorization-->>AuthorizeController: authorizationCode
AuthorizeController-->>Client: redirect(code, state)
sequenceDiagram
participant Client
participant TokenController
participant OAuth2AuthorizeGrant
participant SessionManager
participant OpenIDTokenIssuer
Client->>TokenController: POST /token (code)
TokenController->>OAuth2AuthorizeGrant: runWith(authorizationCode)
OAuth2AuthorizeGrant->>SessionManager: resolveSession(authorizationCode)
SessionManager-->>OAuth2AuthorizeGrant: session
OAuth2AuthorizeGrant->>OpenIDTokenIssuer: issue(claims incl sid, auth_time, at_hash)
OpenIDTokenIssuer-->>OAuth2AuthorizeGrant: id_token
OAuth2AuthorizeGrant-->>TokenController: tokens (access_token, id_token)
TokenController-->>Client: token response
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 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 |
authup
@authup/client-web
@authup/server-core
@authup/access
@authup/client-web-kit
@authup/client-web-kit-theme
@authup/client-web-nuxt
@authup/client-web-theme
@authup/core-http-kit
@authup/core-kit
@authup/core-realtime-kit
@authup/errors
@authup/i18n
@authup/kit
@authup/server-adapter-kit
@authup/server-adapter-node
@authup/server-adapter-socket-io
@authup/server-adapter-web
@authup/server-kit
@authup/server-test-kit
@authup/specs
commit: |
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
@coderabbitai full review |
✅ Action performedFull review finished. |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/client-web/pages/clients/[id]/url.vue (1)
50-63: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winGenerated URL missing
stateand PKCE parameters required for public clients.The
response_type=codechange is correct, but the generated URL omitsstate,code_challenge, andcode_challenge_method— all now required for public clients per the verifier. ThebuildAuthorizeURLhelper inclient-web-kitincludes all of these; this component manually constructs the URL instead. For public clients, the generated URL will be rejected by the server.At minimum, adding
stateis trivial. Full PKCE support requires generating acode_verifierand computing its SHA-256code_challenge, which is more involved but could leveragebuildAuthorizeURLdirectly.💡 Suggested improvement — add state and note PKCE requirement
const generatedUrl = computed(() => { const link = new URL('authorize', config.public.apiUrl); link.searchParams.set('client_id', props.entity.id); link.searchParams.set('response_type', 'code'); + link.searchParams.set('state', 'RANDOM_STATE'); if (scopes.value.length > 0) { link.searchParams.set('scope', scopes.value.join(' ')); }For full PKCE support, consider using
buildAuthorizeURLfrom@authup/client-web-kitinstead of manual URL construction.🤖 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 `@apps/client-web/pages/clients/`[id]/url.vue around lines 50 - 63, The authorize URL built in the `computed` block of `url.vue` is missing the public-client-required `state` and PKCE parameters. Update this logic so the generated link includes `state`, `code_challenge`, and `code_challenge_method` (or replace the manual URL assembly with `buildAuthorizeURL` from `@authup/client-web-kit` to keep it consistent). If you keep manual construction, generate a `code_verifier`/`code_challenge` pair and append them alongside the existing `client_id`, `response_type`, `scope`, and `redirect_uri` values.
🧹 Nitpick comments (1)
apps/server-core/test/unit/http/controllers/workflows/token/grant-idp-authorize.spec.ts (1)
241-291: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winConsider asserting
auth_timein the federated login id_token.The PR objectives explicitly call out carrying
auth_timeon the authorization code blob, and the federated (session-less) flow is one of the three key cases. The test verifiessidalignment but doesn't checkauth_timein the decoded id_token payload. Adding an assertion would close the coverage gap for this key objective.♻️ Suggested addition
const payload = JSON.parse( Buffer.from(tokenResponse.id_token!.split('.')[1], 'base64url').toString('utf8'), - ) as { sid?: unknown }; + ) as { sid?: unknown, auth_time?: unknown }; expect(typeof payload.sid).toEqual('string'); expect((payload.sid as string).length).toBeGreaterThan(0); + + expect(typeof payload.auth_time).toEqual('number'); const introspection = await suite.client.token.introspect({ token: tokenResponse.access_token }); expect(payload.sid).toEqual(introspection.session_id);🤖 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 `@apps/server-core/test/unit/http/controllers/workflows/token/grant-idp-authorize.spec.ts` around lines 241 - 291, The federated openid login test in grant-idp-authorize.spec should also verify auth_time on the minted id_token, since this flow is meant to carry it alongside sid. Update the existing openid federated login assertion in the tokenResponse/id_token payload check to decode and assert payload.auth_time is present and valid, using the same tokenResponse, payload parsing, and introspection flow already in the test.
🤖 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 @.agents/architecture.md:
- Around line 1114-1115: Update the auth-code flow description in the
architecture doc so it no longer says an openid-scoped code stores its id_token
on the code blob; the `id_token` field is removed from the auth-code blob and
should be described as minted during the `/token` exchange instead. Use the
surrounding auth-code and `/token` sections in `.agents/architecture.md` to keep
the narrative consistent with the current `auth_time`-based blob shape.
---
Outside diff comments:
In `@apps/client-web/pages/clients/`[id]/url.vue:
- Around line 50-63: The authorize URL built in the `computed` block of
`url.vue` is missing the public-client-required `state` and PKCE parameters.
Update this logic so the generated link includes `state`, `code_challenge`, and
`code_challenge_method` (or replace the manual URL assembly with
`buildAuthorizeURL` from `@authup/client-web-kit` to keep it consistent). If you
keep manual construction, generate a `code_verifier`/`code_challenge` pair and
append them alongside the existing `client_id`, `response_type`, `scope`, and
`redirect_uri` values.
---
Nitpick comments:
In
`@apps/server-core/test/unit/http/controllers/workflows/token/grant-idp-authorize.spec.ts`:
- Around line 241-291: The federated openid login test in
grant-idp-authorize.spec should also verify auth_time on the minted id_token,
since this flow is meant to carry it alongside sid. Update the existing openid
federated login assertion in the tokenResponse/id_token payload check to decode
and assert payload.auth_time is present and valid, using the same tokenResponse,
payload parsing, and introspection flow already in the test.
🪄 Autofix (Beta)
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: defaults
Review profile: CHILL
Plan: Pro
Run ID: d7941a89-2c88-48d0-bb82-b02647346158
📒 Files selected for processing (26)
.agents/architecture.mdapps/client-web/pages/clients/[id]/url.vueapps/server-core/src/adapters/http/controllers/entities/realm/module.tsapps/server-core/src/adapters/http/controllers/workflows/authorize/module.tsapps/server-core/src/adapters/http/controllers/workflows/authorize/types.tsapps/server-core/src/adapters/http/controllers/workflows/token/module.tsapps/server-core/src/adapters/http/controllers/workflows/token/types.tsapps/server-core/src/app/modules/http/modules/controller.tsapps/server-core/src/core/oauth2/authorization/code-request/validator.tsapps/server-core/src/core/oauth2/authorization/code-request/verifier/module.tsapps/server-core/src/core/oauth2/authorization/code/issuer/module.tsapps/server-core/src/core/oauth2/authorization/code/issuer/types.tsapps/server-core/src/core/oauth2/authorization/module.tsapps/server-core/src/core/oauth2/authorization/types.tsapps/server-core/src/core/oauth2/grant-types/authorize.tsapps/server-core/src/core/oauth2/grant-types/types.tsapps/server-core/test/unit/core/helpers/fake-oauth2-openid-token-issuer.tsapps/server-core/test/unit/core/helpers/index.tsapps/server-core/test/unit/core/oauth2/authorization/code-request/verifier/module.spec.tsapps/server-core/test/unit/core/oauth2/authorization/module.spec.tsapps/server-core/test/unit/core/oauth2/grant-types/authorize.spec.tsapps/server-core/test/unit/http/controllers/workflows/authorize.spec.tsapps/server-core/test/unit/http/controllers/workflows/token/grant-authorize.spec.tsapps/server-core/test/unit/http/controllers/workflows/token/grant-idp-authorize.spec.tsdocs/src/guide/development/api-oauth2.mdpackages/core-kit/src/domains/authorization-code/entity.ts
💤 Files with no reviewable changes (3)
- apps/server-core/src/adapters/http/controllers/workflows/authorize/types.ts
- apps/server-core/src/core/oauth2/authorization/types.ts
- apps/server-core/src/adapters/http/controllers/workflows/authorize/module.ts
# Conflicts: # apps/server-core/src/adapters/http/controllers/workflows/authorize/module.ts # apps/server-core/src/adapters/http/controllers/workflows/authorize/types.ts # apps/server-core/src/app/modules/http/modules/controller.ts # apps/server-core/src/core/oauth2/authorization/module.ts # apps/server-core/src/core/oauth2/authorization/types.ts # apps/server-core/test/unit/core/oauth2/authorization/module.spec.ts
The response-types section still said an openid-scoped code stores its id_token on the code blob and the /token exchange returns it, contradicting the minting-site section in the same file: authorize() no longer mints or stores the id_token — it stamps auth_time on the blob (the id_token field was removed) and the /token exchange mints and returns it. Reported by CodeRabbit on PR #3200.
Plan 042 item 6. Stacked on #3199 (drop implicit) — base branch
feat/oauth2-drop-implicit; retarget tomasteronce #3199 merges.The defect
The id_token was minted at
/authorizetime fromoptions.sessionIdand passed through the auth-code blob verbatim to/token. Two consequences:sid. Theauthorization_codegrant'sresolveSessioncan back the issued tokens with a different session than the code'ssession_id— the fix: reuse bearer session on interactive authorization_code login #3191 sub/realm-mismatch fallback, or a session deleted in flight. The id_token, minted earlier, kept the oldsid→ revoke-by-sid(RP-initiated logout, feat: add rp-initiated logout (end_session_endpoint) #3196) targeted the wrong session.OAuth2Authorization.authorize()minted an id_token, but the external-IdP callback (IdentityProviderController) issues its code directly, bypassing that path — so anopenid-scoped federated login received no id_token at all.The fix
Mint the id_token inside
OAuth2AuthorizeGrant.runWith, afterresolveSession:sid = session.id(the real backing session) — authoritative in the reuse branch, the fallback-create branch, and the session-less federated flow alike.auth_timeis captured at authorize time onto the auth-code blob as a newOAuth2AuthorizationCode.auth_timefield (replacing the removedid_tokenfield — the code is a Redis cache blob, so no migration), and read back at the exchange.at_hash(over the freshly-issued access token) andc_hashare recomputed at the exchange;noncerides from the code.OAuth2Authorization.authorize()no longer mints the id_token, and drops itsopenIdTokenIssuer/identityResolverdependencies (and thecodeIssuer.updateIdTokenmethod is gone). TheopenIdTokenIssueris instead wired into theTokenController's authorize grant.Tests
grant-types/authorize.spec.ts): no id_token withoutopenidscope;sid= reused session (not the code'ssession_idby coincidence) withauth_time/nonce/at_hashasserted;sid= the freshly-created session on the fallback branch (≠ the stale code id); id_token minted for a session-less (federated) openid code.auth_time= sessioncreated_atfor an interactive authorize,= nowfor a session-less one, passed through to the code issuer.grant-authorize.spec.ts: strengthened the existingsid/auth_timetest to assertid_token.sid === introspect(access_token).session_id— the id_token and access token share one real session.grant-idp-authorize.spec.ts: new test — anopenidfederated login now returns an id_token whosesidmatches the access token's session (previously: no id_token).Full server-core suite green (1170 tests).
Summary by CodeRabbit
New Features
sidand accurateauth_timeclaims.Bug Fixes
state.Documentation