Skip to content

Phase B5: OIDC revocation cascades and back-channel logout - #2045

Merged
neuromechanist merged 20 commits into
feature/issue-2014-epic-oidc-providerfrom
feature/issue-2019-phase5-oidc-revocation-cascades-and-back
Nov 5, 2026
Merged

neuromechanist merged 20 commits into
feature/issue-2014-epic-oidc-providerfrom
feature/issue-2019-phase5-oidc-revocation-cascades-and-back

Conversation

@neuromechanist

@neuromechanist neuromechanist commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Phase B5 of the OIDC provider epic (#2014), issue #2019. Ending a credential now also ends the account's OpenID Connect grants, tokens and unused codes in the same database batch, disabling a client revokes everything it holds, and each client that registered a back-channel logout address is told, with retries and a fence that keeps a dev Worker from calling a real partner host. A revoked person cannot be restored to a working relying-party session by re-approval.

Depends on #2018 (B4). Unblocks #2020. The website needs no change. Compute suspension is not wired: its state does not exist, so this phase ships the {scopePrefix: "compute."} filter and the compute_suspended reason and tests the filter directly; the compute access phase adds the caller.

Round 1 (review of this PR): what changed

Opus checkpoint (no Critical or Important) and Sonnet verification (two Important, three Moderate, one Low), all fixed on this branch in eight further commits, grouped by topic.

  • Important 1, a fault in the first attempt was logged nowhere: attemptDueLogouts never throws, so the .catch after it (and the sweep's try/catch) was dead and the tally was discarded. deferLogoutDelivery and the sweep now log [oidc-logout] first attempt errors=N errorClass=X (a count and the error's class only) from the tally. Test: a wrapD1 fault on the claim and on the due read, one line exactly, no error text, address, token or subject; the sweep's path too; nothing logged for a clean run.
  • Important 2, the "list is ignored in production" test could not fail: it used a named host, which is sent to either way. It now registers hosts that are both local-or-literal AND named in OIDC_LOGOUT_DEV_HOSTS (loopback, localhost, [::1], a private literal, app.localhost) under ENVIRONMENT: "production": each is failed / address_refused with nothing asked of the shim; the same pair is in the pure verdict tests.
  • Minor 3, the caller scan missed an aliased import, the function passed as a value and a raw *_SQL constant: rewritten (backend/test/helpers/oidc-end-scan.ts, mine, independent of A8's) to resolve the module's import bindings (named, aliased, namespace, destructured namespace, alias chains, assignments) and flag every other use outside the module as a stray: a value, a raw statement, a dynamic import() or require() (of the module or of a name it cannot read), a re-export, a default import, an element access or spread of the namespace, a module-level reference. The raw constants stay exported (the issue asks for them) and the *_SQL names are read from the module itself, so a new one is guarded. Every case is planted and shown caught.
  • Minor 4 and 5, ADR wording: rule 12 now says a new path adds to OIDC_END_CALLERS and to the docs and private lists only when it also runs their statements; only the sweep (not the owner's soft delete) runs the tombstone statements conditional on the mask.
  • Minor 6, registration versus send-time disagreed about a trailing dot: isLocalOrLiteral folds every trailing dot (the refusing side) and isLoopbackHost one (a first-party loopback address outside production), so https://localhost./x is refused in production at registration as it is at send time. Dotted forms added to the registry and verdict tables.
  • Ruling a, throttling: a 408 or 429 is retried on the same six-attempt schedule with the new class http_throttled; its Retry-After (seconds or an HTTP date) is read as a LOWER bound for the next wait, capped at 12 hours; the body is still never read; a Retry-After on any other answer is not read; every other 4xx stays failed. http_throttled is in the closed vocabulary (shared/oidc.ts) and, because migration 0124 is unreleased, last_error_class is now a closed IN (...) list in the CHECK instead of a shape, held equal as a set to the vocabulary (as are reason and status), on both engines.
  • Ruling b, retention: the production tick prunes finished deliveries after its delivery work, at most 500 a tick, oldest first: sent and fenced older than 30 days, failed older than 180, never pending (which includes an attempt in flight). Named constants in shared/oidc.ts, commented as defaults the owner sets before the first client registers. A dev or staging Worker has no tick and is not pruned (said in the ADR). The table has no last-update column, so sent ages by sent_at and fenced and failed by created_at.
  • Rulings c, d and e: the retry waits stay documented earliest times (no faster cron); no cookie flag on the new owner routes (one ADR sentence says why: a planted cookie is the attacker's own non-owner session and fails the owner check, and requiring the flag would switch the incident tool off while the flag is off); unreported is not retried (a seventh request would break the six-request bound while the partner may already hold the token). An owner re-send command that makes a NEW row is not built (open point below).
  • Moderate 10: tests for unreported (a claim that never recorded is re-claimed when the lease lapses, the sixth attempt is still made after five such claims, and with all six claimed the delivery is failed / unreported with no request), for the send-time refused-address record through attemptDueLogouts (loopback addresses, and a cleared address, under production), and the constants pinned (OIDC_LOGOUT_LEASE_SECONDS === 120 and above the 5 second timeout); the timing-based lease test is replaced by a deterministic one that reads the lease the claim statement wrote.
  • Moderate 11: the migration test reads each IN (...) list from sqlite_master.sql and compares it as a set to OIDC_END_REASONS, OIDC_LOGOUT_STATUSES and OIDC_LOGOUT_ERROR_CLASSES; OIDC_LOGOUT_TIMEOUT_MS is pinned to 5000 and the accepted window is under 6500 ms; the oidc-token-store test no longer feeds one list through itself (the words are literals, and the token-revoking statement of an ending and of a client disabling are asserted by shape and bind).
  • Moderate 12: the end-account question said "the person is asked again", which is wrong for a first-party client. It now says a third-party client asks for consent again and a first-party client does not (exported as endAccountQuestion and tested); the help and the ADR say the owner pairs end-account with a revocation or a deletion for a merge loser (round 2 corrected the first version of this sentence, which also named a kind change: it is no substitute, see below), because its app sessions and keys survive and it can regain a first-party grant at once.
  • Low 13: the clause "an answer that could not be read" is gone from network (no path produces it); the sender test header and this body no longer say two tests need fetchImpl (see the corrected statement below); the openssl stand-in reports the cause of a failure (made.error?.message); soft delete and the sweep now have the "re-approving restores nothing" test (the UPDATE that undoes the status and the delete stamp, with a comment saying a tombstone has no approval route); AddressVerdict and finishWithoutSend take typed pairs (a mismatched status and class is a compile error, shown), and the end reason is a z.enum with a message that never echoes the value (as OidcAccountEndReason is gone).

Round 2 (delta review of this PR): what changed

The delta reviewer found no Critical or Important defect and closed all 13 round-1 items; it reproduced four findings, fixed here in four commits (one per finding), each verified against the code before it was fixed.

  • F1 (Moderate), the kind-change claim was false for active_account clients. The end-account help and ADR rule 12 said revoking, deleting or changing the kind away from person "ends the grants themselves". A kind change ends only the grants of person_proven_orcid clients, and a non-person account still meets active_account, so it keeps its other grants and signs in again at once (reproduced against the real Worker). Revocation and deletion end every grant the account holds. The merge-loser instruction is now: run end-account and then revoke or delete the account (in that order, because the revocation or deletion then finds nothing live, so the tokens and logouts keep the merge as their reason); a kind change is dropped from every merge-loser sentence. Tests: a kind change keeps the account's active_account grants and a new sign-in works through the real authorization routes while the person_proven_orcid client refuses it; the merge procedure through the real routes for revoke and for delete (reason kept, nothing queued twice, the real authorization check refuses the loser) and the reverse order (the revocation reason is kept and end-account finds nothing); the ADR and help pins now fail on the old sentence.
  • F2 (Moderate), a Retry-After of 11 or more digits was ignored instead of capped: parseRetryAfter accepted {1,10} digits, so a longer run counted as no header and the one-minute wait applied. It now accepts a run of digits of any length and caps digits and dates at OIDC_LOGOUT_RETRY_AFTER_MAX_SECONDS in the parser (a 400-digit run, which is not a finite number, is the cap too); recordOf takes the longer of that and the schedule. Other forms are unchanged (-5, 1e3, NaN, ISO dates, a past date). Tests: 12, 25 and 400 digits, and a long run of leading zeros, through the sender (the wait equals the cap), and a pure table for the parser. The cap moved from recordOf to the parser, so round 1's mutation of the cap in recordOf no longer exists; the parser mutations below replace it.
  • F3 (Low), stale statements. With the cap at 12 hours a failed row's last attempt can come about 63 hours after its creation, not "under a day": the ADR retention paragraph, the comment in shared/oidc.ts, ADR rule 15's "six attempts over fifteen to eighteen hours" and the consequences sentence now say within three days, with the figure derived from the constants (five waits of at most 12 hours, each taken up at the next half-hour tick, and the first attempt, give 63 hours at the most; the schedule alone is fifteen to eighteen). A test derives it from the constants and the cron expression and pins the ADR and the comment. The failed line of the logout-deliveries help now says what is final (a redirect, a 4xx other than 408 and 429, any answer that is not a 200, a 204, a 408, a 429 or a 5xx), what is retried until the attempts are used (a 5xx, a 408, a 429, no answer in time, a connection that failed, a token NEMAR could not sign) and what is never sent; it was read from the code by classifying every status from 200 to 599 through the real sender against a real HTTPS partner, and that table is now a test.
  • F4 (Low), the caller scan missed an exported alias: export const endIt = oidcEndStatements; (and let, var, a cast, an exported destructured alias or namespace member, an alias chain, export let f; f = oidcEndStatements) made no call and passed no value, so a caller in another file could hide behind it. An alias whose name is exported by its declaration is now a stray, reported once; const f = x; export { f } and export default stay flagged as values. Tests parse planted source with the real scanner, one case per form (thirteen), and a guard that exports which are not aliases of the cascade are not flagged. Both headers (the scan helper and the callers test) now say: a call that is present but never executed, or whose result is discarded, passes this scan; the behavioural suites prove each path runs its statements.

Round 2 mutations, each reverted and run with the guarding file as its own argument. F1: the old help sentence restored (1 test), the old ADR sentence restored (1), a kind change that ends every grant (3, one new), a later ending that re-stamps tokens already revoked (5 in the end-account file, 4 of them new), revocation that does not end the grants itself (1, new). F2: restore the 10-digit limit (2: the sender and the parser table), digits not capped in the parser (2), a date not capped in the parser (2), Retry-After replaces the schedule (3), the ADR wording removed (1). F3: the old help line (1), the old retention sentence in the ADR (1), in the shared comment (1), the old faster-cron sentence (1), the old consequences sentence (1), a 429 treated as final (9), the cap raised to three days (1). F4: remove the export check (1), no de-duplication (1), exported names never collected (1), no declaration contributing a name (1), names inside an exported pattern ignored (1), and an exported alias added to a real Worker file (1, in the real-tree test).

What to look at

  • backend/src/services/oidc-cascade.ts: the four statements and their order (queue the logouts from the live grants BEFORE they are revoked, revoke the tokens, revoke the grants, delete the unused codes), the filter (it selects GRANTS; everything under a grant goes with it), every join on oidc_clients.id (the row id, per the B3 amendment), and OIDC_END_CALLERS, the list the docblocks count and oidc-cascade-callers.test.ts holds to the code by reading the syntax tree.
  • Every caller adds the statements INSIDE its existing batch: finalizeRevocation, tombstoneUserCascade (through step(), so the sweep's guarded call keeps them conditional on the mask having applied), unlinkOrcid, relinkIdentity, applyKindChange (new), endAccount (new owner route).
  • backend/src/services/oidc-logout.ts and oidc-logout-store.ts: the outbound request is the main risk surface. Read logoutAddressVerdict (fence), postLogoutToken (redirect: "manual", 5 second signal, answer body cancelled and never read, the one header read is Retry-After of a 408 or 429, only a Content-Type header and one form field sent), attemptOne and the claim statement (one conditional UPDATE decides which runner sends), recordOf (retry versus failed, the Retry-After lower bound), and runOidcLogoutRetryTick (delivery work, then the prune).
  • No network call is made inside any batch. The first attempt is handed to waitUntil after the commit (deferLogoutDelivery), and oidc-logout-callers.test.ts proves per caller that the response arrives while a slow partner is still thinking and that the partner is then told.
  • The fence fails closed the other way from isNonProductionEnv: only ENVIRONMENT exactly production sends to an arbitrary https host, so an unset or mistyped value is fenced.
  • ADR 0119 (still proposed): rule 12 gains the cascade function, order, filters and callers; rule 15 holds the delivery, token, request, fence, owner routes and retention; consequences and open questions; the index line, AGENTS.md hard rule and implementation notes are updated; the wording is pinned by test/adr-0119-wording.unit.test.ts.

Every path that ends a credential today

Found by grepping every write of revoked_at on tokens and web_sessions, every write of users.status, deleted_at and account_kind, and every delete of oauth_identities. The Opus checkpoint enumerated them independently and found none missing its cascade.

Path What it now does to OIDC grants and tokens Test
POST /admin/revoke/:username and /by-id/:id (finalizeRevocation) ends all, reason account_revoked, logouts queued, first attempt after commit oidc-cascade.test.ts (both routes), oidc-logout-callers.test.ts
DELETE /admin/users/by-id/:id (tombstoneUserCascade) ends all, account_deleted, subject kept oidc-cascade.test.ts, oidc-logout-callers.test.ts
Sweep of the live tests' accounts (same function, guarded) same; the sweep makes the first attempt itself because no tick runs outside production; a changed address ends nothing oidc-cascade.test.ts (sweep and "a guarded tombstone"), oidc-logout-callers.test.ts
POST /auth/orcid/unlink ends only person_proven_orcid grants, orcid_changed oidc-cascade-filters.test.ts, oidc-logout-callers.test.ts
ORCID callback relink (relinkIdentity) same same
POST /admin/users/:username/kind away from person (applyKindChange) same filter, kind_changed; a change to person ends nothing same
POST /admin/oidc/accounts/:id/end (nemar admin oidc end-account), the ADR 0043 manual merge step and incident tool ends all, account_merged or account_revoked; ends only the OIDC holdings oidc-end-account.test.ts
POST /admin/oidc/clients/:client_id/disable revokes every token, grant and unused code of the client, queues nothing; also finishes a client disabled before this phase oidc-client-disable.test.ts
Compute suspension not built; oidcEndStatements(id, "compute_suspended", {scopePrefix: "compute."}) is tested directly oidc-cascade-filters.test.ts
Role demotion untouched on purpose (docblock sentence) oidc-cascade-nonmembership.test.ts
API key revocation: DELETE /auth/keys/:id and /current, DELETE /admin/users/:username/keys/:id, GET /auth/confirm-key-regeneration untouched on purpose (docblock sentence) oidc-cascade-nonmembership.test.ts
POST /auth/logout untouched on purpose, the departure ADR 0119 marks as the owner's decision (comment sentence) oidc-cascade-nonmembership.test.ts

The docs and private docblock counts (DOCS_GRANTS_PURGE_SQL five callers, PRIVATE_GRANTS_PURGE_SQL three) are unchanged because no new path runs those statements; their docblocks point at OIDC_END_CALLERS, which has its own count (six callers of oidcEndStatements, one of oidcClientEndStatements).

Decisions for the owner

These are defaults or readings I implemented inside the issue and the rulings; say if any is wrong.

  • Retention windows: 30 days for sent, 30 for fenced, 180 for failed, 500 rows a tick (constants in shared/oidc.ts, ADR rule 15). Defaults pending you, to be set before the first client registers; also data minimisation, since a row holds the sub of possibly deleted accounts. Dev and staging are not pruned.
  • Retry-After is honoured only for 408 and 429, only as a lower bound, capped at 12 hours. A Retry-After on a 503 is not read.
  • last_error_class is a closed list in the migration CHECK (the migration is unreleased, edited in place; migrations:d1-check run once afterwards).
  • The new owner routes do not require HOST_PREFIXED_SESSION_COOKIE (ADR sentence added).
  • The kind-change path is wired although the issue's Changes list omits it, with the reason word kind_changed (the ADR's table and the first acceptance criterion require it).
  • unreported is a failed end state, not retried.
  • A merge loser is ended with end-account and then revoked or deleted, in that order; a kind change is not a way to cut an account off (round 2).
  • A Retry-After of any length is accepted and capped at 12 hours; the longest a failed delivery's attempts can last is 63 hours (round 2).
  • A fresh jti for every attempt (a retry is a new token); the row's jti is the last attempt's.
  • The stand-in partner is a real HTTPS server on loopback with a throwaway certificate made by openssl at test time (nothing is committed), because the registry and the table refuse any non-https logout address, loopback included.
  • "Both relink statements": there is one relink batch (relinkIdentity); the cascade is added there and the RELINK_* constants in services/orcid-auth.ts are unchanged.

Corrected statement about fetchImpl

attemptDueLogouts takes fetchImpl and timeoutMs options. fetchImpl is used in five tests, all in the sender suite's fence tests: it records the address the sender asked for and forwards the request to the loopback stand-in. Two run outside production (a fenced host, where it shows that nothing was asked, and a listed host, where it shows that only that host was asked); three run in production, which refuses a loopback address by design, so the stand-in is reachable only through the shim (one sends to a named host; two refuse an address and assert the shim is never called). My first round said it was used only where a production environment must be exercised, which was wrong.

Open points

  • An owner command that re-sends a failed or unreported delivery as a NEW row (so the six-request bound still holds for each row) is not built; listed in the ADR.
  • A retry wait of 1 or 5 minutes is the earliest time; the tick runs every half hour, so it is taken up at the next half hour (no faster cron, by ruling). Outside production nothing retries: the first attempt and the sweep's are the only attempts.
  • The escalation trigger (the design's compute suspension wording versus the narrower ADR rule) did not fire: the design page and ADR 0119 both say only the grants that carry a compute. scope.

Mutation evidence

Each line is one mutation of one line of production code (or of the scan helper), run with the guarding test file as its own argument, and reverted (git status clean after each). Survivors found along the way are listed after the table with what was done about them.

Mutation Fails
remove the statements from finalizeRevocation / tombstoneUserCascade / unlinkOrcid / relinkIdentity / applyKindChange / endAccount 6 / 5 / 2 / 2 / 2 / 5 tests, and the caller scan wherever the call itself is removed
tombstoneUserCascade runs the OIDC statements unguarded "a guarded tombstone"
relink ends every grant instead of only person_proven_orcid relink tests
add the cascade to role demotion, key revocation or sign-out the matching non-membership test
disable: drop the three statements / only the grants statement 3 / 2 disable tests
enqueue without the logout-address predicate / with disabled clients / with revoked grants 7 / 1 / 1 tests
re-stamp already revoked tokens / delete used codes 2 / 6 tests
filter ignored (rule, scopePrefix) / filtered grants statement ignores the filter 6 / 3 / 6 tests
queue the logouts after the grants are revoked 7 tests
sender follows redirects / sends an Authorization header / reads the answer body redirect tests / token test / "never read" test
timeout class lost / timeout 5000 to 9000 and to 6000 / token lifetime 120 to 600 / nonce added / typ JWT one named test each
retry delay changed / seventh attempt allowed / claim ignores the attempts read / disabled client told the schedule test / schedule test / 9 tests / disabled-client test
unlisted dev hosts sent / unknown ENVIRONMENT sends / trailing dot not stripped 4 / 1 / 1 tests
per caller: remove the first attempt (revoke, soft delete, kind change, unlink, relink, sweep), or block on the partner (end-account) one oidc-logout-callers.test.ts test each
tick: self-fence removed / rows per run 20 to 50 / call removed from scheduled() / put on the dev allowlist / one fault stops the run one test each
listing: oldest first / filter ignored / client row id shown / counts follow the filter 1 / 1 / 3 / 2 tests
D1: disabled clients queued / scope filter ignored one test each
migration 0124: an extra word in the reason, status or last_error_class list (a word no other test names: only the set test fails) / http_throttled dropped / drop the pending-time CHECK / attempts bound 6 to 9 / jti index not unique the set test, plus one or two others, on both engines
round 1, item 1: remove the first-attempt log / the sweep's log / put the error text in the line / log for a clean run 2 / 1 / 4 / 2 tests
round 1, item 2: production honours the dev list for a local host 2 tests (the sender and the pure verdict)
round 1, item 3: 13 mutations of the scan helper (aliased import, chain, assignment, namespace calls, destructuring, value use, raw SQL, dynamic import literal and unreadable, re-export, module-level call, namespace as value, default import, SQL names not read from the module); in real source: a raw constant used by a caller, the function bound as a value, a caller's call dropped 1 to 3 planted-case tests each; the real-source ones fail the caller list or the strays test
round 1, item 6: registry does not fold dots / loopback test folds none / loopback folds every dot the dotted registry rows and the helper test
round 1, item 7: 408 and 429 treated as another 4xx / Retry-After replaces the schedule / uncapped / honoured on a 5xx / class recorded as http_4xx / the date guard removed 7 / 2 / 1 / 1 / 2 / 1 tests
round 1, item 8: sent and failed windows swapped / pending included / sent aged by created_at / newest first / no cap / prune before the delivery work / fenced window removed 3 / 1 / 1 / 1 / 1 / 1 / 1 tests
round 1, item 10: unreported renamed / branch deleted / bound off by one / lease 120 to 60 and to 1 / the claim does not hold the row the unreported test (3) and the lease test (3), one each
round 1, item 11: client_disabled dropped from the reason list / an end reason renamed / the client ending binds another word; timeout 5000 to 6000 one test each
round 1, item 12: the old question text restored / the pairing sentence changed the CLI text test
round 1, ADR: the sweep clause reverted / the OIDC_END_CALLERS sentence reverted / the Retry-After sentence removed one wording test each
round 1, no-echo: the z.enum message removed (default message echoes the value) the no-echo test

Survivors found and corrected: the first verification found that production honouring the dev list, a timeout of 6000, a lease of 60, a deleted unreported branch and an extra word in a CHECK all survived; each now has a test that fails (above). In round 1, my own mutations found three more: the prune cap test computed its expectation from the actual maximum id, so pruning newest-first survived (now compares with the inserted ids); a garbage Retry-After list did not include an ISO date, so removing the date guard survived (added; a bare 2099 is valid seconds and was my mistake); and a first attempt at a "function passed as a value" mutation of endAccount wrapped the call in an arrow and was still a call from the same function, so it was not a mutation (replaced by .bind, which the scan flags). Equivalent mutants, recorded: the kind change away from person is guarded by two layers (the early return and the EXISTS guard) so each alone is absorbed by the other and both removed together fail; and removing the fold in isLocalOrLiteral alone is absorbed for localhost. by isLoopbackHost's own fold, which the helper test catches directly.

Gates

  • bun run typecheck: passes (tsc --noEmit && tsc --noEmit -p backend, no output after the command line).
  • bun run lint (biome check src/): Checked 179 files in 166ms. No fixes applied.
  • bunx biome check on every file this PR touches (48 .ts and .json files): Checked 48 files in 60ms. No fixes applied. The issue's bunx biome check backend/src shared src test still reports errors only in files this PR does not touch (backend/src/services/doi-orcid-discovery.ts, backend/src/services/zenodo.ts, and test files trigger-prescreen, trigger-version-doi, upload-explicit-dataset-id, upload-steps, verify-github-app, workflow-sync, zenodo-sandbox).
  • bun run migrations:d1-check: run once after the round-1 migration edit (All migrations applied on real D1., Catalog matches bun:sqlite (182 objects, 54 tables). OK.); round 2 changes no migration, so it was not run again.
  • The B5 suites plus the oidc, orcid and oauth neighbours and the revocation-path suites (admin-credential-cascade, private-site-cascade, test-account-sweep and its D1 twin, cron-sweep-wiring, cron-dev-safety, logout-cascade-accounts, admin-kind-route, admin-revoke-route, docs-auth-routes, user-duplicates-route, user-soft-delete, session-cookie-name): 1585 pass, 0 fail, Ran 1585 tests across 61 files.
  • CLI and contract suites (admin-oidc-cli, admin-route-inventory, api-export-surface, adr-0119-wording, adr-index, help-tiers, contract-schemas): 162 pass, 0 fail.
  • Existing tests updated for new behaviour: oidc-token-refresh and oidc-token-resources (a disabled client's token rows are now revoked), oidc-token-store, oidc-admin-routes and admin-route-inventory (the two new owner routes, total 215), oidc-client-rules (dotted forms).

Not run

  • Full bun test and CI, per the standing rule: not run, would check on the driver's side because the shared helper backend/test/helpers/oidc-harness.ts gained a collecting waitUntil (settle()) that every suite using it goes through, isLoopbackHost is read by the authorization routes, and scheduled() gained one call.
  • test/account-copy-parity.test.ts: a known baseline failure (needs the sibling website checkout), not run.
  • A second bun run migrations:d1-check: the migration has not changed since the one run after the edit.

The intent row of a back-channel logout, and the closed words of an ending: reasons, statuses, error classes and the retry schedule. Tested on bun:sqlite and Miniflare D1; d1-check passes.
One cascade module (oidcEndStatements) is added to the batch of admin revoke, the owner soft delete and its sweep, ORCID unlink and relink, a kind change away from person, the owner end-account route and the client disable. It queues the logouts, revokes the tokens and grants and deletes unused codes. Role demotion, key revocation and sign-out are deliberate non-paths with tests. Tested through the real routes; each caller mutation-checked; caller count held by a source scan.
The sender signs a logout+jwt and posts it to the client's registered https address after the batch commits (waitUntil), never following a redirect, with a 5 second timeout, no answer body read and no credential. 5xx and network errors retry at 1m, 5m, 30m, 2h and 12h from a production-only 30 minute tick. A dev worker sends only to loopback or OIDC_LOGOUT_DEV_HOSTS and records the rest as fenced. Owner list view added.
nemar admin oidc end-account (the manual merge step and incident tool) and logout-deliveries, and the disable command now reports what it revoked.
Every cascade and delivery store statement, as the real functions build it, runs on D1 itself, where bun:sqlite accepts SQL that D1 refuses.
Rule 12 gains the cascade function, its order, filters and caller list, rule 15 the delivery, token, request and fence, with consequences and open questions. Index line, AGENTS.md and implementation notes updated; wording pinned by test.
localhost. names localhost; the production address check now strips trailing dots before testing the host. Tested for production and dev.
The kind route comment names the grants it now ends; wrangler documents the absent OIDC_LOGOUT_DEV_HOSTS var; a userinfo test expects a disabled client's token row to be revoked.
A 408 or 429 is retried on the same six-attempt schedule with the class http_throttled; Retry-After is only a lower bound for the wait, capped at 12 hours, and only for those two. last_error_class is now a closed list in the unreleased migration, held equal as a set to the vocabulary for reason, status and class.
The production tick deletes sent and fenced deliveries after 30 days and failed ones after 180, at most 500 a tick and after its delivery work, and never a pending row. The windows are named defaults in shared/oidc.ts for the owner to set before the first client registers. Dev has no tick and is not pruned.
attemptDueLogouts never throws, so the catch after it was dead and a fault in the first attempt (or the sweep's) left no trace. The tally is now logged as a count and the error's class, never its text, an address, a token or a subject.
isLoopbackHost and isLocalOrLiteral fold a trailing dot, so registration of a logout or redirect address and the sender's check at send time agree. Tests: production ignores OIDC_LOGOUT_DEV_HOSTS for a local host that the list names, a stored address that is no longer sendable is recorded address_refused through the sender, dotted forms in the registry and verdict tables.
Claimed-never-recorded attempts are taken up again when the lease lapses and failed as unreported once all six are used; the claim's two-minute lease is read from the database and pinned above the 5 second timeout; the timeout window is tight; the token-store reason test no longer feeds one list through itself.
The caller scan now resolves import bindings of the cascade module (named, aliased, namespace, destructured, alias chains) and flags every other use outside it as a stray: a value, a raw SQL constant, a dynamic import, a re-export, a default import, a namespace element access, a module-level reference. Each way is planted and shown caught.
The end-account question no longer says the person is asked again at every client (a first-party client does not ask), and the help says to pair the command with a revocation, deletion or kind change for a merge loser. The reason is a z.enum that never echoes a value, an unsent delivery's status and class are a typed pair, the soft delete and sweep paths get the restore test, and the stand-in reports the cause of an openssl failure.
Rule 12 says a new path adds to OIDC_END_CALLERS and to the docs and private lists only when it runs their statements, that only the sweep is guarded, and that a merge loser's end-account is paired with a revocation, deletion or kind change. Rule 15 decides throttling with Retry-After, unreported, the owner routes without the cookie flag, and retention; open points updated.
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

📦 Package Preview

Your package is ready to test!

bun install -g nemar-cli@PR2045

Version: 0.10.28-PR2045.17230c8
Commit: 17230c8


🤖 Updated on each push.

A kind change away from person ends only the person_proven_orcid grants, and a non-person account still meets active_account, so it cuts no merge loser off. The end-account help and ADR 0119 rule 12 now say to run end-account and then revoke or delete the loser, and why in that order. Tested: kind change keeps active_account grants and signs in again; the merge procedure through the real routes; wording pins fail on the old text.
A run of 11 or more digits was read as no Retry-After, so a partner asking for the longest wait got the shortest. parseRetryAfter now accepts any run of digits and caps digits and dates at 12 hours; the cap lives there and recordOf only takes the longer of it and the schedule. Tested: 12, 25 and 400 digits through the sender and a pure parser table; restoring the 10-digit limit fails both.
With Retry-After capped at 12 hours, a failed row's last attempt can come about 63 hours after its creation, not under a day: the retention comment, ADR rule 15 and its consequences now say within three days, derived from the constants and pinned by a test. The logout-deliveries help now lists what is final and what is retried, read from a table of every status from 200 to 599 through the real sender.
The caller scan saw no call and no value in export const endIt = oidcEndStatements, so a caller in another file could hide behind it. An alias whose name is exported by its declaration (const, let, var, a destructured pattern, a namespace member, a later assignment to an exported let) is now a stray, reported once. Both headers say a call that never runs, or whose result is discarded, passes the scan. Tested with the real scanner on planted source; removing the check fails it.
@neuromechanist
neuromechanist merged commit 8b5189b into feature/issue-2014-epic-oidc-provider Nov 5, 2026
16 of 19 checks passed
@neuromechanist
neuromechanist deleted the feature/issue-2019-phase5-oidc-revocation-cascades-and-back branch November 5, 2026 22:47
neuromechanist added a commit that referenced this pull request Nov 6, 2026
* Phase B1: ADR 0119, partner hosts, __Host- cookie and OIDC subject (#2031)

* docs: ADR 0119, NEMAR as an OIDC provider

* feat: exclude partner hosts from origin checks

* feat: __Host- session cookie behind a flag

* feat: users.oidc_subject and owner lookup

* feat: reserve the nmu_ username prefix

* docs: refresh compute notes for ADR 0119

* docs: ADR 0119 notes the single legacy clear

* docs: ADR 0119 names the cookie exposure

* docs: correct stale session cookie docblocks

* fix: brand OidcSubject, correct shared docblocks

* docs: say who deletes TOLERATED_GAPS entry

* feat: __Host- names for the ORCID flow cookies

* feat: reversible flag, slide and sign-out rules

* test: name-aware session cookie in live tests

* docs: ADR 0119 states the cookie principle

* docs: refresh stale cookie comments, 0120 notes

* fix: sign-out cascades for every carried account

* docs: ADR 0119 rule 9 matches the Context

* fix: name every account in the sign-out log

* Phase B2: OIDC client registry, signing keys and discovery (#2033)

* Add the OIDC scope, token and id vocabulary

* Add migration 0121 for OIDC clients and keys

* Add OIDC config and signing key service

* Amend ADR 0119 rule 8: first-party needs NEMAR hosts

* Serve OIDC discovery and keys on the issuer host

* Add owner routes for OIDC clients and keys

* Declare OIDC_SECRET as a Worker secret

* Add nemar admin oidc commands

* Retype OIDC vocabulary and share encoders

* Add revoked key state and unique active names

* Harden OIDC key rotation and add revocation

* Tighten OIDC client registration rules

* Close OIDC surface bypasses and cached errors

* Add keys revoke and emergency rotation to the CLI

* Record OIDC key and client decisions in ADR 0119

* Note what the key set cache depends on

* Use router path, add --emergency, ADR note

* Phase B3: OIDC authorization and consent (#2036)

* Add the OIDC authorization wire contract

* Add migration 0122 for OIDC grants and codes

* Add the OIDC sign-in rule and ORCID proof

* Add OIDC authorization and consent service

* Add a per-account OIDC authorize budget

* Serve OIDC authorize and consent routes

* Add OIDC consent, rule and error copy

* Record phase B3 rules in ADR 0119

* Correct the OIDC error copy comment

* Treat an empty request parameter as omitted

* Pin the OIDC authorize cap in the caps table

* Mint a fresh session at every ORCID sign-in

* Link an ORCID iD only from a __Host- session

* Give OIDC codes a row id and strict times

* Refuse a redirect query naming code or state

* Move ID token reading into its own module

* Sign the reauth marker, guard the caller

* Show the redirect host on the consent screen

* Say the authorization routes need the flag

* Record round-1 authorization rules in ADR 0119

* Start an ORCID link only from the POST route

* State the flag-off ORCID link residual

* Phase B4: OIDC token, userinfo, revocation and introspection (#2042)

* Add oidc_tokens table (migration 0123)

* Add OIDC token, userinfo, revoke, introspect

* Refuse OIDC tokens on every non-OIDC route

* Add the oauth-ip rate limit bucket

* Name the nemar.account claims in discovery

* Test token statements, router and bearer

* Use a plain string in the bearer test

* Let the statement decide the refresh token

* Record token rules 13 and 14 in ADR 0119

* Note the /oauth routes beside the cookie flag

* Revoke on any second presentation of a code

* Make the access expiry index partial

* Revoke a refresh token's siblings on rotation

* Revoke a used code only after PKCE matches

* Serve userinfo and introspection in read-only

* Seed owner-only data in the allowlist test

* Bare bearer challenge, userinfo scope pinned

* Omit token_type for a refresh token; type user

* Test the content type and a late reuse

* Scan the constant-time comparisons

* Test database and signing faults

* Test trimming, form decoding, grant binding

* Correct the surface and bearer docblocks

* Record round-1 token rules in ADR 0119

* Let the lost claim detect a code's replay

* Refuse a retry once the first child was used

* Exempt only POST in read-only maintenance

* Record round-2 token rules in ADR 0119

* Correct the ADR 0119 index line

* Test the grace's time limit on its own

* Phase B5: OIDC revocation cascades and back-channel logout (#2045)

* Add oidc_logout_deliveries (migration 0124)

The intent row of a back-channel logout, and the closed words of an ending: reasons, statuses, error classes and the retry schedule. Tested on bun:sqlite and Miniflare D1; d1-check passes.

* End OIDC grants in every credential cascade

One cascade module (oidcEndStatements) is added to the batch of admin revoke, the owner soft delete and its sweep, ORCID unlink and relink, a kind change away from person, the owner end-account route and the client disable. It queues the logouts, revokes the tokens and grants and deletes unused codes. Role demotion, key revocation and sign-out are deliberate non-paths with tests. Tested through the real routes; each caller mutation-checked; caller count held by a source scan.

* Send back-channel logouts after a cascade

The sender signs a logout+jwt and posts it to the client's registered https address after the batch commits (waitUntil), never following a redirect, with a 5 second timeout, no answer body read and no credential. 5xx and network errors retry at 1m, 5m, 30m, 2h and 12h from a production-only 30 minute tick. A dev worker sends only to loopback or OIDC_LOGOUT_DEV_HOSTS and records the rest as fenced. Owner list view added.

* Add end-account and logout-deliveries commands

nemar admin oidc end-account (the manual merge step and incident tool) and logout-deliveries, and the disable command now reports what it revoked.

* Run the cascade statements on Miniflare D1

Every cascade and delivery store statement, as the real functions build it, runs on D1 itself, where bun:sqlite accepts SQL that D1 refuses.

* Record the OIDC cascade and logout in ADR 0119

Rule 12 gains the cascade function, its order, filters and caller list, rule 15 the delivery, token, request and fence, with consequences and open questions. Index line, AGENTS.md and implementation notes updated; wording pinned by test.

* Refuse a loopback host with a trailing dot

localhost. names localhost; the production address check now strips trailing dots before testing the host. Tested for production and dev.

* Document the kind change and the dev hosts var

The kind route comment names the grants it now ends; wrangler documents the absent OIDC_LOGOUT_DEV_HOSTS var; a userinfo test expects a disabled client's token row to be revoked.

* Retry throttled logouts, close the class list

A 408 or 429 is retried on the same six-attempt schedule with the class http_throttled; Retry-After is only a lower bound for the wait, capped at 12 hours, and only for those two. last_error_class is now a closed list in the unreleased migration, held equal as a set to the vocabulary for reason, status and class.

* Prune finished logout deliveries in the tick

The production tick deletes sent and fenced deliveries after 30 days and failed ones after 180, at most 500 a tick and after its delivery work, and never a pending row. The windows are named defaults in shared/oidc.ts for the owner to set before the first client registers. Dev has no tick and is not pruned.

* Log a database fault in the first attempt

attemptDueLogouts never throws, so the catch after it was dead and a fault in the first attempt (or the sweep's) left no trace. The tally is now logged as a count and the error's class, never its text, an address, a token or a subject.

* Agree on a trailing dot and test the fence

isLoopbackHost and isLocalOrLiteral fold a trailing dot, so registration of a logout or redirect address and the sender's check at send time agree. Tests: production ignores OIDC_LOGOUT_DEV_HOSTS for a local host that the list names, a stored address that is no longer sendable is recorded address_refused through the sender, dotted forms in the registry and verdict tables.

* Test the lease, unreported and the pins

Claimed-never-recorded attempts are taken up again when the lease lapses and failed as unreported once all six are used; the claim's two-minute lease is read from the database and pinned above the 5 second timeout; the timeout window is tight; the token-store reason test no longer feeds one list through itself.

* Hold the cascade callers by every reference

The caller scan now resolves import bindings of the cascade module (named, aliased, namespace, destructured, alias chains) and flags every other use outside it as a stray: a value, a raw SQL constant, a dynamic import, a re-export, a default import, a namespace element access, a module-level reference. Each way is planted and shown caught.

* Correct the end-account text, tighten types

The end-account question no longer says the person is asked again at every client (a first-party client does not ask), and the help says to pair the command with a revocation, deletion or kind change for a merge loser. The reason is a z.enum that never echoes a value, an unsent delivery's status and class are a typed pair, the soft delete and sweep paths get the restore test, and the stand-in reports the cause of an openssl failure.

* Record the round-1 rulings in ADR 0119

Rule 12 says a new path adds to OIDC_END_CALLERS and to the docs and private lists only when it runs their statements, that only the sweep is guarded, and that a merge loser's end-account is paired with a revocation, deletion or kind change. Rule 15 decides throttling with Retry-After, unreported, the owner routes without the cookie flag, and retention; open points updated.

* Drop kind change from the merge-loser steps

A kind change away from person ends only the person_proven_orcid grants, and a non-person account still meets active_account, so it cuts no merge loser off. The end-account help and ADR 0119 rule 12 now say to run end-account and then revoke or delete the loser, and why in that order. Tested: kind change keeps active_account grants and signs in again; the merge procedure through the real routes; wording pins fail on the old text.

* Cap a Retry-After of any length

A run of 11 or more digits was read as no Retry-After, so a partner asking for the longest wait got the shortest. parseRetryAfter now accepts any run of digits and caps digits and dates at 12 hours; the cap lives there and recordOf only takes the longer of it and the schedule. Tested: 12, 25 and 400 digits through the sender and a pure parser table; restoring the 10-digit limit fails both.

* Correct the delivery span and failed help

With Retry-After capped at 12 hours, a failed row's last attempt can come about 63 hours after its creation, not under a day: the retention comment, ADR rule 15 and its consequences now say within three days, derived from the constants and pinned by a test. The logout-deliveries help now lists what is final and what is retried, read from a table of every status from 200 to 599 through the real sender.

* Flag an exported alias of the cascade

The caller scan saw no call and no value in export const endIt = oidcEndStatements, so a caller in another file could hide behind it. An alias whose name is exported by its declaration (const, let, var, a destructured pattern, a namespace member, a later assignment to an exported let) is now a stray, reported once. Both headers say a call that never runs, or whose result is discarded, passes the scan. Tested with the real scanner on planted source; removing the check fails it.

* Phase B6: OIDC end-to-end test (S0, S1) (#2048)

* Pin relying-party libraries for the OIDC test

* Add OIDC end-to-end test with a real library

* Declare OIDC token error words once

* Check the token error type at compile time

* Scope e2e hooks and add verifier controls

* Pin openid-client 6.8.9

* Amend ADR 0119 on key re-encryption

* Narrow the key recovery to current and next

* List every verifier control in the e2e header

* Guard the e2e hooks against failed setup

* Phase B6: OIDC conformance rig and run (S4, S5) (#2049)

* Add the conformance plan configurations

* Add the conformance rig and its pre-flight

* Pin the conformance suite images by digest

* Add the OIDC conformance workflow

* Accept a redirect as the suite being up

* Run the suite scripts in their local mode

* Let every Basic module run to its outcome

* Give the rig a client for each purpose

* Record the approved deviations and skips

* Stop the rig and pin Python before upload

* Test the expected files and workflow limits

* Give each plan its own expected failures

* Expect both client_secret_post failures

* Accept a combined decision in the PKCE check

* Say what the exported results copy

* Log each authorization error the rig answers

* Check the authorization errors before upload

* Wait for the rig to exit before upload

* Bound the suite start and lower the Basic limit

* Say the suite goes on after the secret check

* Test the PKCE refusal, scopes and the pre-flight

* Test the authorization check and stop step

* Fail on malformed authorization lines

* Match strictly and report a missing log

* Test the check's entry point and its step

* Log a rule refusal as access_denied

* Read an error in the redirect fragment

* Count authorization requests against their lines

* Test each kind of authorization line

* Kill a rig that ignores the stop

* State the residual risk of a global allowed set

* Fix the tier claims in two OIDC test headers (#2053)

* Claim the unit-pure tier in two OIDC headers

* Fix OIDC test header wording

* Add a process CI tier and move the two OIDC process tests into it (#2056)

* Route CI TIER: process files out of unit-pure

Add scripts/ci/process-files.sh, which lists the files whose header
claims the process tier, and have unit-pure-files.sh skip them.
The routing test reads the new pattern from the script.
Tested: bun test test/ci-tier-routing.unit.test.ts.

* Add the process-tier CI job

One job, on the unit-pure trigger, that runs the files process-files.sh
lists and refuses an empty list. No secrets, no sharding.
Tested: routing test; actionlint shows only the three SC2086 notes
already present on the base.

* Move the two OIDC process tests to the process tier

oidc-conformance-rig and oidc-e2e now claim CI TIER: process, with the
reason stated. The routing test asserts they are listed by
process-files.sh and absent from the unit-pure list.
Tested: routing test; both files run on their own.

* Run the process tier in the deploy gate

The pure list skips process files, so test-gate gains a step that runs
scripts/ci/process-files.sh with the same empty-list refusal. The
routing test asserts the gate runs it.
Tested: routing test, both OIDC files, actionlint, typecheck, lint.

* Give the OIDC alias scan test 60 s (#2052)

* Reword the OIDC compute-spend consent sentence (#2057)

* Reword the OIDC compute-spend consent sentence

* Update ADR 0119 consent screen wording

* Remove the temporary conformance push trigger (#2059)

This branch was previously deployed

1 inactive deployment
npm — 17230c8f Deployed Nov 5, 2026 by neuromechanist via publish #4200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant