Skip to content

feat(auth): OIDC Back-Channel Logout 1.0 — notifier + admin config + UI + tests - #61

Merged
wangrh0909 merged 12 commits into
masterfrom
feat/oidc-backchannel-logout
Aug 16, 2026
Merged

wangrh0909 merged 12 commits into
masterfrom
feat/oidc-backchannel-logout

Conversation

@voidvec

@voidvec voidvec commented Aug 14, 2026 •

Copy link
Copy Markdown
Owner

What

Real OIDC Back-Channel Logout 1.0 — replaces the LoggingBackchannelLogoutNotifier stub. On logout the OP finds every relying party with an active session for the user and a registered backchannel_logout_uri, and POSTs a signed logout_token to each (fire-and-forget). Includes the full config path (admin API + admin UI), endpoint test coverage, and fixes for the two review findings (#55, #57).

Design doc: docs/productization-evolution/in-progress/backchannel-logout-design.md (§评审问题修复 for the #55/#57 details).

Key finding (verified)

oauth2_access_tokens.user_id stores the public subject (public_sub), identical to the userId notify() receives (TokenService.cc:172,343) and to the id_token sub → no subject mapping needed.

Changes

logout_token

RS256 JWT (same OP key/kid as id_token). Claims: {iss, sub, aud=clientId, iat, exp=iat+120, jti, events={"http://schemas.openid.net/event/backchannel-logout":{}}}; no nonce. POSTed as application/x-www-form-urlencoded logout_token=<jwt>.

Tests (green locally)

  • Unit: LogoutTokenTest (claim set/no nonce, exp=iat+ttl, jti uniqueness) · BackchannelLogoutNotifierTest (per-client fan-out, skip empty URI, transport failure audited + others notified, non-200=failure/200=success, RS256 signature verifies against the signing key, completion-after-dispatch) · Unit_P0_Validation_BackchannelLogoutUri_AllScenarios — now 27 cases: scheme, structure, private-host matrix (incl. 172.32 public boundary, v4-mapped, metadata IP), length cap, hatch-vs-private precedence.
  • Endpoint suites (sh+ps1): admin Tests 44–46 (set/read/clear lifecycle · non-https 400 via ftp:// · create-with-uri + read-back + cleanup; suite 52→55) and discovery Test 3 asserts both backchannel flags.
  • Full local 8-step pipeline: 462/462 ctest; admin frontend npm run build (tsc + vite) clean.

Follow-ups (not blocking)

Full e2e POST-to-RP integration test (needs a mock RP listener) · sid issuance (clients with backchannel_logout_session_required=true — documented gap) · cross-client token revocation on logout · configurable HTTP timeout/retry · RP response-body validation · RFC 7591 backchannel_logout_uri · DNS-rebinding-grade SSRF protection (literal-IP scope documented in design doc §九).

Safety

Default config (no client has a backchannel_logout_uri) → zero POSTs, identical to prior behavior.

Fixes #55, fixes #57

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

voidvec added 12 commits August 15, 2026 22:56
The outbound-HTTP port (IOAuthHttpClient) and its Drogon adapter
(DrogonOAuthHttpClient) were only compiled under WITH_SOCIAL because their
sole consumer was social login. OIDC Back-Channel Logout (B1) is a core
feature that needs the same postForm() transport to deliver logout_tokens,
so the port + adapter can no longer be social-gated.

- Drop the #ifdef WITH_SOCIAL guards from IOAuthHttpClient.h and
  DrogonOAuthHttpClient.{h,cc} (FakeOAuthHttpClient was already ungated).
- Move IOAuthHttpClient.h out of the social-only header group in
  libs/identity/CMakeLists.txt so it is a declared public header regardless
  of WITH_SOCIAL. DrogonOAuthHttpClient.cc was already always compiled by
  the GLOB; its body now defines symbols unconditionally.

No behavior change for social builds; non-social builds now also provide the
port + adapter.
First slice of B1 (OIDC Back-Channel Logout 1.0): the real notifier and the
pure logout_token claim builder, with full unit coverage. Wiring into the
logout flow + admin/UI config follow in subsequent commits.

- libs/oauth2: LogoutToken.{h,cc} -- pure buildLogoutTokenClaims() (iss/sub/
  aud/iat/exp/jti/events, no nonce per spec §2.4) + generateJti(). Unit tests
  assert the exact claim set, exp=iat+ttl, and jti uniqueness.
- libs/drogon: BackchannelLogoutNotifier -- the real Adapter-layer
  IBackchannelLogoutNotifier. notify() chains two async Mapper queries (active
  tokens for the user -> distinct client_ids -> clients with a
  backchannel_logout_uri, no JOIN per db-operations.md) then dispatch().
  dispatch() signs a per-RP logout_token and POSTs it fire-and-forget,
  auditing each attempt; logout responses are never blocked by RP round-trips.
  enable_shared_from_this + per-Mapper try-catch that always reaches the
  callback.
- libs/drogon/test: dispatch unit tests (D1-D6) with an ephemeral-key
  JwkManager + FakeOAuthHttpClient + FakeAuditSink, including RS256 signature
  verification of the logout_token against the signing key.

Not yet wired into IdentityAssembly (still uses the logging stub).
- IdentityAssembly: replace the LoggingBackchannelLogoutNotifier stub with
  the real BackchannelLogoutNotifier (dbClient + plugin signing key/issuer/
  audit sink + the shared DrogonOAuthHttpClient). Move oauthHttpClient
  construction out of the WITH_SOCIAL block so the notifier always has a
  transport (social reuses the same instance).
- SessionController: delete the dead sendBackchannelLogoutNotifications()
  stub; the sessionManager_==null branch (memory/no-DB configs, where there
  are no clients to notify) now just responds.
- DiscoveryController: advertise OIDC Back-Channel Logout 1.0 support --
  backchannel_logout_supported=true, backchannel_logout_session_supported=
  false (subject-scoped logout_tokens, no sid).
The backchannel_logout_uri column (V015) was writable nowhere -- admin API,
RFC 7591 registration, and the admin UI all ignored it, so the notifier added
in the previous commit could never be exercised in production. This wires the
write/read path through the client admin service.

- RuleSet: new validateBackchannelLogoutUri() -- OIDC §2.3 https requirement
  (empty == not configured), honoring the auth.allow_http_redirect_uri dev
  hatch; loopback NOT exempt (server-to-server).
- ClientManagementService: createClient/updateClient read, validate (https),
  and persist backchannel_logout_uri (empty on update clears it to NULL);
  getClient/listClients surface backchannel_logout_uri (+ session_required on
  the detail endpoint).
- openapi.yaml: add requestBody schemas (with backchannel_logout_uri) to
  POST/PUT /api/admin/clients -- these operations previously had none.
…s row

Mark Backchannel Logout backend as delivered on feat/backchannel-logout-b1
(notifier + logout_token builder + admin config + discovery + unit tests
D1-D6), and record that the admin-UI forms are ready but blocked by a Mimosa
false-positive on pre-existing mock-api.ts fixtures, and that integration
tests are pending (need PostgreSQL).
- ApplicationDetailPage (Auth Config tab): editable Backchannel Logout URI,
  loaded from getClient and sent on save (only when changed).
- ApplicationsPage (create modal): optional Backchannel Logout URI field,
  included in the create payload.
…overy endpoint tests

- ValidatorTest: Unit_P0_Validation_BackchannelLogoutUri_AllScenarios —
  https valid, empty valid (not configured), scheme-less/ftp invalid; http
  expectations read from the live config because the test env enables
  auth.allow_http_redirect_uri (dev hatch honored by the validator). Loopback
  http is NOT free (unlike redirect_uri) — gated by the same hatch.
- Admin endpoint suite (sh+ps1): Test 44 backchannel_logout_uri
  set/read/clear lifecycle; Test 45 non-https scheme rejected 400 (ftp:// —
  plain http is not a reliable negative under the dev hatch); Test 46 create
  client with backchannel_logout_uri + read-back + cleanup. ps1 $total 52→55.
- OAuth2 endpoint suite (sh+ps1): Test 3 discovery now asserts
  backchannel_logout_supported=true and backchannel_logout_session_supported
  =false (subject-scoped logout_tokens, no sid).
Test 44/45 hit /api/admin/clients/api-service, which is a frontend e2e MOCK
id — no such client exists in the seed data, so Test 44's first PUT returned
404 (Test 45 passed only because scheme validation (400) fires before the
client lookup). Target the seeded vue-client instead; the lifecycle test
restores it (clears to NULL) immediately.
…1 delivery

Restores the memory-verdict updates lost when the working tree was
switched to feat/user-management-crud-v2 (the previous edits were never
committed), and syncs all tracking docs with the newly delivered work:

Memory verdict (⚠️ → ✅, re-applied across 4 docs):
- SDK embedding scope measured 2026-08-13: third-party-host-smoke
  (pure SDK) peak working set 2.5 MB / private 0.6 MB / binary 12 MB;
  full-stack-host-smoke (SDK+Drogon) also 2.5 MB peak
- 50-120MB claim conservatively MET — actual SDK logic layer far below
- docker stats 2.4GB is a different scope (container: pools + shared
  libs + page cache), not comparable to the SDK claim

Newly delivered work synced:
- A2 user management CRUD — IMPLEMENTED (PR #52): pagination, search,
  createUser, updateUser expansion, deleteUser soft-delete (V024)
- D1 Backchannel Logout — BACKEND DELIVERED (PR #50): notifier +
  logout_token JWT + admin API + discovery + unit tests D1-D6;
  frontend blocked by Mimosa false-positive, integration tests pending
- Phase 2 completion raised ~25% → ~45%; Phase 0 raised ~85% → ~90%
- IAM audit: user mgmt + backchannel logout rows updated to delivered
- next-phase plan: completed-tiers table extended, A2/B1 sections
  marked delivered, dependency graph + risk matrix + decision items
  updated (decisions 1-3 now resolved)
The notifier was wired into POST /oauth2/logout only; every logout flow the
product itself performs (end_session from the user portal, revoke-only from
the admin console) bypassed it, so zero logout_tokens were ever delivered
while discovery advertised backchannel_logout_supported: true.

- endSession now notifies: subject from the browser session's "sub"
  (login() now stores the PUBLIC subject next to the internal-id userId --
  the internal id does not match oauth2_access_tokens.user_id), falling back
  to the id_token_hint's sub claim. Both success terminals (302 redirect +
  200) notify; 400/500 error terminals do not. JWT hint decode extracted to
  decodeJwtPayloadClaims (sub + aud in one pass, was an inline aud-only
  block).
- Admin console logout: the access-token /oauth2/revoke call is replaced by
  POST /oauth2/logout with the bearer token (revokes + notifies); the
  refresh-token revoke is kept. e2e mock gains the /oauth2/logout route.
- User portal needs no change: its end_session call now notifies.
- BackchannelLogoutNotifier.h header now enumerates the trigger paths.

Fixes #55
… crash safety

validateBackchannelLogoutUri accepted anything with an https:// prefix: no
host/structure check ("https://", userinfo, fragments passed), no
private-IP rejection, no length cap — and the OP POSTs a signed
logout_token server-side to the stored URI on every logout.

- Full structure validation: length <= 512 (column width), non-empty host,
  no userinfo, no fragment, well-formed IPv6 brackets.
- Reject loopback/private/link-local host literals (localhost; v4 0/8,
  10/8, 127/8, 172.16/12, 192.168/16, 169.254/16; v6 ::, ::1, fc00::/7,
  fe80::/10, v4-mapped) unless the NEW dedicated opt-in
  auth.allow_private_backchannel_logout_uri permits them — deliberately NOT
  the allow_http_redirect_uri browser-redirect hatch. Literal-IP scope
  only; DNS-rebinding coverage is documented as delivery-side (design doc
  §九).
- DrogonOAuthHttpClient: both methods now wrap newHttpClient/sendRequest in
  try/catch and degrade to a transport-failure callback (audited as a
  failed delivery) — a degenerate stored URI can no longer throw inside an
  async DB callback and kill the event loop.
- Validator test extended to 27 cases (structure, private-host matrix
  incl. 172.32 public boundary, length, hatch-vs-private precedence).

Fixes #57
…d-line-only)

CI's api-diff gate flagged the WITH_SOCIAL guard-line removals in
IOAuthHttpClient.h / DrogonOAuthHttpClient.h as BREAKING (2 removed lines
each). The declarations are byte-identical; un-gating only makes the same
symbols compile unconditionally (additive in effect, no caller breaks --
WITH_SOCIAL builds are unchanged, non-social builds gain the port). Ratified
with --force per the established convention (f28eeb5, 8e83813, 6254209);
also picks up the additive validateBackchannelLogoutUri declaration.
@voidvec
voidvec force-pushed the feat/oidc-backchannel-logout branch from 0bd1ae4 to 4993bb3 Compare August 15, 2026 15:18
@wangrh0909
wangrh0909 merged commit a9a1bf8 into master Aug 16, 2026
8 checks passed
@voidvec
voidvec deleted the feat/oidc-backchannel-logout branch August 22, 2026 12:56
voidvec added a commit that referenced this pull request Aug 25, 2026
…log, next-phase plan

progress-status: Phase 0 verdicts refreshed to 2026-08-23 TTL=30
comparison (five-scenario lead, cold-start 1.26s); Phase 1 ~60% (PyPI
1.4.0 live, README badge done); Phase 2 ~50% (backchannel full-stack
PR #61 + social link/unlink PR #68); perf-optimization workstream added;
issue section rewritten to current 15 open issues in 4 categories;
milestones extended through v1.4.0 (2026-08-24).

iam-architecture-audit: Backchannel Logout upgraded from
'backend delivered' to full-stack (PR #61, #55/#57 hardening, leftover
#82); social link/unlink row annotated with 5 follow-up issues
(#69/#70/#71/#73/#54); footer baseline bumped to v1.4.0.

SUMMARY.md: staleness banner — numbers superseded by optimization
program + competitor comparison; points to COMPARISON.md as authority
(S2 8.9k→14.4k, S6 16.7k→49.3k etc.); original kept as pre-optimization
baseline record.

next-phase-implementation-plan (4th revision): all seven original
workstreams (A1/A2/A3-badge/B1/B2/C1/C3) marked delivered; new focus =
Tier1 security batch (#78 end_session signature verify, #79/#80 cache
refill race, #54 soft-delete social bypass) → Tier2 social fixes
(#69 token hash mismatch 401, #71 state validation, #70 mappings,
#73 guard race) → Tier3 blog (M1) + docs site (M2) → Tier4 hygiene
(#81/#72/#82/#83/#84/#66 + stale branch cleanup); parallel-safety map,
risks, and 4 decision items.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants