Repository navigation
fix(auth)!: a SAML provider keys its accounts on a stable attribute (Entra object id by default), so the app and the IdP portal reach one account - #33490
Conversation
…O account needs an address Claude-Session: https://claude.ai/code/session_016WV4d1NJYFGVi2FRztyBNo Co-authored-by: Claude <noreply@anthropic.com>
…to end Claude-Session: https://claude.ai/code/session_016WV4d1NJYFGVi2FRztyBNo Co-authored-by: Claude <noreply@anthropic.com>
…dress narrowing Claude-Session: https://claude.ai/code/session_016WV4d1NJYFGVi2FRztyBNo Co-authored-by: Claude <noreply@anthropic.com>
…pin the portal-first case, declare claim-over-email precedence Claude-Session: https://claude.ai/code/session_016WV4d1NJYFGVi2FRztyBNo Co-authored-by: Claude <noreply@anthropic.com>
…nt_not_linked; name the vendor fingerprint at the hidden-member helper Review S1 and N1 on #33418: prose and a comment only. Claude-Session: https://claude.ai/code/session_016WV4d1NJYFGVi2FRztyBNo Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016WV4d1NJYFGVi2FRztyBNo Co-authored-by: Claude <noreply@anthropic.com>
…e register bridge Claude-Session: https://claude.ai/code/session_016WV4d1NJYFGVi2FRztyBNo Co-authored-by: Claude <noreply@anthropic.com>
# Conflicts: # packages/plugins/plugin-auth/src/auth-manager-auth-instance.ts # packages/plugins/plugin-auth/src/auth-manager.ts # packages/plugins/plugin-auth/src/objectql-adapter.ts # packages/plugins/plugin-auth/src/sso-saml-refusal-landing.test.ts # packages/plugins/plugin-auth/src/sso-saml-standard-claims.ts # packages/plugins/plugin-auth/src/sso-sign-in-options.ts
Claude-Session: https://claude.ai/code/session_016WV4d1NJYFGVi2FRztyBNo Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016WV4d1NJYFGVi2FRztyBNo Co-authored-by: Claude <noreply@anthropic.com>
… key param Claude-Session: https://claude.ai/code/session_016WV4d1NJYFGVi2FRztyBNo Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 2 package(s): 31 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 7 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 24 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin 492d494c4f0c0f98d0d2d8418e1eaccdc2a06693 && git checkout 492d494c4f0c0f98d0d2d8418e1eaccdc2a06693
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin e40cd1e28dd79e60e7f4be0db06f071f3f962574 06329b0ae051b5558f3fa07a8a1ba34c6c6902ad && git checkout -B drift-repro e40cd1e28dd79e60e7f4be0db06f071f3f962574 && git merge --no-ff 06329b0ae051b5558f3fa07a8a1ba34c6c6902ad
node scripts/docs-audit/affected-docs.mjs --json e40cd1e28dd79e60e7f4be0db06f071f3f962574
|
|
domain:server#5 · os-elon-musk · session_016WV4d1NJYFGVi2FRztyBNo Request: review · area A1 · Fixes #33437 · head d8d72cf · requested at 2026-11-14T23:06Z Local: plugin-auth full suite 274 files / 5307 passed; platform-objects 122 files / 1958 passed; typecheck exit 0; eslint exit 0; i18n bundles in sync; dogfood battery 466 files / 3948 passed; three ablations (account-key create rewrite removed: 6/10 red; findMany key rewrite removed: 4/10 red; Entra default removed: 4/10 red) in the os-dev report (#33437 comment 6885628638); derived gates 108: 106 exit 0, 2 NOT MEASURED (skill-examples, dual-build-cjs-loads). Declarations: |
|
Contract-review-claim: session_016WV4d1PGptBW3QRQNmy5e6 · head d8d72cf · 2026-11-14T23:07:45Z review#3. |
Contract reviewServed-tier: ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgmentKeying at the adapter, with a confirmation at the vendor's one validation hook, is the smallest design that keeps the vendor's lookup, linking rule and create path unchanged. The alternative, forking the SSO callback to pass a different account id, would own far more vendor code. Leaving existing rows alone is decision B. The design holds. The FAIL is M1: the operator-facing sentence about existing accounts has to be measured and say what it measures. Implemented-by: VERDICT: FAIL |
…account-key attribute must be one users cannot edit The changeset and sso.mdx now state exactly the three measured cases: same entry signs in, the other entry is refused account_not_linked, an email change no longer reaches the account (JIT makes a new user, otherwise SELF_REGISTRATION_CLOSED). Claude-Session: https://claude.ai/code/session_016WV4d1NJYFGVi2FRztyBNo Co-authored-by: Claude <noreply@anthropic.com>
|
Contract-review-claim: session_016WV4d1PGptBW3QRQNmy5e6 · head 06329b0 · 2026-11-14T23:30Z review#3 (delta). |
Contract reviewServed-tier: This reviews the delta ① Derived judgments
② Semver levelUnchanged and correct: ③ Boundary flags
④ Design judgmentUnchanged from Implemented-by: VERDICT: PASS |
|
domain:server#5 · os-elon-musk · session_016WV4d1NJYFGVi2FRztyBNo ACCEPT · area A1 · Fixes #33437 · head 06329b0 · 2026-11-15T00:06Z
|
Fixes #33437
Clause-②: yes (narrowing) — widened: the Register SAML Provider form and its bridge (
POST /api/v1/auth/admin/sso/register-saml) take an optionalmapAccountKey, the assertion attribute a provider keys its accounts on, stored as the provider'smapping.extraFields.accountKey; with none named, a Microsoft Entra ID provider (IdP Entity ID onsts.windows.netorlogin.microsoftonline.com) keys onhttp://schemas.microsoft.com/identity/claims/objectidentifierwhen the assertion carries it, so an IdP-initiated entry after an SP-initiated one (or the other way round) signs in to the same account where it was refusedaccount_not_linked. Narrowed: on such a provider a new account's key is that value instead of the NameID, and an account made before this change keeps its NameID key, which a sign-in no longer looks up directly: a sign-in that resolves to the account's email and carries its NameID still signs in to it, but one whose email changed at the IdP no longer reaches it (a new user is made where the provider allows JIT, otherwise the sign-in is refused); and a SAML sign-in whose verified assertion does not carry the account-key value read from the posted one is refusedINVALID_REQUEST. No first-party composition in this repository registers a SAML provider.Metadata-protocol: none
Skills-docs: none — no skill under
skills/**teaches SAML account keys or the SSO register form;content/docs/permissions/sso.mdxgains the rule in this change.维护者速读
mapAccountKey);不填时,Entra ID 提供方(IdP Entity ID 在 sts.windows.net / login.microsoftonline.com)默认用objectidentifier声明;其它 IdP 仍用 NameID。packages/plugins/plugin-auth/src/sso-saml-account-key.ts(规则、对供应商的依赖、验证后确认)·packages/plugins/plugin-auth/src/objectql-adapter.ts中samlAccountKeyWhere/samlAccountKeyOnCreate两处接线 ·packages/plugins/plugin-auth/src/auth-manager.ts中runSsoCallback的 SAML 分支。pnpm --filter @objectstack/plugin-auth exec vitest run --maxWorkers=2 src/sso-saml-refusal-landing.test.ts -t stable,预期 10 个用例全绿;其中前两例显示 SP 发起与门户发起两次进入后只有一个账号、键为 object id、两次都登录成功。What changes
sso-saml-account-key.ts). The key is, in order: the attribute named at registration (mapAccountKey, stored as the provider'smapping.extraFields.accountKey); with none named, for an Entra ID provider (its stored issuer's host issts.windows.netorlogin.microsoftonline.com),http://schemas.microsoft.com/identity/claims/objectidentifier; otherwise the NameID, as before. When the assertion does not carry the attribute, that sign-in is keyed on its NameID, as before.@better-auth/sso1.7.12's SAML mapping has no account-key member (samlMappingSchemais strict; the ACS setsaccountId: extract.nameIDafter spreadingextraFields), and there is no seam between verifying the assertion and resolving the account. So:SAMLResponseis read once (samlAssertionPreview, extending the pre-read fix(auth)!: an unmapped SAML sign-in reads the standard email and name claims before the NameID; SSO creates accounts only for email addresses #33418 added) for the one assertion's NameID and the key attribute's first value. Only a value written as one plain text is read: a comment, CDATA, an entity reference, child markup, an empty value or a repeated attribute reads nothing, and the NameID keys that sign-in. Both go into the request's SAML scope, with the provider's key attribute read from its stored row.findOne/findMany/countonsys_accountwith exactly this provider and this NameID) and account creates to the key value.validateUserInfogate (run with the vendor's verified attributes before it creates a user, links an account or signs in to one): when the verified assertion does not carry that value, the sign-in is refusedINVALID_REQUEST(existing plugin-auth ledger code), with a description that names no value and onewarnline naming the provider and attribute only.register_saml_providergainsmapAccountKey(sys-sso-provider.object.ts), passed by the SAML register bridge inregister-sso-provider.ts; translations regenerated withnode scripts/check-i18n-bundles.mjs --write --filter=platform-objects.content/docs/permissions/sso.mdx, the SAML register table row and a new "Key accounts on a stable attribute" subsection of the SAML mapping section, which now states that both entries reach one account for a provider keyed on a stable attribute (the line fix(auth)!: an unmapped SAML sign-in reads the standard email and name claims before the NameID; SSO creates accounts only for email addresses #33418 withdrew).patchforplugin-authandplatform-objects, declared BREAKING with its ADR-0087 disposition.Tests
End to end, real
AuthManager+better-auth+@better-auth/ssoover the in-memory engine, the IdP played with the vendor's ownsamlifysigning with a generated key: a new top-leveldescribeinsso-saml-refusal-landing.test.ts(10 cases):account_not_linked, nothing written.Pure halves:
sso-saml-account-key.test.ts(issuer recognition incl. look-alike hosts, attribute choice, the bridge's mapping write, the preview reading and its refusals, the adapter halves in and out of scope, the confirmation's three branches).Ablations (
scripts/ablation-replace.mjs, each on committed headd8d72cf5d1, run-t stableon the landing file; each restore verified blob == HEAD andgit diff HEADempty; plugin-auth tests import their ownsrc, so no rebuild leg):samlAccountKeyOnCreate): 6 of 10 red (both Entra two-entry cases, email change, both named-attribute cases, same-provider-only); the NameID-keyed cases and the CONTROL stay green.findManyread half (the vendor'sfindAccountOwnerByKey): 4 of 10 red (both two-entry cases, email change, named attribute across entries).Acceptance notes
@better-auth/sso1.7.12 resolving the SAML account through the adapter by(providerId, accountId = NameID)within the ACS request. A vendor that changes that lookup leaves the NameID keying the accounts; the end-to-end pins go red on it. The durable fix is upstream: an account-key member in the SAML mapping.mapping.idin the vendor. The vendor's SAML mapping has no id member to reuse, so the key rides the genericextraFieldsmember, as the groups claim does (extraFields.groups);extraFields.accountKeytherefore also appears on the vendor'suserInfo, which no user column declares.check:i18n-coveragecounts no untranslated label for platform-objects).Verification
Readings at
d8d72cf5d1(the branch withorigin/mainmerged at19cc8976bf), shared container.plugin-auth and platform-objects: suites, typecheck, lint
pnpm --filter @objectstack/plugin-auth exec vitest run --maxWorkers=2:Test Files 274 passed (274),Tests 5307 passed | 10 skipped (5317);pnpm --filter @objectstack/platform-objects test:Test Files 122 passed (122),Tests 1958 passed (1958); lockVERDICT command-exit 0.pnpm --filter @objectstack/plugin-auth typecheckandpnpm --filter @objectstack/platform-objects typecheck(tsc, examples/scripts,check:test-typecheck): lockVERDICT command-exit 0.eslint --no-inline-configover the changed.tsfiles: exit 0.node scripts/check-i18n-bundles.mjs --filter=platform-objects: in sync (32 bundles), exit 0.plugin-auth'ssrc/index.tsis untouched; the platform-objects change is one action parameter.Derived gate families (dispatch-gates --commands, 108)
@objectstack/spec check:skill-examples,check:dual-build-cjs-loads.dispatch-gates --ran(with exit codes): 108 derived, 106 run, 2 NOT-MEASURED, 0 UNRUN.Dogfood battery (title carries a breaking marker)
Generated by Claude Code