Repository navigation
fix(auth): OIDC login-loop hardening — interactive fallback on login_required, preserve pending logins - #31181
Conversation
… pending logins (#30304) - /callback with login_required/interaction_required/consent_required/ account_selection_required: redirect to interactive /signin instead of 500. These are the IdP's spec-defined 'silent auth not possible' replies (e.g. prompt=none with no IdP session); a 500 loops the frontend. - /callback with no pending session (stale/consumed cookie): redirect to /signin instead of 500 — the stale cookie is already cleared. - acquireRefreshLease on a PENDING (in-flight) login: return empty (401) WITHOUT clearing the session cookie — a concurrent tab's refresh timer must not break the login round-trip at the IdP. Root cause reproduced end-to-end on 1.13.1 + mock OIDC provider (issue #30304, Okta confidential + offline_access): login -> concurrent refresh -> user completes Okta -> callback fails -> loop. Test added for the pending-lease race. Co-Authored-By: Claude Opus 4.8 <[email protected]>
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically. Maintainers can bypass this check by adding the |
There was a problem hiding this comment.
Pull request overview
This PR hardens the OIDC authentication code flow to prevent server-side login loops in confidential-client deployments (e.g., Okta with offline_access) by (1) providing an interactive fallback for spec-defined “silent auth not possible” errors and stale pending sessions, and (2) ensuring concurrent refresh attempts don’t invalidate an in-flight login.
Changes:
- Add interactive fallback redirect (
/signin) from/callbackwhen the IdP returnslogin_required/interaction_required/ related silent-auth errors. - Redirect to
/signin(instead of 500) when the callback cookie references no live pending session. - Prevent
/refreshfrom clearing cookies or mutating sessions when the session isPENDING(login in-flight), plus add a regression unit test.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| openmetadata-service/src/main/java/org/openmetadata/service/security/session/SessionService.java | Avoids clearing session cookie / mutating state when refresh races with an unexpired PENDING login session. |
| openmetadata-service/src/main/java/org/openmetadata/service/security/AuthenticationCodeFlowHandler.java | Redirects to interactive signin for missing pending session and for spec-defined silent-auth error codes instead of returning 500. |
| openmetadata-service/src/test/java/org/openmetadata/service/security/session/SessionServiceTest.java | Adds unit coverage ensuring PENDING sessions don’t get their cookie cleared or session mutated during refresh lease acquisition. |
| if (response instanceof AuthenticationErrorResponse authenticationErrorResponse) { | ||
| LOG.error( | ||
| "Bad authentication response, error={}", authenticationErrorResponse.getErrorObject()); | ||
| // login_required & friends are the IdP's spec-defined "silent auth not possible" | ||
| // replies (e.g. prompt=none with no IdP session). Fall back to interactive signin | ||
| // instead of a 500 the frontend cannot recover from. | ||
| if (SILENT_AUTH_ERRORS.contains(authenticationErrorResponse.getErrorObject().getCode())) { | ||
| resp.sendRedirect(serverUrl + "/signin"); | ||
| return; | ||
| } | ||
| throw new TechnicalException("Bad authentication response"); | ||
| } |
✅ Playwright Results — workflow succeededValidated commit ✅ 796 passed · ❌ 0 failed · 🟡 0 flaky · ⏭️ 0 skipped · 🧰 0 lifecycle flaky PerformanceBlocking targets: ✅ met · Optimization targets: 🟡 in progress Shard-job maxima below are not the full workflow wall time; the linked run includes build, fixture, planning, and reporting. 🕒 Full workflow signal wall (to summary) 1h 1m 38s ⏱️ Max setup 3m 2s · max shard execution 20m 56s · max shard-job elapsed before upload 24m 29s · reporting 6s 🌐 215.24 requests/attempt · 2.67 app boots/UI scenario · 15.13% common-shard skew Optimization targets still in progress:
How to debug locally# Download playwright-test-results-<shard> artifact and unzip
npx playwright show-trace path/to/trace.zip # view trace |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (2)
openmetadata-service/src/main/java/org/openmetadata/service/security/AuthenticationCodeFlowHandler.java:490
login_required/silent-auth errors are being logged at ERROR before you short-circuit to an interactive redirect. Since these errors are expected in the silent-auth flow, this will generate noisy/false-positive ERROR logs in normal operation. Consider checking the error code first and logging at DEBUG/INFO for the silent-auth fallback, reserving ERROR for truly unexpected authentication errors.
if (response instanceof AuthenticationErrorResponse authenticationErrorResponse) {
LOG.error(
"Bad authentication response, error={}", authenticationErrorResponse.getErrorObject());
// login_required & friends are the IdP's spec-defined "silent auth not possible"
// replies (e.g. prompt=none with no IdP session). Fall back to interactive signin
// instead of a 500 the frontend cannot recover from.
if (SILENT_AUTH_ERRORS.contains(authenticationErrorResponse.getErrorObject().getCode())) {
resp.sendRedirect(serverUrl + "/signin");
return;
}
throw new TechnicalException("Bad authentication response");
openmetadata-service/src/main/java/org/openmetadata/service/security/AuthenticationCodeFlowHandler.java:468
- This behavior change (no pending session at callback now redirects to
/signininstead of returning a 500) likely breaks the existing unit testAuthenticationCodeFlowHandlerTest#handleCallback_noPendingSession_writesErrorResponse, which currently asserts a 500 + body containing "No pending session found for callback". The PR should update that test (and any similar ones) to assert the redirect behavior.
Optional<UserSession> maybePendingSession = sessionService.getPendingSession(req, resp);
if (maybePendingSession.isEmpty()) {
// The cookie points at no live pending session (invalidated, restarted, or already
// consumed). A 500 here strands the browser in a login loop; getPendingSession has
// already cleared the stale cookie, so route the user to interactive signin instead.
LOG.warn("No pending session found for callback, redirecting to signin");
resp.sendRedirect(serverUrl + "/signin");
return;
Code Review ✅ ApprovedHardens OIDC login flow to prevent server-side session loss during concurrent refreshes and redirects silent-auth errors to interactive sign-in. No issues found. OptionsDisplay: compact → Showing less information. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
Fixes #30304 (Okta confidential client login loop — this PR is the server-side half).
Root cause (reproduced end-to-end)
On a confidential OIDC deployment, the login loop is server-side session loss amplified by error handling:
/api/v1/auth/loginwrites the session cookie immediately, but the session only becomes usable at/callback. A concurrent/refresh(another tab's expiry timer, shared cookie) landing in that window broke the pending login — the user completes Okta/WebAuthn and their own callback then fails.login_required& friends (the IdP's spec-defined "silent auth not possible" replies, e.g.prompt=nonewith no IdP session) returned HTTP 500 with no recovery path./callbackalso returned 500.Reproduced deterministically against
server:1.13.1+ the repo's mock OIDC provider (confidential client,offline_access): the exact sequencelogin → concurrent refresh → complete Okta → callbackfailed into a loop. The same defects exist on main in the new SessionService architecture (verified by code path).Changes
handleCallback:login_required/interaction_required/consent_required/account_selection_required→ 302 to/signin(interactive) instead of 500.handleCallback: missing pending session → 302 to/signin(stale cookie already cleared) instead of 500.SessionService.acquireRefreshLease: PENDING (in-flight) login → return empty (401) without clearing the session cookie — a concurrent refresh no longer breaks the login round-trip.Testing
acquireRefreshLease_pendingLogin_returnsEmptyWithoutClearingCookieOrSession(fails without the fix).login_requiredat/callbackredirects to/signin; non-silent errors keep the 500; no-pending-session callback asserts the redirect.SessionServiceTest: 32/32 green;AuthenticationCodeFlowHandlerTest: 33/33 green.login_required→ interactive signin; healthy login+refresh unchanged.Sibling PRs: 2.0 (cherry-pick of this commit) and 1.13 (equivalent hotfix for the in-memory HttpSession architecture).
🤖 Generated with Claude Code