Repository navigation
Commit 4e55e4e
fix(plugin-auth)!: deleting an SSO provider ends the sessions a sign-in through it opened and removes its projected grants (#36173)
Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — no published skill teaches deleting an SSO provider,
its sessions or its projected grants; the rule is documented in
`content/docs/permissions/sso.mdx` ("Deleting an SSO provider")
## 维护者速读
- 管理员删除一个企业单点登录提供方后,经它登录的用户的在线会话随之结束;其他方式登录的会话不受影响。
- 安全加固:删除身份提供方即收回它所担保的访问(安全席位的无卡派单)。
- 若出错,经该提供方登录的用户会被要求重新登录;改动可直接撤回,会话表多出的一列不影响旧版本。
- 要你做的事:无(合同层审核归安全席位)。
## What changes
Rule: **deleting an SSO provider ends the sessions a sign-in through it
opened and removes its projected grants.**
1. **Sessions.** Each session an SSO sign-in opens (OIDC or SAML, SP- or
IdP-initiated, new or returning user) records the provider it was signed
in through, in a new read-only, system-managed column
`sys_session.sso_provider_id`. After `POST
/api/v1/auth/sso/delete-provider` succeeds, the live sessions that
record the deleted provider are revoked in place (`revoke_reason:
'sso_provider_deleted'`), the same shape every other revocation writes.
A session signed in any other way is left as it is; a delete the vendor
refuses ends nothing.
2. **The delete's answer** carries `revokedSessions` beside the other
counts, and its `message` says it.
3. **Projected grants of a provider that no longer exists are removed at
every boot**, as are live sessions recording such a provider. The delete
already removes its own projected grants at delete time (unchanged, on
`main` since the SSO provider lifecycle landed); the boot sweep settles
what a provider with no `sys_sso_provider` row left behind. It reads
only marker grants and stamped live sessions, re-reads the provider rows
after reading the candidates (a provider registered mid-sweep keeps its
own), and logs at `info` what it removed and at `error` (with the
remedy) when it could not.
**Bounded batches.** Every revoke and removal is written in batches of
at most 500 rows, walked in id order (keyset paging), so the rule holds
for any number of sessions or grants; a batch that fails is logged at
`error` with the remedy, and the next boot's sweep ends what remains.
**Boot sweep, not one-shot backfill — chosen by measurement:**
- A path that leaves a projected grant behind once the provider row is
gone still exists after this change: a delete whose cleanup fails after
the vendor's own delete succeeded (`dependentsRemoved: false`). A
one-shot backfill would leave those for good; the pin "what a delete
whose cleanup failed left behind is removed at the next boot" shows the
sweep settling it.
- Cost, measured on better-sqlite3 with 20,000 grants (10% projected,
all by live providers) and 10,000 sessions (half stamped): a sweep with
nothing to remove takes median 5.3 ms over 5 runs (min 4.2, max 17.5)
and does 3 reads; removing 1,000 grants of a gone provider took 0.9 s,
once.
- Neither changes product behaviour beyond the two rules: the sweep
removes only what rule 2 (and rule 1 for sessions) already says must not
exist.
**Where the producer lives.** The rule lands in
`packages/plugins/plugin-auth` (lifecycle, sign-in seams, boot hook).
One file outside it:
`packages/platform-objects/src/identity/sys-session.object.ts` declares
the new column (plus its index and the `sso_provider_deleted` revoke
reason in the published vocabulary), because `sys_session` is declared
there; its translation bundles are regenerated and the new label
translated. The tenant-audit census page for plugin-auth is regenerated
for the two new session writes, both stating their system context.
Not touched: `client-address.ts` and `objectql-adapter.ts` (other
in-flight work).
## Tests
- `src/sso-saml-refusal-landing.test.ts` — new top-level describe on the
real SAML end-to-end harness (real `AuthManager`, real `sso()` plugin,
the IdP played with the vendor's own `samlify`): two providers, a new
and a returning sign-in through one, a sign-in through the other, a real
delete through the vendor's door. Pins that the first provider's
sessions end (with the reason and the count in the answer) and the other
provider's session stays; a control where the vendor refuses the delete
and nothing ends. The sign-in helper gained an optional `providerId`
(default unchanged).
- `src/sso-provider-lifecycle.test.ts` (real ObjectQL over
better-sqlite3, real `AuthPlugin` boot hooks):
- the delete door revokes the provider's live sessions; an already-ended
one keeps its own reason; another provider's and a password session
stay;
- at boot, grants of a provider with no row are removed while a live
provider's, one by hand and a SCIM one stay;
- at boot, live sessions of a gone provider are revoked while another
provider's, an unstamped one and an ended one stay as they are;
- a provider registered while the sweep runs keeps what its sign-ins
wrote;
- what a delete whose cleanup failed left behind is removed at the next
boot;
- the existing delete-answer pin now includes `revokedSessions`.
- `src/sso-session-provider.test.ts` (new) — which sign-in source names
a provider; the settle writes once on the session its request minted; a
control for another request or a non-SSO sign-in; a write failure is
said once at `error` naming the provider and the session, and the
sign-in is not failed.
## Acceptance notes
- The preflight (`GET /admin/sso/delete-impact`, the delete action's
confirmation) still counts users, mappings and grants only; the session
count appears in the delete's own answer. Adding it to the preflight is
a separate UX change, not done here.
- L2 contract-tier review is owed to the security seat.
## Verification
**Current head `4beed2475`:** the three SSO suites 152/152 and the
lifecycle file 48/48 (seat's contract-tier delta read, from a `git
archive` export); pins at the bulk ceiling + 1 for the delete-time
revoke and the boot sweep are red on the previous head and green here;
CI green.
Earlier rounds below: Local runs on `6a7ee0ae` unless a row names
another commit.
- Red on base (`dc10b3b4`): rule 1 pin — 1 failed (the assertion after a
200 delete); rule 2 pin — 1 failed (2 grants left that the rule
removes). Green after.
- Guard ablation (each: mutation proven on disk by
`scripts/ablation-replace.mjs`, then restored to the HEAD blob with `git
diff HEAD` empty): 6 guards — staging the provider at sign-in, settling
it on the session, revoking at delete, the boot hook, the mid-sweep
provider re-read, the liveness filter on revocation — each turned its
pin red (1 or 3 failed) and green on restore. Two guards first stayed
green (no pin reached them); the two pins above were added and both then
went red under ablation.
- Package suites: `@objectstack/plugin-auth` 292/292 files, 6194 passed,
10 skipped; `@objectstack/platform-objects` 125/125 files, 2117 passed.
Typecheck of both packages: exit 0.
- Gate union: the 111 families `node scripts/pm/dispatch-gates.mjs
--commands` derives for this diff, each run locally on `6a7ee0ae` with
its exit code captured before any pipe: 111 exit 0. `dispatch-gates
--ran`: 111 derived, 111 run, 0 unrun. An earlier run on a previous head
surfaced four findings, each fixed on this branch (translation bundles,
the tenant-audit census, the optional error-sink contract, module-top
loading in edited test files), and three prerequisite refusals cleared
by building or fetching what they read. CI-only families are read from
this pull request's check-runs.
- Dogfood battery (narrowing arm): `6a7ee0ae` · lock VERDICT
command-exit 0 · Test Files 483 passed, 3 skipped (486) · Tests 4101
passed, 68 skipped (4169) · no failures.
**Read first (risk order):**
`packages/plugins/plugin-auth/src/sso-provider-lifecycle.ts`
(`sweepDeletedSsoProviderAccess`, `removeSsoProviderDependents`),
`packages/plugins/plugin-auth/src/sso-session-provider.ts`,
`packages/plugins/plugin-auth/src/auth-manager-database-hooks.ts` (the
settle call in `session.create.after`).
**Two-minute check:** `pnpm --filter @objectstack/plugin-auth exec
vitest run src/sso-saml-refusal-landing.test.ts -t "deleting an identity
provider"` — 2 passed.
## Human Minimum
- [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic.
- [x] 2. Every name I added uses the casing for its kind.
- [x] 3. No formatter ran; `pnpm lint` passes (CI).
- [x] 4. One issue, one branch off an up-to-date `main`, one pull
request.
- [x] 5. A change that publishes carries a changeset, and both
declaration lines are filled in here and in the changeset.
- [x] 6. `packages/spec` touched: not touched.
- [x] 7. No hand edits to `content/docs/references/`,
`packages/*/CHANGELOG.md` or `content/docs/releases/`.
- [x] 8. Title, body and comments are in English.
Dispatched as a no-card security order by `security#2 · sunhaolin ·
session_017xRBcW9L8Noz9BxEwjwiov`; developer session
`session_017xRBcVBc1xrigvFwcDc9mc`. The draft was opened by the seat
from the developer's payload (the developer's own relay write was
refused by its session's permission check).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_017xRBcVBc1xrigvFwcDc9mc
<!-- signed: security#2 · sunhaolin · session_017xRBcW9L8Noz9BxEwjwiov
-->
---------
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>1 parent 674f877 commit 4e55e4e
23 files changed
Lines changed: 1033 additions & 42 deletions
File tree
- .changeset
- content/docs/permissions
- docs/audits/2026-08-tenant-audit-write-call-sites.counts/plugins
- packages
- platform-objects/src
- apps/translations
- identity
- plugins/plugin-auth/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1011 | 1011 | | |
1012 | 1012 | | |
1013 | 1013 | | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
| 1036 | + | |
| 1037 | + | |
| 1038 | + | |
| 1039 | + | |
| 1040 | + | |
| 1041 | + | |
| 1042 | + | |
| 1043 | + | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
| 1047 | + | |
| 1048 | + | |
1014 | 1049 | | |
1015 | 1050 | | |
1016 | 1051 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | | - | |
| 17 | + | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
| 35 | + | |
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
| 128 | + | |
128 | 129 | | |
| 130 | + | |
129 | 131 | | |
130 | 132 | | |
131 | 133 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
497 | 497 | | |
498 | 498 | | |
499 | 499 | | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
500 | 504 | | |
501 | 505 | | |
502 | 506 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
497 | 497 | | |
498 | 498 | | |
499 | 499 | | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
500 | 504 | | |
501 | 505 | | |
502 | 506 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
495 | 495 | | |
496 | 496 | | |
497 | 497 | | |
498 | | - | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
499 | 503 | | |
500 | 504 | | |
501 | 505 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
497 | 497 | | |
498 | 498 | | |
499 | 499 | | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
500 | 504 | | |
501 | 505 | | |
502 | 506 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
497 | 497 | | |
498 | 498 | | |
499 | 499 | | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
500 | 504 | | |
501 | 505 | | |
502 | 506 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
497 | 497 | | |
498 | 498 | | |
499 | 499 | | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
500 | 504 | | |
501 | 505 | | |
502 | 506 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
497 | 497 | | |
498 | 498 | | |
499 | 499 | | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
500 | 504 | | |
501 | 505 | | |
502 | 506 | | |
| |||
0 commit comments