Skip to content

fix: post-review hardening for OAuth2 authorize + RP-initiated logout - #3216

Merged
tada5hi merged 12 commits into
masterfrom
fix/plan047-post-review-hardening
Jul 10, 2026
Merged

tada5hi merged 12 commits into
masterfrom
fix/plan047-post-review-hardening

Conversation

@tada5hi

@tada5hi tada5hi commented Jul 10, 2026 •

Copy link
Copy Markdown
Collaborator

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)

  • Pattern-less clients rejected at /authorize (server) + AuthorizeForm.abort() gated on redirectUriVerified (kit): a client with no registered redirect_uri patterns previously had its redirect_uri accepted unchecked (code issued to arbitrary URIs), and the kit's Deny click navigated to it unconditionally (user-click open redirect). The verifier now throws redirect_uri_mismatch outright (OAuth 2.1 posture — registered redirect URIs are required); the kit renders a localized stay-on-page notice when unverified (new authupClient.authorizeAborted key, all 4 locales).
  • prompt=select_account chooser soft-lock: a non-user (client/robot) lingering session — or a transient userinfo failure — left the default authorize path on a permanent spinner. Failed resolveUser() 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 stale id_token: cleanup() now runs between the password grant succeeding and applying the response (mirrors exchangeAuthorizationCode), so an RP-logout can never send a previous user's id_token_hint.

Hardening (P2 — fail-closed shapes)

  • End-session aud cross-check: an aud-less verified hint with a request client_id now counts as unverified (was silently skipped); a name-form client_id is 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 /authorize verifier).
  • Forced-logout auto-clear gate checks sub_kind: controller forwards hintSubKind (verified hints only) and AEndSessionForm requires hintSubKind === 'user' alongside the sub match — missing kind fails closed. Matches the server revoke's own sub+sub_kind invariant.
  • Dangling realm relations fail closed: the realm-binding gate and the code issuer no longer TypeError→500 on a deleted realm row — clean login_required / identity_invalid.

Contracts pinned / future-proofing (P3)

  • at_hash digest derived from the id_token signing alg (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 via keyRepository.findByRealmId, matching the issuer's key selection today — a true multi-key future should have the issuer return the alg it signed with.
  • prompt=login 60s window pinned by tests as the deliberate stateless approximation (sub-window passes, over-window throws, max_age=0 is stricter — the documented inversion). Strict step-up remains PROMPT_LOGIN_MAX_AGE=0.
  • Docs: architecture notes updated for all of the above; post_logout_redirect_uri corrected to text (the 2000-char cap is the request-param validator's); prompt=none client-side-only enforcement recorded as a known limitation (server-side silent path scoped as a separate plan); noted that no c_hash is minted (code-only flow).

Breaking-ish notes

  • Clients with no registered redirect_uri can no longer use /authorize (previously issued codes to arbitrary URIs — the misconfiguration this PR exists to kill).
  • A name-form client_id at /logout without any realm key no longer resolves a client (was an unscoped, collation-lucky lookup); send realm_id/realm_name, the UUID, or omit client_id.

Verification

  • Full server-core suite: 121 files / 1220 tests passed (Docker-backed, includes the rebuilt SSR bundle)
  • client-web-kit: 61/61 (+8 new), i18n: 77/77 (locale parity)
  • check:types (server-core incl. tests) clean, ESLint clean across all changed files

Summary by CodeRabbit

  • New Features

    • Improved OAuth authorization and logout validation, including safer redirect and identity handling.
    • Added algorithm-aware OIDC token hash generation.
    • Added clearer authorization-denied messaging when automatic redirection is unavailable.
    • Improved account selection when user information is still loading or unavailable.
  • Bug Fixes

    • Prevented stale identity tokens from carrying over between logins.
    • Strengthened forced logout protections and invalid-session handling.
    • Prevented unsafe redirects for unverified authorization requests.

tada5hi added 10 commits July 10, 2026 10:51
…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
Copilot AI review requested due to automatic review settings July 10, 2026 08:54

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 Jul 10, 2026 •

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4505083e-1ec3-42f9-aae7-c37ace0d251e

📥 Commits

Reviewing files that changed from the base of the PR and between 589fdfd and 7b8e33b.

📒 Files selected for processing (35)
  • .agents/architecture.md
  • apps/client-web/pages/logout.vue
  • apps/server-core/src/adapters/http/controllers/workflows/logout/module.ts
  • apps/server-core/src/adapters/http/controllers/workflows/token/module.ts
  • apps/server-core/src/adapters/http/controllers/workflows/token/types.ts
  • apps/server-core/src/app/modules/http/modules/controller.ts
  • apps/server-core/src/core/oauth2/authorization/code-request/verifier/module.ts
  • apps/server-core/src/core/oauth2/authorization/code/issuer/module.ts
  • apps/server-core/src/core/oauth2/authorization/helpers.ts
  • apps/server-core/src/core/oauth2/authorization/module.ts
  • apps/server-core/src/core/oauth2/end-session/service.ts
  • apps/server-core/src/core/oauth2/grant-types/authorize.ts
  • apps/server-core/src/core/oauth2/grant-types/types.ts
  • apps/server-core/test/unit/core/oauth2/authorization/code-request/verifier/module.spec.ts
  • apps/server-core/test/unit/core/oauth2/authorization/code/issuer/module.spec.ts
  • apps/server-core/test/unit/core/oauth2/authorization/helpers.spec.ts
  • apps/server-core/test/unit/core/oauth2/authorization/module.spec.ts
  • apps/server-core/test/unit/core/oauth2/end-session/service.spec.ts
  • apps/server-core/test/unit/core/oauth2/grant-types/authorize.spec.ts
  • apps/server-core/ui/src/pages/logout.vue
  • packages/client-web-kit/src/components/workflows/authorize/AAccountPrompt.vue
  • packages/client-web-kit/src/components/workflows/authorize/Authorize.vue
  • packages/client-web-kit/src/components/workflows/authorize/AuthorizeForm.vue
  • packages/client-web-kit/src/components/workflows/end-session/AEndSessionForm.vue
  • packages/client-web-kit/src/core/store/create.ts
  • packages/client-web-kit/test/unit/components/workflows/authorize-form.spec.ts
  • packages/client-web-kit/test/unit/components/workflows/authorize.spec.ts
  • packages/client-web-kit/test/unit/components/workflows/end-session.spec.ts
  • packages/client-web-kit/test/unit/core/store/id-token.spec.ts
  • packages/client-web-kit/test/unit/core/store/lifecycle.spec.ts
  • packages/i18n/src/catalogs/de/client.ts
  • packages/i18n/src/catalogs/en/client.ts
  • packages/i18n/src/catalogs/es/client.ts
  • packages/i18n/src/catalogs/fr/client.ts
  • packages/i18n/src/constants.ts

📝 Walkthrough

Walkthrough

OAuth2/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.

Changes

OAuth2 and OIDC hardening

Layer / File(s) Summary
Authorization validation and realm binding
.agents/architecture.md, apps/server-core/src/core/oauth2/authorization/..., apps/server-core/test/unit/core/oauth2/authorization/...
Pattern-less clients and missing realm relations now fail with OAuth errors; redirect verification and prompt freshness behavior are covered by tests.
Signing-key-aware token exchange
.agents/architecture.md, apps/server-core/src/adapters/http/.../token/*, apps/server-core/src/core/oauth2/grant-types/*, apps/server-core/test/unit/core/oauth2/...
Authorization-code grants receive a key repository and compute at_hash using the realm signing algorithm, with missing-key and algorithm-specific tests.
Realm-aware logout hint validation
.agents/architecture.md, apps/server-core/src/core/oauth2/end-session/service.ts, apps/server-core/src/adapters/http/.../logout/module.ts, apps/server-core/ui/src/pages/logout.vue, apps/client-web/pages/logout.vue, apps/server-core/test/unit/core/oauth2/end-session/service.spec.ts
Logout client resolution and aud/client_id checks fail closed across UUID, name, realm, and unverified-hint cases while verified subject-kind data reaches the UI.
Authorize and logout client safeguards
packages/client-web-kit/src/components/workflows/authorize/*, packages/client-web-kit/src/components/workflows/end-session/*, packages/client-web-kit/test/unit/components/workflows/*, packages/i18n/src/*/client.ts, packages/i18n/src/constants.ts
Abort redirects require verified redirect URIs, unresolved account selection exposes switching, and automatic logout cleanup requires a matching user subject kind.
Identity store cleanup ordering
packages/client-web-kit/src/core/store/create.ts, packages/client-web-kit/test/unit/core/store/*
User resolution resets its settled state after errors, and login clears prior identity data before applying new token-grant data.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

  • authup/authup#3020: Modifies the same authorization request verifier with additional PKCE and public-client validation.
  • authup/authup#3196: Extends the same RP-initiated logout service and UI flow.
  • authup/authup#3200: Modifies the same token-time OIDC id_token and at_hash generation path.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/plan047-post-review-hardening

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.

@pkg-pr-new

pkg-pr-new Bot commented Jul 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

authup

npm i https://pkg.pr.new/authup@3216

@authup/client-web

npm i https://pkg.pr.new/@authup/client-web@3216

@authup/server-core

npm i https://pkg.pr.new/@authup/server-core@3216

@authup/access

npm i https://pkg.pr.new/@authup/access@3216

@authup/client-web-kit

npm i https://pkg.pr.new/@authup/client-web-kit@3216

@authup/client-web-kit-theme

npm i https://pkg.pr.new/@authup/client-web-kit-theme@3216

@authup/client-web-nuxt

npm i https://pkg.pr.new/@authup/client-web-nuxt@3216

@authup/client-web-theme

npm i https://pkg.pr.new/@authup/client-web-theme@3216

@authup/core-http-kit

npm i https://pkg.pr.new/@authup/core-http-kit@3216

@authup/core-kit

npm i https://pkg.pr.new/@authup/core-kit@3216

@authup/core-realtime-kit

npm i https://pkg.pr.new/@authup/core-realtime-kit@3216

@authup/errors

npm i https://pkg.pr.new/@authup/errors@3216

@authup/i18n

npm i https://pkg.pr.new/@authup/i18n@3216

@authup/kit

npm i https://pkg.pr.new/@authup/kit@3216

@authup/server-adapter-kit

npm i https://pkg.pr.new/@authup/server-adapter-kit@3216

@authup/server-adapter-node

npm i https://pkg.pr.new/@authup/server-adapter-node@3216

@authup/server-adapter-socket-io

npm i https://pkg.pr.new/@authup/server-adapter-socket-io@3216

@authup/server-adapter-web

npm i https://pkg.pr.new/@authup/server-adapter-web@3216

@authup/server-kit

npm i https://pkg.pr.new/@authup/server-kit@3216

@authup/server-test-kit

npm i https://pkg.pr.new/@authup/server-test-kit@3216

@authup/specs

npm i https://pkg.pr.new/@authup/specs@3216

commit: a2e0dad

@tada5hi tada5hi changed the title fix: post-review hardening for OAuth2 authorize + RP-initiated logout (plan 047) fix: post-review hardening for OAuth2 authorize + RP-initiated logout Jul 10, 2026
tada5hi added 2 commits July 10, 2026 11:06
…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).
@tada5hi
tada5hi merged commit 423849d into master Jul 10, 2026
4 of 5 checks passed
@tada5hi
tada5hi deleted the fix/plan047-post-review-hardening branch July 10, 2026 09:15
@github-actions github-actions Bot mentioned this pull request Jul 10, 2026
tada5hi added a commit that referenced this pull request Jul 10, 2026
…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)
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.

2 participants