fix(dashboard): RP-initiated logout fallback for non-compliant IdPs#526
Merged
Conversation
The dashboard's logout flow inherits Daytona upstream's call to `signoutRedirect()` (react-oidc-context / oidc-client-ts), which navigates the browser to the IdP's `end_session_endpoint` from the OIDC discovery document. Auth0 advertises this endpoint, so the upstream flow Just Works. BoxLite ships Dex as the default IdP. Dex does not advertise `end_session_endpoint` (dexidp/dex#1697, open since 2019), so oidc-client-ts throws `Error("No end session endpoint")` and the dashboard gets stuck on its "Authentication Error / Go Back" dialog at `https://<stack>/?code=…&state=…`. Fix in three layers: 1. API hosts an OIDC-compatible logout endpoint at `/api/auth/end-session`. Open-redirect prevention is a strict origin-match against `DASHBOARD_URL` plus an operator-set `OIDC_POST_LOGOUT_REDIRECT_ALLOWLIST`. State param preserved. New `apps/api/src/auth/logout.controller.ts`. 2. API decides at runtime whether to expose the fallback. New `OidcMetadataService` probes the IdP's discovery doc once at startup (replaces the inline fetch in `auth.module.ts`) and exposes a tri-state `getEndSessionState(): 'present' | 'absent' | 'unknown'`. The `ConfigurationDto` only emits `endSessionEndpoint` when the IdP definitively lacks one (`'absent'`); on probe failure ('unknown') it stays undefined — fail-closed prevents an Auth0/Okta stack from silently routing logout through BoxLite if discovery has a transient blip. `oidc-client-ts.js:827` applies `metadataSeed` LAST, so this would otherwise override Auth0's real endpoint. 3. Dashboard `ConfigProvider.tsx` passes `metadataSeed: { end_session_endpoint }` to AuthProvider only when the API reports the field. `App.tsx` auth-error dialog's "Go Back" handler now calls `removeUser()` and navigates to `/` instead of re-calling the same `signoutRedirect()` that just failed — breaks the sticky-error loop. SST wires `OIDC_END_SESSION_ENDPOINT` unconditionally to `https://<stackDomain>/api/auth/end-session`. Safe because the API gates its exposure on the discovery probe; Auth0/Okta stacks see no behaviour change. README documents the Auth0 "RP-Initiated Logout End Session Endpoint Discovery" toggle that pre-Nov-2023 tenants need to flip. Note: `apps/libs/api-client/src/models/oidc-config.ts` is hand-patched to add the optional `endSessionEndpoint` field. The next OpenAPI codegen pass will regenerate it from the API schema; the hand edit keeps types and runtime in sync until then.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The dashboard's logout flow inherits Daytona upstream's
signoutRedirect()call (react-oidc-context / oidc-client-ts), which navigates the browser to the IdP'send_session_endpointfrom OIDC discovery. Auth0 advertises that endpoint, so upstream Just Works.BoxLite's default IdP is Dex, which does not advertise
end_session_endpoint(dexidp/dex#1697, open since 2019).oidc-client-tsthrowsError("No end session endpoint")and the dashboard gets stuck on itsAuthentication Error / Go Backdialog athttps://<stack>/?code=…&state=…. The "Go Back" button re-calls the same failingsignoutRedirect()— the dialog is sticky.Root cause
Two distinct bugs, one tenant-config issue:
Fix
Three-layer fix that's zero-config for compliant IdPs and self-healing for the rest.
API
LogoutControllerat/api/auth/end-session— implements OIDC RP-Initiated Logout 1.0. Open-redirect prevention is strict origin-match againstDASHBOARD_URL+ an operator-setOIDC_POST_LOGOUT_REDIRECT_ALLOWLIST. State param preserved across the redirect.OidcMetadataService— singleton that probes the IdP's discovery doc once at startup, caches the result, and exposesgetEndSessionState(): 'present' | 'absent' | 'unknown'. Replaces the inline fetch previously embedded inauth.module.ts. Fails closed on probe error so a transient blip doesn't override Auth0's real endpoint.ConfigurationDto.oidc.endSessionEndpointis only emitted when the probe returns'absent'. Validates the env-set URL before exposing it (typos don't propagate asmetadataSeedvalues).Dashboard
ConfigProvider.tsxconditionally passesmetadataSeed: { end_session_endpoint }toAuthProvider.oidc-client-ts.js:827merges this LAST, after discovery — so the fallback wins iff the field is set.App.tsxauth-error dialog's "Go Back" handler now callsremoveUser()and navigates to/instead of re-callingsignoutRedirect(). Breaks the sticky-error loop.Infra
sst.config.tswiresOIDC_END_SESSION_ENDPOINT=https://<stackDomain>/api/auth/end-sessionunconditionally. Safe because the API gates exposure on the discovery probe — Auth0/Okta stacks see no behaviour change.apps/infra/README.mddocuments the Auth0 toggle for pre-Nov-2023 tenants + a troubleshooting entry for the failure mode.Test plan
/api/auth/end-session→ 302 to dashboard, session cleared.dev-j60pjpmu6neaeaga.us.auth0.com, toggle enabled):curl /api/config | jq .oidc.endSessionEndpointreturnsnull. Sign out navigates to/oidc/logouton Auth0 directly, terminates the session cookie, no silent re-auth./cleanly instead of re-triggering the same error.curl -i '/api/auth/end-session?post_logout_redirect_uri=https://evil.example.com'→ 400.Known limitations / follow-ups
apps/libs/api-client/src/models/oidc-config.tsis hand-patched to add the optionalendSessionEndpointfield. The next OpenAPI codegen pass will regenerate it from the API schema; the hand edit keeps types and runtime in sync until then. Follow-up: runnx run api-client:generate:api-client./token/revoketo invalidate the refresh token. Skipped in this PR — the security delta is small onceremoveUser()clears local storage and the IdP terminates its own session. Tracked for a follow-up.