Repository navigation
fix(den-api): refuse SCIM-deprovisioned SSO sign-ins before Better Auth creates the user - #4775
Conversation
…th creates the user A member deactivated over SCIM who still followed the SSO link was correctly refused at the callback, but only in provisionUser, after Better Auth had already committed a fresh user, account, and session; in single-org mode the session hook also re-created their membership. The ghost user then made the IdP's re-provision POST /Users collide with 409 uniqueness. Refuse the deprovisioned email in the user.create.before hook for SSO callbacks (both the OIDC callback and the SAML ACS carry :providerId), so no rows are written and the 403 response and message are unchanged, and make ensureSingletonOrganizationForUser skip SCIM-deprovisioned identities. Journey: evals/specs/scim-deprovisioned-sso-reprovision.test.ts drives the real OIDC callback through the mock IdP in multi-org and single-org Dens.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Warden review summary — ClearNative findings: 1. Blocking policy matches before consolidation: 0. Full finding text remains in Warden's native checks and review threads. This comment retains only native IDs, severity, skill attribution, and safe locations. Analysis run Reported trigger coverage (not proof of complete repository or context coverage): diff-security-review (121645 ms), confidentiality-review (75507 ms), spec-provenance-review (160022 ms), desktop-den-sync-review (109602 ms). Blockers
Advisories
Needs recheck
Observed review-thread metrics
Thread states are read-only collection snapshots. These metrics are neither lifetime totals nor exact resolution times, and this summary is not clearance authority. |
There was a problem hiding this comment.
Warden security clearance: clear. No blocking findings (security or desktop↔den sync) in this diff (29a8a704d7c22b2df3924805b534f268eeff09a4). Automated clearance satisfies the required-review gate only — a human still reviews and merges. Analysis run
Additional test evidence (same PR head
|
Test evidence — a SCIM-deactivated member who tries SSO is refused without a ghost identity, so the IdP can re-provision them (single-org Den) — ✅ passedSHA 29a8a70 · engine v1 ✅ passed · 2 expectations passed · 0 failed · 0 pending verdict passed · 0 user observations · 0 probes · steps 0/0 ℹ️ ASSERTION — 1. A SCIM-deprovisioned person is refused at the SSO callback without leaving a ghost identity (single_org)The OIDC callback returned 403 "This user was deprovisioned by SCIM. Reactivate them in the identity provider before signing in." with no session cookie; afterwards the database holds 0 user row(s) and 0 session row(s) for [email protected], /v1/org lists no joined member for that email, and [email protected] remains owner.
ℹ️ ASSERTION — 2. The IdP's re-provision restores access after the refused SSO attempt (single_org)POST /Users for [email protected] returned 201 with id usr_01m24v59h8eqv8wca2n1v3dfc6; GET reports active=true, /v1/org lists the member as member, exactly 1 user row exists, password sign-in returned 403, and [email protected] is still owner.
Test run created 2026-09-10T05:02:27.852Z · Source: |
Summary
active=false) who still followed the SSO link was refused at the callback with the intended 403 (This user was deprovisioned by SCIM…), but only insideprovisionUser, after Better Auth had already committed a freshuser,account, andsessionrow. In single-org mode thesession.createhook (ensureSingletonOrganizationForUser) also re-created their membership.POST /Userscollide with409 uniqueness, contradictingpackages/docs/cloud/scim-okta.mdx§5.4 and breaking Okta reactivation for anyone who tried to sign in while deactivated.databaseHooks.user.create.beforewhen the endpoint carries an SSO:providerId(OIDC callback and SAML ACS share this), so no rows are written and the 403 status/message are unchanged; and makeensureSingletonOrganizationForUserskip SCIM-deprovisioned identities.Why
Issue
Scope
ee/apps/den-api/src/scim-deprovisioning.ts: sharedSCIM_DEPROVISIONED_SIGN_IN_MESSAGEandisScimDeprovisionedEmailForSsoProvider(tombstone lookup via the SSO provider's organization).ee/apps/den-api/src/auth.ts:user.create.beforerefuses SSO-created users for tombstoned emails;provisionUserreuses the shared message (unchanged text).ee/apps/den-api/src/orgs.ts:ensureSingletonOrganizationForUserreturnsnullfor SCIM-deprovisioned identities.evals/specs/scim-deprovisioned-sso-reprovision.test.ts: new PR-lane journey (multi-org and single-org Den) that provisions over SCIM, deactivates, drives the real OIDC callback via the mock IdP, and re-provisions.Out of scope
POST /Usersstill returns 409 because the SCIM plugin'slinkExistingUsersis off (pre-existing, also on the clean path).scim-okta-lifecyclee2e asserts) are unchanged.Testing
Ran
pnpm evals:pr specs/scim-deprovisioned-sso-reprovision.test.ts(local lane; red before the fix, green after)pnpm evals:e2e scim-okta-lifecycle --localpnpm --filter @openwork-ee/den-api testDATABASE_URL=… pnpm --filter @openwork-ee/den-api test:dbbun test --conditions development test/<file>.test.tsfor scim-auth-sync, scim-groups, scim-token-storage, sso-jit, sso-saml-policy, sso-saml-response-policy, sso-resolve-helpers, sso-resolve-route, sso-account-linking-policy, sso-entra-domain, sso-readiness, member-removal-rejoinpnpm --filter @openwork-ee/den-api exec tsc --noEmit -p tsconfig.jsonResult
ghost user rows after refused SSO (multi_org|single_org): expected 1 to have length 0; with the user-row assertions removed it went on to fail withre-provision after refused SSO: HTTP 409 … scimType uniqueness(multi-org) andghost membership after refused SSO (single_org): expected true to be false. After the fix: 2/2 passed; scim-okta-lifecycle 1/1 passed; den-apitest24/24;test:db2/2; SSO/SCIM unit files 39/39; tsc exit 0.origin/dev(7d5097d) worktree with the same command:member-removal-rejoin.test.ts› "a new explicit invitation activates its placeholder as a fresh member lifecycle" (Expected: "admin" Received: "member").CI status
Manual verification
PATCH /Users/{id}withactive=false.This user was deprovisioned by SCIM…, no session cookie, and theusertable has no row for that email; in single_org mode/v1/orglists no joined member for it.POST /Usersfor the sameuserNamereturns 201 and the member re-joins.Evidence
29a8a704d).scim-okta-lifecyclee2e run, both on the same head. The legacy publisher shows one test per sticky comment and the review-app multi-run publication needs the CI-only private review Blob token, so those two are rendered from their stored runs.29a8a704dvsorigin/dev7d5097d42:pnpm warden:check, all 4 skills completed (diff-security-review, confidentiality-review, spec-provenance-review, desktop-den-sync-review), no findings.Risk
:providerIdparam (SSO callbacks) and is a single indexed lookup; the single-org guard runs one tombstone/identity lookup per session creation.Rollback