Repository navigation
fix: post-review hardening for OAuth2 authorize + RP-initiated logout - #3216
Conversation
…erns at /authorize OAuth 2.1 posture: a pattern-less client left data.redirect_uri entirely unchecked (any attacker-supplied URI passed, merely flagged redirectUriVerified=false) — the server would issue a code to an arbitrary redirect target. The code-request verifier now throws redirect_uri_mismatch for a client with no registered patterns, before any code issuance. redirectUriVerified is false only when the request carries no redirect_uri.
…redirect_uri Every other redirect in the authorize ladder is gated on redirectUriVerified, but AuthorizeForm.abort() navigated to codeRequest.redirect_uri unconditionally — for a pattern-less client a user click on Deny was an open redirect (error params only). The form now takes a fail-closed redirectUriVerified prop threaded from Authorize.vue and renders a localized stay-on-page notice instead of navigating when the redirect_uri is unverified.
…never resolves loggedIn/realmId are truthy for ANY identity type, but the chooser needs the resolved user — a non-user (client/robot) lingering session, or a transient userinfo failure (userResolved latched true before the call), left the page on a permanent spinner with no way forward; buildAuthorizeURL defaults prompt=select_account, so this was the default path. A failed resolveUser() no longer latches, the page re-resolves once, and a settled null user now renders the account prompt in switch-only mode (AAccountPrompt hides "Continue as" for an empty identityName) instead of the loading text. Also fixes the promise-share wrapper spawning an unhandled rejection from its internal .finally() chain whenever the shared promise rejects.
…password grant applyTokenGrantResponse deliberately retains an existing id_token when a response carries none (the refresh path) — but login() applied the password-grant response without a preceding cleanup(), so a stale id_token survived onto a newly-authenticated user. Reused for account switching, an RP-logout would then send the OLD user's id_token as id_token_hint and revoke the wrong session. login() now runs cleanup() between the grant succeeding and applying the response, mirroring exchangeAuthorizationCode.
…resolve name-form client ids Three fail-open shapes in OAuth2EndSessionService.verify(): - an aud-less verified hint paired with a request client_id silently skipped the cross-check (guarded on audiences.length > 0) — it now counts as unverified; - the id_token aud is the client UUID, so a name-form client_id (web) always failed the cross-check and silently degraded the logout to the confirm page — a non-UUID client_id is now resolved (realm from the request hint, else the VERIFIED hint's own realm claim; never claims of an unverified hint, no master fallback) and compared by its resolved UUID, failing closed when it does not resolve; - a supplied-but-unknown realm key degraded to an UNSCOPED client name lookup — it now skips client resolution entirely (no name, no redirect), and a name-form client_id with no realm key anywhere fails closed too (ambiguous: every realm has a built-in web client — same rule as the /authorize verifier). UUID client ids, including the sole-aud-derived one, resolve globally as before.
The forced-logout CSRF gate in AEndSessionForm compared hintSub against the local USER id but ignored the subject kind — the server revoke checks both sub and sub_kind. The logout controller now forwards hintSubKind (verified hints only) through the SSR page into the form, and the auto-clear requires hintSubKind === 'user' in addition to the sub match; a missing kind fails closed (no auto-clear).
…orize flow The realm-binding gate dereferenced identity.data.realm.id unguarded, and the code issuer read realm id/name the same way — a realm row deleted out from under a live identity produced a raw TypeError → HTTP 500. The gate now treats a missing realm relation as a mismatch (clean login_required, still no identity data in the body) and the issuer throws identityInvalid before building the code.
… algorithm buildOAuth2TokenHash hardcoded SHA-256 with a 16-byte left half — only coincidentally correct while every key is RS256. The digest (and its half-length, per OIDC Core §3.1.3.6) now follows the id_token's JWS alg (*256→SHA-256/16, *384→SHA-384/24, *512→SHA-512/32; an unrecognized alg throws instead of silently defaulting), and the authorization_code grant passes the realm signing key's signature_algorithm, resolved via a DI-injected key repository. Behavior today is unchanged; a future multi-algorithm key can no longer silently mint wrong hashes.
…erate contract The 60s promptLoginMaxAge window is a documented stateless approximation, not an accident: a sub-window session satisfies prompt=login without re-auth (it absorbs the hosted login→consent round-trip), an over-window session throws login_required, and max_age=0 stays stricter than prompt=login (the documented inversion). Also covers the dangling-realm login_required guard.
- end-session aud cross-check: fail-closed shape + name-form client_id resolution and the fail-closed realm-key rules - pattern-less clients rejected at /authorize; redirectUriVerified semantics - AuthorizeForm abort gate, select_account chooser escape hatch, login() cleanup-before-apply, hintSubKind auto-clear gate - at_hash digest derived from the signing alg; note that no c_hash is minted (code-only flow) - prompt=login window pinned as deliberate contract; prompt=none client-side enforcement recorded as a known limitation (server-side silent path scoped separately) - post_logout_redirect_uri column is text, the 2000-char cap is the request param validator's - client-web logout page comment updated for the name-form client_id resolution
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (35)
📝 WalkthroughWalkthroughOAuth2/OIDC authorization, token exchange, RP-initiated logout, and client workflows now use stricter fail-closed validation. Signing-key-aware token hashes, realm checks, redirect gating, logout subject validation, account-chooser fallbacks, and login cleanup are covered by updated tests and documentation. ChangesOAuth2 and OIDC hardening
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
✨ Finishing Touches📝 Generate docstrings
🧪 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: |
…rdening # Conflicts: # packages/client-web-kit/src/core/store/create.ts
…ore-apply contract The #3214 characterization spec pinned the pre-047.3 login lifecycle; login() now clears previous identity state between the grant and the apply, so the unset events precede the apply sequence and REALM_UPDATED legitimately fires exactly once (the cleanup unset — introspection still bypasses setRealm).
…tion) - login(): keep 047.3's cleanup between grant and staging (previous identity wiped + tokens revoked); the generation snapshot moves AFTER cleanup since cleanup bumps it - master's resolveUser un-latch fix is subsumed by the pure-fetcher design (validated is set only on a successful commit) - Authorize.vue: drop this PR's single-gate consolidation in favor of master's evolved guards (#3216 userSettled escape hatch — a user-less client/robot session must not spin on a loading gate)
Hardening pass over the plans 041/042 OAuth2/OIDC + RP-logout work, from the deep post-merge review of
b7fc25c..master. Ten commits, one item each.Fixes (P1 — real bugs)
/authorize(server) +AuthorizeForm.abort()gated onredirectUriVerified(kit): a client with no registeredredirect_uripatterns previously had itsredirect_uriaccepted unchecked (code issued to arbitrary URIs), and the kit's Deny click navigated to it unconditionally (user-click open redirect). The verifier now throwsredirect_uri_mismatchoutright (OAuth 2.1 posture — registered redirect URIs are required); the kit renders a localized stay-on-page notice when unverified (newauthupClient.authorizeAbortedkey, all 4 locales).prompt=select_accountchooser soft-lock: a non-user (client/robot) lingering session — or a transient userinfo failure — left the default authorize path on a permanent spinner. FailedresolveUser()no longer latches, the page re-resolves once, and a settled null user gets a switch-only account prompt. Also fixes an unhandled-rejection leak in the store's promise-share wrapper.store.login()retained a staleid_token:cleanup()now runs between the password grant succeeding and applying the response (mirrorsexchangeAuthorizationCode), so an RP-logout can never send a previous user'sid_token_hint.Hardening (P2 — fail-closed shapes)
audcross-check: anaud-less verified hint with a requestclient_idnow counts as unverified (was silently skipped); a name-formclient_idis resolved to its UUID before the cross-check (realm from the request hint, else the verified hint's realm claim — never an unverified hint's claims, no master fallback), so name-identified RPs get full silent logout instead of degrading to the confirm page; a supplied-but-unknown realm key, or a bare name with no realm key anywhere, fails closed (same rule as the/authorizeverifier).sub_kind: controller forwardshintSubKind(verified hints only) andAEndSessionFormrequireshintSubKind === 'user'alongside the sub match — missing kind fails closed. Matches the server revoke's ownsub+sub_kindinvariant.login_required/identity_invalid.Contracts pinned / future-proofing (P3)
at_hashdigest derived from the id_token signingalg(SHA-256/384/512 + 16/24/32-byte left half per OIDC Core §3.1.3.6; unknown alg throws). Behavior unchanged today (all keys RS256). Residual, deliberate: the alg is read viakeyRepository.findByRealmId, matching the issuer's key selection today — a true multi-key future should have the issuer return the alg it signed with.prompt=login60s window pinned by tests as the deliberate stateless approximation (sub-window passes, over-window throws,max_age=0is stricter — the documented inversion). Strict step-up remainsPROMPT_LOGIN_MAX_AGE=0.post_logout_redirect_uricorrected totext(the 2000-char cap is the request-param validator's);prompt=noneclient-side-only enforcement recorded as a known limitation (server-side silent path scoped as a separate plan); noted that noc_hashis minted (code-only flow).Breaking-ish notes
redirect_urican no longer use/authorize(previously issued codes to arbitrary URIs — the misconfiguration this PR exists to kill).client_idat/logoutwithout any realm key no longer resolves a client (was an unscoped, collation-lucky lookup); sendrealm_id/realm_name, the UUID, or omitclient_id.Verification
check:types(server-core incl. tests) clean, ESLint clean across all changed filesSummary by CodeRabbit
New Features
Bug Fixes