Repository navigation
Commit de5eb08
fix(plugin-auth)!: with SSO domain verification on, an SSO sign-in links to an existing account, or changes its email address, only at a domain the provider has proven (#33307)
Clause-②: no (narrowing)
Metadata-protocol: none
Skills-docs: none — no file under `skills/**` teaches SSO domain
verification, account linking or an address change through an SSO
provider; `content/docs/permissions/sso.mdx` ("Domain verification
(opt-in)") states the rule.
## 维护者速读
- 改了什么:开启 SSO
域名验证后,"经由身份提供方到达的账号,其邮箱只能位于该提供方已验证的域名"这条规则(此前只管新建账号)现在也管另外两条路径:隐式关联到已有账号,以及会改写已关联账号已存邮箱的登录。会改写邮箱、而新邮箱不在已验证域名时拒绝;无法判定是否会改写时也拒绝;不改写任何东西的登录照常放行。拒绝码为
`EMAIL_DOMAIN_NOT_ALLOWED`,不写关联、不发会话、已存邮箱不变。依据为维护者裁决(review#2 记录
6884303063 转述,选项 B「只拦会改邮箱的登录」)。
-
为什么改:让域名验证的保证在账号被"到达"的每一条会落地变化的路径上都成立,而不只是在新建时;匹配方式与新建时完全相同(精确匹配,子域名须自身列出并验证)。
- 风险与回滚:仅在开启域名验证的环境生效;关闭验证、非 SSO 来源、用户自己发起的显式关联、不改写邮箱的登录(含所有 SAML
提供方,以及平台自身注册流程下从不开启更新的 OIDC 提供方)均不变。本地账号位于"已列出域名的未列出子域名"的人,首次经 SSO
登录会被拒,需把该子域名加到提供方并重新验证;完全未列出的域名此前就不关联,不受影响。回滚即还原本 PR。D6 的 ADR 说明在
#33356(Tier H,另行审批)。
- 先看:`packages/plugins/plugin-auth/src/implicit-account-linking.ts`(规则
4:`refuseImplicitAccountLink`
新增判定;`refuseSsoAddressChangeOutsideProvenDomain` 与
`ssoSignInWritesAddress`,后者读不到即按"会改写"处理);`packages/plugins/plugin-auth/src/auth-manager-auth-instance.ts`(`validateUserInfo`
串接顺序);`packages/plugins/plugin-auth/src/sso-account-at-proven-domain.ts`(仅抽出
`readSsoProviderProvenDomains`,新建规则行为不变)。
- 两分钟验证:`pnpm --filter @objectstack/plugin-auth exec vitest run
src/implicit-account-linking.test.ts src/sso-oidc-refusal-cause.test.ts
src/sso-saml-refusal-landing.test.ts
src/sso-account-at-proven-domain.test.ts`,预期 `Tests 255 passed (255)`(合并
main 后)。
- 需要你做的:无,席位落地。
## What changes
The rule, as ruled (the maintainer's ruling relayed in review#2 record
6884303063): with SSO domain verification on, an account reached through
a provider holds an email address only at a domain that provider has
proven. Account creation already follows it. This PR applies the same
rule, with the same module, to the two other ways an SSO sign-in (SAML
or OIDC) reaches an account:
- **An implicit link.** A sign-in that links to an account that already
exists is admitted only when the asserted address is at a domain the
provider has proven, compared exactly: a subdomain counts only when it
is itself listed and verified (`refuseImplicitAccountLink`, rule 4 in
the `implicit-account-linking.ts` header). The two cases are kept apart.
An address at a domain the provider does not list at all was already not
linked, and is still refused as before with the same answer (pinned as a
CONTROL). An address at a subdomain of a listed domain that is not
itself listed and verified was linked before and is now refused.
- **A sign-in that would change the stored address.** A sign-in into an
already-linked account is refused when it would change the stored
address to one outside the proven domains, and refused where whether it
would change the address cannot be determined. A sign-in that reports an
address outside the proven domains but changes nothing is admitted, as
before. This is `refuseSsoAddressChangeOutsideProvenDomain`, chained
into `validateUserInfo` after the link gate and before the audience
gate. Whether the sign-in writes the address is the vendor's own
decision, read from the inputs it reads (`ssoSignInWritesAddress`): for
OIDC, the provider's stored update setting, which the platform's own
provider registration never turns on; for SAML, none; and a configured
`defaultSSO` entry or `resolveUser` selection where one is composed. A
decision that cannot be read is judged as a write.
- **The refusal** is `EMAIL_DOMAIN_NOT_ALLOWED`, the code creation
answers, with a rule-level description per case that names no domain. No
new error code. A provider row that cannot be read refuses; an account
that cannot be read throws, which the sign-in answers with the gate's
general refusal.
- **Reuse.** The provider read moves out of
`refuseSsoAccountOutsideProvenDomain` into the exported
`readSsoProviderProvenDomains`. The creation rule's behaviour is
unchanged and its tests are untouched.
- **Unchanged.** Verification off; sign-ins that would not change the
stored address; non-SSO sources (the cloud identity provider and
enterprise OAuth providers); a link the user starts from their own
session (an explicit link); the domain-matching rule itself.
- **Texts.** `content/docs/permissions/sso.mdx` states the rule for an
implicit link (both cases) and for a sign-in that would change the
address. The gate comments in `sso-account-at-proven-domain.ts` and
`auth-manager-auth-instance.ts`, the SSO mount comment in
`auth-manager-plugin-list.ts`, and the TSDoc of
`isSsoDomainVerificationEnabled` all state the rule for creation,
implicit link and address change.
- **ADR.** The dated ADR-0135 D6 note recording this extension and its
ruling is the separate governed PR #33356.
## Tests
Named by the rule.
- `sso-oidc-refusal-cause.test.ts`, section 6 (real `AuthManager`, real
vendor callback, stubbed IdP), covering:
- an implicit link at an unlisted subdomain: refused, with no
`sys_account` row and no session;
- an implicit link at a domain the provider does not list at all:
refused as before (CONTROL);
- an implicit link at a proven domain: links and signs in;
- with a provider that updates the account, a change to an outside
address or to an unlisted subdomain: refused, stored email unchanged, no
new session;
- a change to another proven domain: applies;
- with a provider that does not update the account, an outside address
asserted later: signs in, and nothing changes;
- CONTROLS: verification off, and a later sign-in with the stored
address.
- `sso-saml-refusal-landing.test.ts`:
- the implicit-link pair over SAML, plus the verification-off CONTROL;
- a later SAML sign-in asserting an outside address: signs in, and the
stored address is unchanged.
- `implicit-account-linking.test.ts`, new top-level describe: the rule
on its own inputs, OIDC and SAML, including:
- the write decision read as the vendor reads it;
- fail-closed cases;
- CONTROLS for verification off, a non-SSO source, an explicit link (an
OAuth source), and the creation rule unchanged.
<details><summary>Readings</summary>
- Before the fix, on this branch's base: the new end-to-end cases ran
red, 3 failed of 8 (OIDC) and 1 failed of 3 (SAML).
- At `c21b6b600c`, the four affected files: `Test Files 4 passed (4)`,
`Tests 218 passed (218)`. `pnpm --filter @objectstack/plugin-auth
typecheck` exit 0.
- At `ba3fd25ea8`, the last code change (`c21b6b600c` adds comment and
prose only), `pnpm --filter @objectstack/plugin-auth test`: `Test Files
270 passed (270)`, `Tests 5157 passed | 10 skipped (5167)`, and
typecheck exit 0.
- Ablation. Each leg ran through `scripts/ablation-replace.mjs`, with
the anchor proven on disk and the restore proven by blob equality with
`HEAD`.
- The implicit-link check removed: `Tests 5 failed | 200 passed (205)`;
restored.
- The address-change judge removed (first rule): `Tests 4 failed | 201
passed (205)`; restored.
- The write-decision call removed: `Tests 4 failed | 207 passed (211)`;
restored.
- The stored update setting forced on: `Tests 2 failed | 209 passed
(211)`; restored.
- The SAML branch of the write decision removed: `Tests 2 failed | 209
passed (211)`; restored.
- Dogfood battery:
- Last full run at `b0796f0239` (before the narrower address rule):
`Tests 2 failed | 3925 passed | 42 skipped (3969)`. Both failures were 5
s timeouts on a contended box. Re-run alone: `Tests 36 passed (36)`.
- At `ba3fd25ea8`: the local run was interrupted, so it is NOT MEASURED
locally. CI's `Dogfood Regression Gate` on that head: success.
- `c21b6b600c` is comment and prose only, so it owes no battery.
</details>
## Acceptance notes
- Two open drafts touch nearby text. One edits the header of
`implicit-account-linking.ts` at the spot where rule 4 is inserted,
which is a textual merge of two doc paragraphs. The other edits a
different section of `sso.mdx`. Neither touches the gate code.
- Local gates at `c21b6b600c`: the `dispatch-gates --commands`
derivation for this diff, 105 families, reconciled with `--ran`: 105
run, 0 not measured.
## Verification
- `pnpm --filter @objectstack/plugin-auth exec vitest run
src/implicit-account-linking.test.ts src/sso-oidc-refusal-cause.test.ts
src/sso-saml-refusal-landing.test.ts
src/sso-account-at-proven-domain.test.ts`
---
_Generated by [Claude
Code](https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f)_
<details><summary>Merge of origin/main (head 4a7e194)</summary>
- Two files conflicted, both from main's new SAML account-key and
address-value checks in the same `validateUserInfo` chain:
- `auth-manager-auth-instance.ts`: both kept, in the order identity
locale, SAML account key, the proven-domain creation check, the
address-value check, the implicit-link gate, the address-change gate,
then audience admission.
- `implicit-account-linking.test.ts`: both appended describes kept.
- The rule text and code are unchanged from the reviewed head.
`implicit-account-linking.ts`, `sso.mdx` and the changeset merged
cleanly and are byte-identical in this PR's own lines.
- At `4a7e194f97`:
- the four touched files: `Tests 255 passed (255)`;
- `pnpm --filter @objectstack/plugin-auth test`: `Test Files 275 passed
(275)`, `Tests 5355 passed | 10 skipped (5365)`; typecheck exit 0;
- dispatch-gates: 105 derived, 105 run, 0 NOT-MEASURED;
- dogfood battery (owed: the merge brought non-text plugin-auth
changes): `Test Files 467 passed | 3 skipped (470)`, `Tests 3953 passed
| 42 skipped (3995)`, VERDICT command-exit 0.
</details>
<!-- signed: security#1 · sunhaolin · session_017xRBcT1w3zpekijraHJE4f
-->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent b95d915 commit de5eb08
10 files changed
Lines changed: 669 additions & 30 deletions
File tree
- .changeset
- content/docs/permissions
- packages/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 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
380 | 380 | | |
381 | 381 | | |
382 | 382 | | |
383 | | - | |
384 | | - | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
385 | 404 | | |
386 | 405 | | |
387 | 406 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
71 | | - | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
72 | 76 | | |
73 | 77 | | |
74 | 78 | | |
| |||
353 | 357 | | |
354 | 358 | | |
355 | 359 | | |
356 | | - | |
357 | | - | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
358 | 365 | | |
359 | 366 | | |
360 | 367 | | |
| |||
364 | 371 | | |
365 | 372 | | |
366 | 373 | | |
367 | | - | |
| 374 | + | |
368 | 375 | | |
369 | 376 | | |
370 | 377 | | |
371 | | - | |
| 378 | + | |
| 379 | + | |
372 | 380 | | |
373 | 381 | | |
374 | 382 | | |
375 | 383 | | |
376 | 384 | | |
377 | 385 | | |
378 | 386 | | |
| 387 | + | |
379 | 388 | | |
380 | 389 | | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
381 | 393 | | |
382 | 394 | | |
383 | 395 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
770 | 770 | | |
771 | 771 | | |
772 | 772 | | |
773 | | - | |
774 | | - | |
775 | | - | |
776 | | - | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
777 | 780 | | |
778 | 781 | | |
779 | 782 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5994 | 5994 | | |
5995 | 5995 | | |
5996 | 5996 | | |
5997 | | - | |
5998 | | - | |
| 5997 | + | |
| 5998 | + | |
| 5999 | + | |
| 6000 | + | |
| 6001 | + | |
5999 | 6002 | | |
6000 | 6003 | | |
6001 | 6004 | | |
| |||
0 commit comments