Repository navigation
feat: validate & harden the rp-initiated logout endpoint (plan 042) - #3198
Conversation
- add OAuth2EndSessionRequestValidator: length caps on every /logout param, blank params treated as absent, realm hint canonicalized (trim + lowercase) at the ingress; on validation failure the controller falls back to a parameter-less confirm page instead of a JSON error (every attacker-controlled value dropped, no revoke) - add endSessionHintGracePeriod config (END_SESSION_HINT_GRACE_PERIOD): seconds past exp an expired id_token_hint is still accepted for a server-side revoke; default 0 keeps spec/Keycloak parity (unbounded), a positive window bounds how long a leaked id_token stays a replayable remote logout (exp-less payloads fail closed) - set Referrer-Policy: no-referrer on every SSR auth page (the URLs carry id_token_hint / code / redirect / state) - redact sensitive query params (id_token_hint, tokens, code, client_secret) from access-log lines - a GET /logout?id_token_hint= <jwt> no longer writes a signature-valid token into the log
📝 WalkthroughWalkthroughThis PR hardens the ChangesLogout Endpoint Hardening
Estimated code review effort: 3 (Moderate) | ~30 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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: |
There was a problem hiding this comment.
🧹 Nitpick comments (2)
apps/server-core/src/adapters/http/controllers/workflows/logout/module.ts (1)
55-60: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winLog validation failures for observability.
The
catchblock silently swallows all errors, including potential non-validation bugs in the validator (e.g.,TypeError). A debug-level log — without echoing the attacker-controlled input — would help distinguish expected validation rejections from unexpected runtime errors during incident investigation.📝 Suggested addition
let data: OAuth2EndSessionRequest; try { data = await this.validator.run(merged); } catch (e) { + // eslint-disable-next-line no-console + console.debug('Logout request validation failed, falling back to parameter-less confirm page', e instanceof Error ? e.message : e); data = {}; }🤖 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 55 - 60, The logout flow’s validation fallback in the `module.ts` controller currently swallows every exception from `this.validator.run(merged)`, which hides unexpected runtime bugs. Update the `catch` around `this.validator.run` to emit a debug-level log with a clear message and the thrown error, while avoiding any attacker-controlled request data; keep the existing `data = {}` fallback for expected validation failures. Use the `validator.run` call in the logout module as the fix location.apps/server-core/test/unit/core/oauth2/end-session/validator.spec.ts (1)
52-62: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAdd max-length rejection tests for remaining fields.
Tests cover
id_token_hintandstatemax-length rejection, butclient_id(256),realm_id(256),realm_name(256), andpost_logout_redirect_uri(2000) max-length boundaries are untested. Adding these would ensure length limits aren't accidentally relaxed.🧪 Suggested additional tests
it('should reject a non-URL post_logout_redirect_uri', async () => { await expect(validator.run({ post_logout_redirect_uri: 'not a url' })).rejects.toThrow(); }); + + it('should reject an oversized client_id', async () => { + await expect(validator.run({ client_id: 'x'.repeat(300) })).rejects.toThrow(); + }); + + it('should reject an oversized realm_id', async () => { + await expect(validator.run({ realm_id: 'x'.repeat(300) })).rejects.toThrow(); + }); + + it('should reject an oversized realm_name', async () => { + await expect(validator.run({ realm_name: 'x'.repeat(300) })).rejects.toThrow(); + }); + + it('should reject an oversized post_logout_redirect_uri', async () => { + await expect(validator.run({ post_logout_redirect_uri: `https://example.com/${'x'.repeat(2000)}` })).rejects.toThrow(); + }); });🤖 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/validator.spec.ts` around lines 52 - 62, Add max-length rejection coverage in validator.spec for the remaining EndSessionValidator fields that currently lack boundary tests. Extend the existing validator.run rejection cases to include oversized client_id, realm_id, realm_name, and post_logout_redirect_uri inputs, using the same style as the current id_token_hint and state tests so the length limits enforced by the validator stay covered.
🤖 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 `@apps/server-core/src/adapters/http/controllers/workflows/logout/module.ts`:
- Around line 55-60: The logout flow’s validation fallback in the `module.ts`
controller currently swallows every exception from `this.validator.run(merged)`,
which hides unexpected runtime bugs. Update the `catch` around
`this.validator.run` to emit a debug-level log with a clear message and the
thrown error, while avoiding any attacker-controlled request data; keep the
existing `data = {}` fallback for expected validation failures. Use the
`validator.run` call in the logout module as the fix location.
In `@apps/server-core/test/unit/core/oauth2/end-session/validator.spec.ts`:
- Around line 52-62: Add max-length rejection coverage in validator.spec for the
remaining EndSessionValidator fields that currently lack boundary tests. Extend
the existing validator.run rejection cases to include oversized client_id,
realm_id, realm_name, and post_logout_redirect_uri inputs, using the same style
as the current id_token_hint and state tests so the length limits enforced by
the validator stay covered.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 701a9ec0-a13b-4b67-b020-f829fcb99708
📒 Files selected for processing (20)
.agents/architecture.mdapps/server-core/src/adapters/http/controllers/workflows/logout/module.tsapps/server-core/src/adapters/http/middleware/built-in/logger.tsapps/server-core/src/adapters/http/ui/render.tsapps/server-core/src/app/modules/config/constants.tsapps/server-core/src/app/modules/config/normalize.tsapps/server-core/src/app/modules/config/read/env.tsapps/server-core/src/app/modules/config/types.tsapps/server-core/src/app/modules/config/validator.tsapps/server-core/src/app/modules/http/modules/controller.tsapps/server-core/src/core/oauth2/end-session/index.tsapps/server-core/src/core/oauth2/end-session/service.tsapps/server-core/src/core/oauth2/end-session/types.tsapps/server-core/src/core/oauth2/end-session/validator.tsapps/server-core/test/unit/core/oauth2/end-session/service.spec.tsapps/server-core/test/unit/core/oauth2/end-session/validator.spec.tsapps/server-core/test/unit/http/controllers/workflows/logout/end-session.spec.tsapps/server-core/test/unit/http/middleware/logger.spec.tsdocs/src/guide/deployment/configuration-server-core.mddocs/src/guide/development/api-oauth2.md
Plan 042 items 4, 2, and 5 — the
/logouthardening bundle (follow-ups to #3196/#3197).Request validation (item 4)
LogoutControllerpreviously readid_token_hint/client_id/post_logout_redirect_uri/state/realm_id/realm_nameraw from body+query. A newOAuth2EndSessionRequestValidator(mirroring the authorize code-request validator) now runs over the merged input:id_token_hint≤ 4096,post_logout_redirect_uri≤ 2000 + URL check,state≤ 2048)?state=) treated as absent, not as failuresrealm_id/realm_namehint canonicalizedtrim().toLowerCase()at the ingress (canonical-identifier-form layer 3, same contract as the token endpoint'sreadRealmHint) — a mixed-case realm hint previously failed closed and silently dropped the redirect validationBounded expired-hint window (item 2)
New config
endSessionHintGracePeriod(END_SESSION_HINT_GRACE_PERIOD, seconds): with a positive value, an id_token_hint expired beyond the window counts as unverified — bounding how long a leaked id_token stays a replayable remote logout. Post-verifyexpcheck inOAuth2EndSessionService(no server-kit change); exp-less payloads fail closed under a bounded window. Default0= unbounded, spec/Keycloak parity — the effective bound then remains session lifetime, since a hint can only revoke the live, sub-matched session itssidreferences.Endpoint hardening (item 5)
Referrer-Policy: no-referreron every SSR auth page (renderUIPageis the single choke point; the page URLs carryid_token_hint,code,redirect,state)id_token_hint,id_token,access_token,refresh_token,token,code,client_secret) — aGET /logout?id_token_hint=<jwt>previously wrote the signature-valid token verbatim into thelogger.httplineSec-Fetch-Siteconfirm gate (a legitimate RP-initiated logout is a cross-site top-level navigation; the forced-logout CSRF is already mitigated by the sub-match +hintSubgate) and no/logout-specific rate limit (the global identity-tiered limiter covers it; a hint can only revoke its own sub-matched session, so there is no amplification)Tests
end-session/service.spec.ts(default-unbounded, beyond/within window, unexpired, exp-less fail-closed)end-session/validator.spec.ts(canonicalization, blank-as-absent, caps, URL check)http/middleware/logger.spec.ts(redaction incl. repeated params, untouched non-sensitive URLs)logout/end-session.spec.ts: hardening headers, mixed-case realm hint resolves the client (asserted via hydration payload), malformed input drops all params without revokingFull server-core suite green (1172 tests). Note:
grant-authorize.spec.ts› "should work with authorize grant for confidential client" is a pre-existing flake (FK violation inSessionTokenRepositoryAdapter.createwhen a concurrent worker deletes the backing session mid-grant) — it failed two full-suite runs and passed a third with identical code, and passes in isolation; unrelated to this diff.Summary by CodeRabbit
New Features
Bug Fixes