Repository navigation
fix(bff): end a login whose IdP session got a back-channel logout before its row - #525
Merged
Merged
Conversation
Owner
Author
Review findings that stay openTwo review rounds ran on this branch. These findings stay open, each with its reason.
Out of scope, seen during the checks:
|
Owner
Author
|
Maintainer decision on the open medium: keep the spec precondition (an IdP must refuse a code for a session that it ended). Keycloak and Authentik obey it. No second clock rule in this PR. |
… one-transaction back-channel logout The model comes from fv/bff-session. It now describes the code at b43c777: the jti and the session deletes commit in one transaction, so JtiInSameTransaction, ForgetAsync, and BackChannelFixed.cfg are gone, and G2 holds. The line references name the code at that commit. check.sh prints only ok lines. G1 still breaks on BackChannel.cfg: a back-channel logout that comes before the login row commits is lost.
…ore its row A back-channel logout that came after the code exchange and before the login wrote its row found no row, and the login then created one that stayed signed in. The replay cache row now keeps the sid, the sub, and the iat of the token. The login transaction takes IdpSessionLock, reads these records, and refuses a login of the same IdP session if a record was issued at or after the iat of its ID token, less 5 s for the clocks of the IdP. The auth_time is not used: an SSO login keeps the auth_time of the first authentication, so after an IdP that keeps the session past its logout token (the Keycloak consent revoke), each SSO login would fail until the record expires. The logout takes the same lock before the find. A login also fails at its deadline, the challenge plus RemoteAuthenticationTimeout, and a record lives at least until the last such deadline, so the cleanup never deletes a record that a login in flight needs. A refused login gets the 400 problem of a failed callback. The bff-session-lifecycle model describes the fix. BackChannel.cfg holds every rule, and two new configs show that the lock and the deadline are each needed.
pdevito3
force-pushed
the
fix/bff-logout-after-login
branch
from
November 15, 2026 18:19
09761a6 to
2fb490f
Compare
pdevito3
added a commit
that referenced
this pull request
Nov 16, 2026
…sh commits on main (#533) ## Why The formal verification skills must stay true to the code on main. The three TLA+ skills recorded sync commits from their PR branches. A squash merge left those commits off main, so the `git log <sync>..HEAD` check in each skill named a commit that main does not have. ## What changed - `bff-session-lifecycle` now syncs to `a1637f8a` (#525). `object-storage-lifecycle` syncs to `d4c3fef7` (#526). `membership-lifecycle` syncs to `adeb4db0` (#528). - The skills cited other branch commits as history. Each of those now names the main commit that holds the same code, which is #519 or #521. ## Scope - No change to a model, a config, or `check.sh`. The covered code that main changed after each branch point does not change what the models describe. - No product code changes. ## Blast Radius Only skill text changes, so the app is not affected. An agent that uses these skills now compares against commits that exist on main. ## Verification - `bff-session-lifecycle/model/check.sh` printed only `ok` lines. `object-storage-lifecycle/check.sh` kept every config at its baseline. `membership-lifecycle/check.sh` passed all 4 configs. - `scripts/remove-examples.cs` and the example-name grep of `without-examples.cs` passed on a copy of this branch. The full script stopped at its Docker check because Docker Desktop did not start.
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.
Why
Stacked on #521.
A back-channel logout can come after the code exchange of a login and before the login writes its BFF session row. The logout then finds no row and answers 200, and the login creates a row that stays signed in. Now the record of the logout token ends that login.
What changed
sid, thesub, and theiatof the logout token.EfBffSessionStore.CreateAsyncreads these records in the login transaction, and refuses a login of the same IdP session if a record has aniatat or after theiatof the ID token of the login, less 5 s for the clocks of the IdP.IdpSessionLocktakespg_advisory_xact_lockon thesuband thesidof the login, and on thesid(or thesub) of the logout token. Thus each logout commits before the read of the login, or finds the row after the login commits.LoginTimesputs a deadline in the protectedstateat the challenge: the challenge plusRemoteAuthenticationTimeout. A login at its deadline fails, and a logout record lives at least that long after its receipt, so the cleanup never deletes a record that a login in flight still needs. A refused login gets the 400 problem of a failed callback.Scope
bff-session-lifecyclemodel. The model, the spec, and the authentication doc describe the fix.sid, and another row of the same browser can have thatsid.Tradeoffs
LoginRefusedException, becauseITicketStore.StoreAsyncreturns only a key. A middleware beforeUseAuthenticationmaps it to the 400.UseExceptionHandlerwould clear the deletes of the correlation and nonce cookies.iatof the ID token, not itsauth_time. An SSO login keeps theauth_timeof the first authentication. Keycloak sends a logout token for thesidwhen a user revokes the consent of the client, and keeps the SSO session. Withauth_time, each SSO login after that failed until the record expired.Blast Radius
Each login now runs one transaction with two advisory locks and one indexed read, and waits for a back-channel logout of its IdP session. A login that began before the deploy has no deadline in its
state, so its callback gets 400 one time, and the user logs in again. The migration adds three columns and two indexes toused_logout_tokens. Its old rows have nosidorsub, so they end no login. Until each instance runs this code, an old instance writes the row of a login with no lock and no read of the records.Verification
dotnet build FullstackTemplate.slnxhas 0 warnings.tests/FullstackTemplate.Bff.Testspasses 541 of 541 in 4 of 4 runs.sidor of thesubthat comes during the held code exchange, and a login at its deadline, each got 302 where 400 was expected. The record lifetime test got an expiry before the receipt plusRemoteAuthenticationTimeout. With the lock removed, the test of a logout during the read of the records saw no lock wait, and left a readable row after the logout answered 200. With theauth_timewindow, the SSO login after a logout of itssidthat the IdP kept got 400 where 302 was expected. An ID token with no readableiat(an encrypted token, or no claim) passedLoginTimes.Ofand later failed withArgumentOutOfRangeException. It now fails there with a clear message.auth_timemapper of thebasicscope: log in, revoke the consent of the client (Keycloak sends a logout token for thesidand keeps the SSO session), and log in again by SSO 6 s later. Theauth_timeversion answered 400 and left no session. This version answers 302 with the samesid. A scratch spec ran this, and it is not in the PR.pnpm test:e2e:stackon Keycloak: 11 passed, and 3 skipped for features that this stack does not turn on (DPoP, a refresh on each call)..agents/skills/bff-session-lifecycle/model/check.shprints onlyok.BackChannel.cfgholds every rule in 82,555 states, where beforeBackChannelLogoutEndsSessionsbroke.BackChannelNoLock.cfgandBackChannelNoDeadline.cfgeach remove one part of the fix, and that rule breaks in each.