Skip to content

feat: add rp-initiated logout (end_session_endpoint) - #3196

Merged
tada5hi merged 1 commit into
masterfrom
feat/oauth2-end-session
Jul 7, 2026
Merged

tada5hi merged 1 commit into
masterfrom
feat/oauth2-end-session

Conversation

@tada5hi

@tada5hi tada5hi commented Jul 7, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #3195 (prompt surface). PR C of the plan in .agents/plans/041-authorize-session-binding.md. Review/merge after #3195.

Problem

A downstream app that logs the user out locally had no standard way to also end the authup session — the "logout doesn't reach authup" half of the reported issue. This is deliberately not solved with a kit-specific store.logout() session delete (that stays local-only); the RP-agnostic answer is the OIDC standard end_session_endpoint.

What this adds

GET/POST /logout (OIDC RP-Initiated Logout, advertised as end_session_endpoint in discovery, no feature flag). Core logic is OAuth2EndSessionService. It's the mechanism any RP — kit or non-kit React/other — redirects to on its own logout.

Security posture (all enforced, full unit-test matrix):

  • id_token_hint is verified by the token verifier with a new ignoreExpiry option — signature, nbf and kind still apply; only exp is skipped (a logout hint is routinely expired). It threads down to server-kit's verifyToken (validateExp: false).
  • A hint whose kind !== id_token is rejected — access/refresh tokens also carry session_id, so accepting them would let a leaked access token force a logout. aud is cross-checked against client_id when both are present.
  • A verified hint carrying sid → the session is revoked immediately, but only after its sub/sub_kind match the hint's subject (never revoke someone else's session). Without a hint the endpoint mutates nothing — the SSR page's sign-out is a click-gated, bearer-authenticated store.logout().
  • post_logout_redirect_uri is honored only when it is absolute http(s) AND matches a registered client redirect_uri pattern (open-redirect guard); state rides only with a validated redirect, and an unverified hint's claims are never reflected.

Also: the SSR logout page (AEndSessionForm + apps/server-core/ui/src/pages/logout.vue), the discovery end_session_endpoint, and the typed buildEndSessionURL.

Testing

Full apps/server-core suite (1136) + @authup/server-kit (10, the verifyToken change) + @authup/i18n parity + @authup/client-web-kit green. New OAuth2EndSessionService matrix: valid hint verified; forged hint rejected; access-token-as-hint rejected (kind check); aud/client_id mismatch rejected; registered redirect honored; unregistered + javascript: redirect dropped; sub-match revoke vs sub-mismatch no-revoke. Plus discovery end_session_endpoint assertion.

Deferred follow-up

A dedicated post_logout_redirect_uri client column + migration + a WebClientProvisioner default + the client-web end-session round-trip — until then /logout validates against redirect_uri patterns.

Residual (documented)

Keycloak parity: a leaked valid id_token can force-logout its own session (an annoyance, not privilege escalation) — mitigated by the sub-match requirement and the short id_token TTL.

Summary by CodeRabbit

  • New Features

    • Added OIDC RP-initiated logout support, including a new logout endpoint, session verification/revocation flow, and logout redirect handling.
    • Exposed logout metadata in OpenID provider configuration so clients can discover the logout endpoint.
    • Added a logout page and confirmation form in the UI, with support for immediate sign-out when the session was already revoked.
    • Added logout URL building support for client-side sign-out redirects.
  • Bug Fixes

    • Tightened redirect validation to allow only safe absolute HTTP(S) logout redirects.

Copilot AI review requested due to automatic review settings July 7, 2026 17:15
@coderabbitai

coderabbitai Bot commented Jul 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@tada5hi, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 48 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 85b74e9f-cbac-4f18-89bc-129f57db0f35

📥 Commits

Reviewing files that changed from the base of the PR and between a708faa and 05bb11a.

📒 Files selected for processing (29)
  • .agents/architecture.md
  • apps/server-core/src/adapters/http/controllers/entities/realm/module.ts
  • apps/server-core/src/adapters/http/controllers/workflows/index.ts
  • apps/server-core/src/adapters/http/controllers/workflows/logout/index.ts
  • apps/server-core/src/adapters/http/controllers/workflows/logout/module.ts
  • apps/server-core/src/adapters/http/controllers/workflows/logout/types.ts
  • apps/server-core/src/app/modules/http/modules/controller.ts
  • apps/server-core/src/core/oauth2/end-session/index.ts
  • apps/server-core/src/core/oauth2/end-session/service.ts
  • apps/server-core/src/core/oauth2/end-session/types.ts
  • apps/server-core/src/core/oauth2/index.ts
  • apps/server-core/src/core/oauth2/token/verifier/module.ts
  • apps/server-core/src/core/oauth2/token/verifier/types.ts
  • apps/server-core/test/unit/core/oauth2/end-session/service.spec.ts
  • apps/server-core/test/unit/http/controllers/entities/realm-openid.spec.ts
  • apps/server-core/ui/src/app.ts
  • apps/server-core/ui/src/pages/logout.vue
  • docs/src/guide/development/api-oauth2.md
  • packages/client-web-kit/src/components/workflows/end-session/AEndSessionForm.vue
  • packages/client-web-kit/src/components/workflows/end-session/index.ts
  • packages/client-web-kit/src/components/workflows/index.ts
  • packages/client-web-kit/src/core/oauth2/authorization-request.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
  • packages/server-kit/src/crypto/json-web-token/verify/module.ts
  • packages/specs/src/openid/type.ts
📝 Walkthrough

Walkthrough

Adds OIDC RP-Initiated Logout support: a new /logout HTTP controller backed by OAuth2EndSessionService for id_token_hint verification and session revocation, end_session_endpoint OpenID metadata, ignoreExpiry token verification option, client-side UI logout page/form and buildEndSessionURL helper, i18n strings, and documentation.

Changes

RP-Initiated Logout Implementation

Layer / File(s) Summary
End-session and token verifier contracts
apps/server-core/src/core/oauth2/end-session/types.ts, .../token/verifier/types.ts, packages/specs/src/openid/type.ts
Defines OAuth2EndSessionRequest/Result/ServiceContext and IOAuth2EndSessionService, adds ignoreExpiry to OAuth2TokenVerifyOptions, and adds end_session_endpoint to OpenIDProviderMetadata.
OAuth2EndSessionService verify/revoke logic
apps/server-core/src/core/oauth2/end-session/{service,index}.ts, .../core/oauth2/index.ts, apps/server-core/test/unit/core/oauth2/end-session/service.spec.ts
Implements hint verification, client/audience matching, redirect URI validation, subject-matched revocation, with unit tests covering success/failure and redirect/revocation edge cases.
Token verifier ignoreExpiry propagation
apps/server-core/src/core/oauth2/token/verifier/module.ts, packages/server-kit/src/crypto/json-web-token/verify/module.ts
Propagates ignoreExpiry/validateExp through OCT, EC, and RSA token verification paths.
/logout HTTP controller and DI wiring
apps/server-core/src/adapters/http/controllers/workflows/logout/*, .../entities/realm/module.ts, apps/server-core/src/app/modules/http/modules/controller.ts, tests
Adds LogoutController (GET/POST), wires OAuth2EndSessionService into HTTPControllerModule, and exposes end_session_endpoint in realm OpenID metadata.
Logout UI page, form component, and URL builder
apps/server-core/ui/src/{app.ts,pages/logout.vue}, packages/client-web-kit/src/components/workflows/end-session/*, .../core/oauth2/authorization-request.ts, packages/i18n/*, .agents/architecture.md, docs/src/guide/development/api-oauth2.md
Adds logout page/route, AEndSessionForm component, buildEndSessionURL helper, i18n keys across catalogs, and documentation for the logout flow.

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

Sequence Diagram(s)

sequenceDiagram
  participant Browser
  participant LogoutController
  participant OAuth2EndSessionService
  participant SessionManager

  Browser->>LogoutController: GET/POST /logout (id_token_hint, client_id, post_logout_redirect_uri, state)
  LogoutController->>OAuth2EndSessionService: verify(request)
  OAuth2EndSessionService-->>LogoutController: hintVerified, sub, sessionId, redirectUri
  alt hintVerified and identifiers present
    LogoutController->>OAuth2EndSessionService: revoke(sessionId, sub, subKind)
    OAuth2EndSessionService->>SessionManager: revoke(sessionId)
  end
  alt redirectUri validated
    LogoutController-->>Browser: redirect to redirectUri (with state)
  else
    LogoutController-->>Browser: render logout UI page
  end
Loading

Possibly related PRs

  • authup/authup#2945: Both PRs modify apps/server-core/src/app/modules/http/modules/controller.ts, with the logout controller wiring in this PR depending on the DI container refactor introduced there.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding RP-initiated logout support via end_session_endpoint.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/oauth2-end-session

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.

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.

Pull request overview

Adds OIDC RP-Initiated Logout support to Authup by introducing a public end_session_endpoint (GET/POST /logout) that can verify id_token_hint, revoke the referenced session (when safe), and optionally redirect back to a validated client URL. This fits into the OAuth2/OIDC surface area by completing the session-binding/logout story alongside the discovery metadata and client kit helpers.

Changes:

  • Advertise and implement end_session_endpoint (/logout) with SSR UI + controller wiring and core OAuth2EndSessionService.
  • Extend token verification to optionally ignore exp for logout-hint verification, while retaining signature/nbf validation.
  • Add client-web-kit URL builder + workflow component and add i18n strings for logout UX.

Reviewed changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/specs/src/openid/type.ts Extends OpenID provider metadata type to include end_session_endpoint.
packages/server-kit/src/crypto/json-web-token/verify/module.ts Adds ignoreExpiry option to allow skipping exp validation when verifying logout hints.
packages/i18n/src/constants.ts Introduces new client-facing translation keys for logout UI.
packages/i18n/src/catalogs/fr/client.ts Adds French translations for logout UI strings.
packages/i18n/src/catalogs/es/client.ts Adds Spanish translations for logout UI strings.
packages/i18n/src/catalogs/en/client.ts Adds English translations for logout UI strings.
packages/i18n/src/catalogs/de/client.ts Adds German translations for logout UI strings.
packages/client-web-kit/src/core/oauth2/authorization-request.ts Adds buildEndSessionURL() helper for constructing RP-initiated logout URLs.
packages/client-web-kit/src/components/workflows/index.ts Exports the new end-session workflow.
packages/client-web-kit/src/components/workflows/end-session/index.ts Adds workflow barrel export for AEndSessionForm.
packages/client-web-kit/src/components/workflows/end-session/AEndSessionForm.vue Adds logout confirmation/done UI and local-store logout action.
apps/server-core/ui/src/pages/logout.vue Adds SSR page that hosts the end-session form.
apps/server-core/ui/src/app.ts Registers /logout UI route in the SSR router.
apps/server-core/test/unit/http/controllers/entities/realm-openid.spec.ts Tests discovery advertises end_session_endpoint.
apps/server-core/test/unit/core/oauth2/end-session/service.spec.ts Adds unit test matrix for end-session verify/revoke and redirect validation behavior.
apps/server-core/src/core/oauth2/token/verifier/types.ts Extends verifier options with ignoreExpiry.
apps/server-core/src/core/oauth2/token/verifier/module.ts Threads ignoreExpiry down into server-kit verifyToken.
apps/server-core/src/core/oauth2/index.ts Exports the new end-session module from oauth2 core index.
apps/server-core/src/core/oauth2/end-session/types.ts Defines request/result types and service interface for end-session logic.
apps/server-core/src/core/oauth2/end-session/service.ts Implements hint verification, redirect validation, and safe session revocation.
apps/server-core/src/core/oauth2/end-session/index.ts Adds end-session module barrel exports.
apps/server-core/src/app/modules/http/modules/controller.ts Wires LogoutController and OAuth2EndSessionService into the HTTP module container.
apps/server-core/src/adapters/http/controllers/workflows/logout/types.ts Defines logout controller context/options types.
apps/server-core/src/adapters/http/controllers/workflows/logout/module.ts Implements /logout GET/POST controller behavior (verify → revoke → redirect/SSR).
apps/server-core/src/adapters/http/controllers/workflows/logout/index.ts Adds barrel exports for logout controller.
apps/server-core/src/adapters/http/controllers/workflows/index.ts Exports logout workflow controller module.
apps/server-core/src/adapters/http/controllers/entities/realm/module.ts Adds end_session_endpoint to realm discovery response.
.agents/architecture.md Documents RP-initiated logout design, security posture, and residual behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@tada5hi
tada5hi force-pushed the feat/authorize-prompt-surface branch from c2fa21c to 9421447 Compare July 7, 2026 17:24
@tada5hi
tada5hi force-pushed the feat/oauth2-end-session branch from 6f3cd92 to 602d0f8 Compare July 7, 2026 17:25
@pkg-pr-new

pkg-pr-new Bot commented Jul 7, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

authup

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

@authup/client-web

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

@authup/server-core

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

@authup/access

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

@authup/client-web-kit

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

@authup/client-web-kit-theme

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

@authup/client-web-nuxt

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

@authup/client-web-theme

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

@authup/core-http-kit

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

@authup/core-kit

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

@authup/core-realtime-kit

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

@authup/errors

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

@authup/i18n

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

@authup/kit

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

@authup/server-adapter-kit

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

@authup/server-adapter-node

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

@authup/server-adapter-socket-io

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

@authup/server-adapter-web

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

@authup/server-kit

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

@authup/server-test-kit

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

@authup/specs

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

commit: a708faa

@tada5hi
tada5hi force-pushed the feat/authorize-prompt-surface branch from 9421447 to 675eecf Compare July 7, 2026 17:31
@tada5hi
tada5hi force-pushed the feat/oauth2-end-session branch from 602d0f8 to 5a5e82e Compare July 7, 2026 17:32
Base automatically changed from feat/authorize-prompt-surface to master July 7, 2026 17:33
@tada5hi
tada5hi force-pushed the feat/oauth2-end-session branch 2 times, most recently from 9449782 to a708faa Compare July 7, 2026 17:44
@tada5hi

tada5hi commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
✅ Action performed

Full review finished.


Your plan includes PR reviews subject to rate limits. More reviews will be available in 2 minutes.

@tada5hi

tada5hi commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
✅ Action performed

Full review finished.


Your plan includes PR reviews subject to rate limits. More reviews will be available in 42 seconds.

@tada5hi

tada5hi commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
✅ Action performed

Full review finished.

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

Actionable comments posted: 2

🧹 Nitpick comments (6)
packages/client-web-kit/src/core/oauth2/authorization-request.ts (2)

107-142: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

No unit tests for the new helper.

buildEndSessionURL has no accompanying spec despite being a new public export with several conditional branches (encoding, trailing-slash trimming, optional query params).

🤖 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/client-web-kit/src/core/oauth2/authorization-request.ts` around
lines 107 - 142, Add unit tests for buildEndSessionURL to cover the new public
helper’s behavior: verify trailing slashes are trimmed from baseURL, each
optional field in BuildEndSessionURLContext is included only when present, and
URLSearchParams encoding is applied correctly for query values. Place the tests
alongside the authorization-request helpers so the different branches in
buildEndSessionURL are exercised and future regressions are caught.

120-142: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider accepting the endpoint path/URL directly instead of hardcoding /logout.

buildEndSessionURL always appends /logout to baseURL, coupling this client helper to the exact server route path. If the discovery-provided end_session_endpoint ever diverges from ${baseURL}/logout (e.g., per-realm path segments), this helper would silently build an incorrect URL with no compile-time signal.

🤖 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/client-web-kit/src/core/oauth2/authorization-request.ts` around
lines 120 - 142, buildEndSessionURL is hardcoding the logout route by appending
/logout to baseURL, which makes it too tightly coupled to one server path.
Update buildEndSessionURL to accept and use the end-session endpoint URL/path
directly from BuildEndSessionURLContext (or derive it from discovery input)
instead of constructing it from baseURL, while keeping the existing query
parameter assembly for idTokenHint, clientId, postLogoutRedirectUri, state, and
realmId.
apps/server-core/src/adapters/http/controllers/workflows/logout/module.ts (1)

44-67: 🔒 Security & Privacy | 🔵 Trivial

Public, unauthenticated JWT-verification endpoint — consider rate limiting.

handle() performs signature verification on an arbitrary attacker-supplied id_token_hint on every request to this public, unauthenticated endpoint. This is spec-compliant (OIDC RP-Initiated Logout), but as with any public endpoint doing crypto verification of client-supplied tokens, it's worth ensuring upstream rate limiting/backoff exists to mitigate verification-cost DoS.

🤖 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/src/adapters/http/controllers/workflows/logout/module.ts`
around lines 44 - 67, The public logout endpoint handled by handle() in the
logout controller performs JWT signature verification on attacker-supplied
id_token_hint values, so add or confirm upstream rate limiting/backoff for this
route to reduce verification-cost DoS risk. Keep the OIDC RP-Initiated Logout
behavior intact, and ensure the protection is applied around the endpoint
exposed by this controller and its endSessionService.verify call path.
apps/server-core/src/core/oauth2/end-session/service.ts (1)

44-72: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Swallowed exceptions hide infra failures from validation failures.

The catch {} block treats every failure the same way — a forged signature and a JWKS-fetch/network error both silently result in hintVerified = false. That's safe by design, but it removes any observability into whether verification failed due to an actual bad hint vs. a transient dependency issue, which matters for a security-sensitive revoke path.

♻️ Suggested logging addition
-            } catch {
-                // forged / unverifiable hint → stays unverified (no revoke)
-            }
+            } catch (err) {
+                // forged / unverifiable hint → stays unverified (no revoke)
+                this.logger?.debug('id_token_hint verification failed', { err });
+            }
🤖 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/src/core/oauth2/end-session/service.ts` around lines 44 -
72, The `end-session` verification flow is swallowing all `tokenVerifier.verify`
failures in the `catch` block, making forged hints and infra/network errors
indistinguishable. Update the `catch` in `service.ts` around
`this.tokenVerifier.verify(...)` to log the verification failure with enough
context (without changing the no-revoke behavior), so `hintVerified` still stays
false but operational issues are observable.
packages/server-kit/src/crypto/json-web-token/verify/module.ts (1)

32-34: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Comment slightly overstates this function's scope.

This function only performs signature and nbf checks (plus optional exp); kind/issuer validation happens in the caller (e.g. OAuth2EndSessionService). Worth tightening the comment so future readers don't assume kind is enforced here.

✏️ Suggested comment tweak
-    // Signature, nbf and issuer/kind checks always apply; only exp is skipped
-    // when explicitly requested (e.g. an id_token_hint on RP-initiated logout).
+    // Signature and nbf checks always apply; only exp is skipped when
+    // explicitly requested (e.g. an id_token_hint on RP-initiated logout).
+    // Note: `kind`/issuer validation is performed by the caller, not here.
🤖 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/server-kit/src/crypto/json-web-token/verify/module.ts` around lines
32 - 34, The comment in the JWT verify module overstates what this function
enforces, since `verifyJwt` only handles signature and `nbf` checks plus
optional `exp`, while issuer/kind validation is done by the caller such as
`OAuth2EndSessionService`. Update the inline comment near `validateExp` in
`verify/module.ts` to reflect the actual scope and avoid implying `kind` is
validated here.
apps/server-core/test/unit/core/oauth2/end-session/service.spec.ts (1)

73-187: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add coverage for "no hint" and sub_kind mismatch on revoke.

Coverage is otherwise thorough, but two behaviors called out in the PR description aren't directly tested:

  • Calling verify()/the logout flow without id_token_hint should not mutate session state.
  • revoke() should reject a session match when sub matches but sub_kind differs (only sub mismatch is currently tested, at Line 173).
🧪 Suggested additional test cases
it('should NOT mutate session state without an id_token_hint', async () => {
    const service = buildService(async () => validPayload);
    const result = await service.verify({ client_id: clientId });

    expect(result.hintVerified).toBe(false);
    expect(result.sessionId).toBeUndefined();
});

it('should NOT revoke a session when sub matches but sub_kind differs', async () => {
    await sessionManager.create({
        id: sessionId,
        sub,
        sub_kind: OAuth2SubKind.CLIENT, // different sub_kind
        realm_id: realmId,
    });

    const service = buildService(async () => validPayload);
    const revoked = await service.revoke(sessionId, sub, OAuth2SubKind.USER);

    expect(revoked).toBe(false);
    expect(sessionManager.revokeCalls).toHaveLength(0);
});
🤖 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/core/oauth2/end-session/service.spec.ts` around
lines 73 - 187, Add test coverage in service.spec for the missing logout
behaviors: in the `buildService`/`verify` cases, assert that calling `verify()`
without `id_token_hint` leaves `hintVerified` false and does not set `sessionId`
or mutate state; in the `revoke` tests, add a case where `sessionManager.create`
uses the same `sub` but a different `sub_kind`, and verify `revoke(sessionId,
sub, OAuth2SubKind.USER)` returns false and does not call
`sessionManager.revoke`. Use the existing `verify`, `revoke`,
`sessionManager.create`, and `sessionManager.revokeCalls` helpers to keep the
new tests consistent with the current suite.
🤖 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 `@docs/src/guide/development/api-oauth2.md`:
- Around line 175-180: Clarify the `id_token_hint` logout behavior in the OAuth2
guide: the current wording in the `id_token_hint` description suggests any
signature-valid token revokes the session immediately, but
`OAuth2EndSessionService` also requires the hint’s `sub` and `sub_kind` to match
the session subject. Update the `id_token_hint` row to state that revocation
happens only when the verified hint matches the session subject, and that a
subject mismatch is ignored as a no-op.

In
`@packages/client-web-kit/src/components/workflows/end-session/AEndSessionForm.vue`:
- Around line 49-62: Add error handling around store.logout() in
AEndSessionForm.vue so both signOut and the onMounted auto-logout do not leave
unhandled rejections. Wrap the logout call in a try/catch (or shared helper) and
ensure done.value is updated appropriately after failures, especially in the
serverRevoked path where the UI should still transition away from the pre-logout
state. Refer to the signOut function and the onMounted callback when applying
the fix.

---

Nitpick comments:
In `@apps/server-core/src/adapters/http/controllers/workflows/logout/module.ts`:
- Around line 44-67: The public logout endpoint handled by handle() in the
logout controller performs JWT signature verification on attacker-supplied
id_token_hint values, so add or confirm upstream rate limiting/backoff for this
route to reduce verification-cost DoS risk. Keep the OIDC RP-Initiated Logout
behavior intact, and ensure the protection is applied around the endpoint
exposed by this controller and its endSessionService.verify call path.

In `@apps/server-core/src/core/oauth2/end-session/service.ts`:
- Around line 44-72: The `end-session` verification flow is swallowing all
`tokenVerifier.verify` failures in the `catch` block, making forged hints and
infra/network errors indistinguishable. Update the `catch` in `service.ts`
around `this.tokenVerifier.verify(...)` to log the verification failure with
enough context (without changing the no-revoke behavior), so `hintVerified`
still stays false but operational issues are observable.

In `@apps/server-core/test/unit/core/oauth2/end-session/service.spec.ts`:
- Around line 73-187: Add test coverage in service.spec for the missing logout
behaviors: in the `buildService`/`verify` cases, assert that calling `verify()`
without `id_token_hint` leaves `hintVerified` false and does not set `sessionId`
or mutate state; in the `revoke` tests, add a case where `sessionManager.create`
uses the same `sub` but a different `sub_kind`, and verify `revoke(sessionId,
sub, OAuth2SubKind.USER)` returns false and does not call
`sessionManager.revoke`. Use the existing `verify`, `revoke`,
`sessionManager.create`, and `sessionManager.revokeCalls` helpers to keep the
new tests consistent with the current suite.

In `@packages/client-web-kit/src/core/oauth2/authorization-request.ts`:
- Around line 107-142: Add unit tests for buildEndSessionURL to cover the new
public helper’s behavior: verify trailing slashes are trimmed from baseURL, each
optional field in BuildEndSessionURLContext is included only when present, and
URLSearchParams encoding is applied correctly for query values. Place the tests
alongside the authorization-request helpers so the different branches in
buildEndSessionURL are exercised and future regressions are caught.
- Around line 120-142: buildEndSessionURL is hardcoding the logout route by
appending /logout to baseURL, which makes it too tightly coupled to one server
path. Update buildEndSessionURL to accept and use the end-session endpoint
URL/path directly from BuildEndSessionURLContext (or derive it from discovery
input) instead of constructing it from baseURL, while keeping the existing query
parameter assembly for idTokenHint, clientId, postLogoutRedirectUri, state, and
realmId.

In `@packages/server-kit/src/crypto/json-web-token/verify/module.ts`:
- Around line 32-34: The comment in the JWT verify module overstates what this
function enforces, since `verifyJwt` only handles signature and `nbf` checks
plus optional `exp`, while issuer/kind validation is done by the caller such as
`OAuth2EndSessionService`. Update the inline comment near `validateExp` in
`verify/module.ts` to reflect the actual scope and avoid implying `kind` is
validated here.
🪄 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: d493fe01-6511-4968-8202-7c78145f5038

📥 Commits

Reviewing files that changed from the base of the PR and between 10da494 and a708faa.

📒 Files selected for processing (29)
  • .agents/architecture.md
  • apps/server-core/src/adapters/http/controllers/entities/realm/module.ts
  • apps/server-core/src/adapters/http/controllers/workflows/index.ts
  • apps/server-core/src/adapters/http/controllers/workflows/logout/index.ts
  • apps/server-core/src/adapters/http/controllers/workflows/logout/module.ts
  • apps/server-core/src/adapters/http/controllers/workflows/logout/types.ts
  • apps/server-core/src/app/modules/http/modules/controller.ts
  • apps/server-core/src/core/oauth2/end-session/index.ts
  • apps/server-core/src/core/oauth2/end-session/service.ts
  • apps/server-core/src/core/oauth2/end-session/types.ts
  • apps/server-core/src/core/oauth2/index.ts
  • apps/server-core/src/core/oauth2/token/verifier/module.ts
  • apps/server-core/src/core/oauth2/token/verifier/types.ts
  • apps/server-core/test/unit/core/oauth2/end-session/service.spec.ts
  • apps/server-core/test/unit/http/controllers/entities/realm-openid.spec.ts
  • apps/server-core/ui/src/app.ts
  • apps/server-core/ui/src/pages/logout.vue
  • docs/src/guide/development/api-oauth2.md
  • packages/client-web-kit/src/components/workflows/end-session/AEndSessionForm.vue
  • packages/client-web-kit/src/components/workflows/end-session/index.ts
  • packages/client-web-kit/src/components/workflows/index.ts
  • packages/client-web-kit/src/core/oauth2/authorization-request.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
  • packages/server-kit/src/crypto/json-web-token/verify/module.ts
  • packages/specs/src/openid/type.ts

Adds GET/POST /logout (OIDC RP-Initiated Logout, advertised as
end_session_endpoint) — the RP-agnostic way for a downstream app, kit or not,
to end a lingering authup session on its own logout.

OAuth2EndSessionService verifies the id_token_hint via the token verifier with a
new ignoreExpiry option (signature, nbf and kind still enforced; only exp is
skipped — a logout hint is routinely expired). A hint whose kind is not id_token
is rejected (access/refresh tokens also carry session_id, so accepting them
would let a leaked access token force a logout); aud is cross-checked against
client_id when both are present. A verified hint carrying sid revokes the
referenced session immediately, but only after its sub/sub_kind match the hint's
subject. Without a hint the endpoint mutates nothing — the SSR page's sign-out is
a click-gated, bearer-authenticated logout.

post_logout_redirect_uri is honored only when it is absolute http(s) and matches
a registered client redirect_uri pattern (open-redirect guard); state rides only
with a validated redirect. A dedicated post_logout_redirect_uri client column is
a deferred follow-up.

Ships the SSR logout page (AEndSessionForm), the discovery entry, and the typed
buildEndSessionURL. Stacked on the prompt-surface branch (plan 041 PR C).
@tada5hi
tada5hi force-pushed the feat/oauth2-end-session branch from a708faa to 05bb11a Compare July 7, 2026 18:03
@tada5hi
tada5hi merged commit 865520c into master Jul 7, 2026
7 checks passed
@tada5hi
tada5hi deleted the feat/oauth2-end-session branch July 7, 2026 18:06
@github-actions github-actions Bot mentioned this pull request Jul 7, 2026
tada5hi added a commit that referenced this pull request Jul 8, 2026
…-ups) (#3197)

* fix: rp-initiated logout & authorize hardening (plan 041 audit follow-ups)

Post-merge fixes for defects and test gaps surfaced by an audit of plan 041
(#3194/#3195/#3196). Closes plan 042 items #1, #11 and most of #12.

Security / correctness:
- AEndSessionForm gates its on-mount local sign-out on
  `serverRevoked && hintSub === store.user.id` — a cross-site
  /logout?id_token_hint=<attacker's own token> can no longer force-log-out an
  unrelated victim who merely renders the page (forced-logout CSRF). The
  controller forwards `hintSub` (verified hints only) into the payload.
- LogoutController bounces back to the RP only when the logout was actually
  performed (serverRevoked && validated redirect). A hint-less or forged
  request renders the click-gated confirm page and redirects after sign-out,
  instead of 302-ing back while the session survives.
- Authorize.vue: a fresh login no longer re-prompts prompt=select_account
  (LoginForm `done` sets accountConfirmed), and the chooser waits for `user`
  to resolve (no empty-name flash).
- /authorize hydration payload trimmed to a ClientSummary DTO (no redirect_uri
  patterns, grant_types, internal URLs, secret flags).
- prompt=none removed from discovery prompt_values_supported + docs (its
  silent-auth error redirect is unimplemented).
- empty `max_age=` is treated as absent instead of coercing to 0
  (z.coerce.number('') === 0 would force re-authentication).
- AuthorizeForm renders a "Signed in as X - Not you?" switch chip (+ i18n).
- Remove the dead OAuth2AuthorizationCode.auth_time field; use specs enums for
  prompt/error string comparisons instead of literals.

Tests:
- /logout HTTP e2e matrix (revoke, redirect+state, hint-less no-op,
  access-token/forged hint no-revoke, unregistered redirect dropped).
- server-kit ignoreExpiry (expired+valid-sig accepted; bad-sig/nbf rejected).
- auth_time passthrough + auth_time!=refreshed_at pins; redirectUriVerified;
  confidential refresh exemption; cross-realm login_required no-identity-oracle
  body; clickjacking headers + trimmed-DTO; max_age empty-vs-0; kit gate spec.

* fix: use a button for the "Not you?" switch affordance

The account-switch affordance is an action, not navigation — render it as a
<button type="button"> styled like a link instead of an <a href="#"> so it has
correct button semantics and keyboard behavior (Enter/Space activation), and
matches the rest of the form's actions.

* fix: reliably skip the account chooser after a fresh login on /authorize

The prompt=select_account chooser reappeared right after entering
username/password on the hosted /authorize page. The previous fix keyed off
LoginForm's `done` emit, but on login the access-token flip re-renders
Authorize and unmounts LoginForm before `done` fires, so the flag that skips
the chooser was never set — the chooser stayed.

Key off the store's LOGGED_IN dispatcher event instead. It is emitted only by
an explicit login() (the form), never by a session restored from cookies
(resolve() → RESOLVED), so a lingering session still gets the chooser while a
fresh login skips it — independent of component mount/unmount timing.

Adds a component spec pinning all three cases (lingering shows, LOGGED_IN
skips, RESOLVED does not suppress).
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