Repository navigation
Commit 0208b68
fix(plugin-auth)!: the SSO domain check refuses a subdomain listed beside its parent, and compares one spelling (#32383)
Fixes #32308
Clause-②: no (narrowing)
Metadata-protocol: none
> Declaration corrected by the seat (card comment 6784574779 on #32308):
the newly refused shapes were accepted before, so this is the narrowing
arm, as contract review 6771575242 graded the same refusal class on this
door. The changeset carries `!`, the BREAKING banner and one ADR-0087
marker; the whole dogfood battery is green on the final head.
## 维护者速读
- 改了什么:SSO
提供方的"同一域名只能一个"检查补了两种漏判:多域名列表里的子域与父域并存(两种注册顺序都拒),以及同一域名的不同写法(punycode 对
Unicode、末尾的点);另加域名长度上限(整值 255、单项 253),超长在解析前拒绝 400;非平台管理员收到的 child
拒绝只点名自己请求的父域。
- 为什么改:厂商按"整值精确匹配,否则按存储行序取第一个列表匹配"路由,列表里的子域赢不了第一步,由行序决定;不同写法是同一个 DNS
域名。上一轮复审还指出去尾点的正则对请求可控输入是二次方回溯,现改为线性扫描。
- 风险与回滚:只会多拒绝注册和域名修改,不放行任何今天被拒的请求;已存的提供方不受影响。回滚即还原本 PR。
-
先看:`packages/plugins/plugin-auth/src/sso-provider-lifecycle.ts`(`withoutTrailingDots`、`ssoDomainTooLong`、`claimSentence`
的 child
分支)、`auth-manager.ts`(`assertSsoProviderDomainFree`:先判长度再解析)、`sso-provider-lifecycle.test.ts`。
- 两分钟验证:`pnpm --filter @objectstack/plugin-auth exec vitest run
--maxWorkers=2 src/sso-provider-lifecycle.test.ts`,预期 29 个用例全过。
- 需要你做的:无,席位落地。
## What changes
`assertSsoProviderDomainFree` already refused `409 RESOURCE_CONFLICT`
(`field: 'domain'`) an exact domain entry another provider lists. This
PR closes N2 and N3b of contract review 6774898717, records why N3a
stays open, and takes every finding of contract review 6787108839.
**Measured vendor routing** (`@better-auth/sso` 1.7.12, `/sign-in/sso`,
read from the installed `dist/index.mjs`): step 1 is `findOne({ domain:
EMAIL_DOMAIN })`, an equality on the whole stored value; step 2 is
`findMany({ model: 'ssoProvider' })` with no `sortBy`, then
`.find(domainMatches)` (an entry equal to the domain, or the domain
ending with `.` plus the entry). The adapter passes no `orderBy` when no
`sortBy` is given, so "first" at step 2 is the store's row order, which
no contract fixes.
- **N2 fixed.** `findSsoDomainClaim` reads every provider row and
returns one of three kinds. `exact` is the old rule. `parent`: the
request lists a subdomain, does not win step 1 for it (its value is a
list, or another spelling of the entry), and another provider lists the
parent. `child`: the request lists a parent of an entry another provider
holds in a list (or in another spelling). Judged in both registration
orders, because row order is not registration order. `code`, `status`,
`field` and the `heldBy` rule are unchanged.
- **N3b fixed.** The store read is no longer narrowed by `$icontains` on
the requested spelling. Every entry on both sides goes through one
`bareDomain`: the URL parser's lower-case ASCII host (punycode for an
internationalised name), trailing root dots dropped, as the vendor's own
parse (`tldts`) does.
- **N3a not fixed: recorded** in the seat's answer 6784574779 (no
transaction on the vendor's register, no store constraint that expresses
the rule, a claim table needs a backfill).
- **N6, N7** as before: the `skip_user_info` edit pin through
`/admin/sso/update-provider`, and the ruled wording in the
`assertSsoProviderDeletable` comment.
Contract review 6787108839:
- **F1.** `bareDomain` runs no pattern: trailing dots are dropped by one
backward index scan and one `slice` (`withoutTrailingDots`); the
trailing-run pattern it replaces backtracked quadratically on a dot run
that does not end the string. A length cap refuses before any parse,
`400 VALIDATION_FAILED`, `field: 'domain'`, `fields: [{ field: 'domain',
code: 'max_length' }]`: a value longer than **255** characters
(`sys_sso_provider.domain` declares `maxLength: 255`, so a longer value
could never be saved), or an entry longer than **253** characters (the
DNS host-name limit: RFC 1035's 255-octet wire form less its leading
length octet and the root label; one trailing root dot not counted). The
cap is asked after the session check, so a sessionless caller's domain
is only type-checked and trimmed, never parsed; the vendor answers that
caller `401` as before.
- **F2.** To a caller who is not a platform administrator, the `child`
refusal names only the parent the request holds ("A subdomain of the
email domain 'acme.example' is served by another SSO provider ..."),
never the other provider's listed subdomain; a platform administrator is
told the subdomain and `heldBy`.
- **F3.** `winsExactStep` compares the stored value by plain equality,
with no trim, as the vendor's step 1 does: a single entry stored padded
with whitespace does not win step 1, so its parent is refused, and a
padded subdomain requested beside a stored parent is refused.
- **F4, F5 (changeset).** Two spelling legs are named as newly refused:
a punycode entry requested beside the same name stored in Unicode, and
the trailing root dot, either way round (`acme.com.` beside a stored
`acme.com`, and `acme.com` beside a stored `acme.com.`). The reverse
internationalised leg (Unicode requested beside punycode stored) was
already refused on `main` and is named as such. The reason given is that
the two spellings are one DNS domain; sign-in itself does not convert
between Unicode and punycode.
## Tests
`packages/plugins/plugin-auth/src/sso-provider-lifecycle.test.ts` (29
cases), on the real engine, `AuthManager`, `sso()` plugin and route
registration:
- refused `409` + `RESOURCE_CONFLICT` + `field: 'domain'`: a listed
subdomain beside its parent (`eng.acme.example, foo.example`,
`https://eng.acme.example`, `Eng.Acme.example`); a parent beside a
listed subdomain; a domain edit adding a listed subdomain;
`xn--bcher-kva.example` beside a stored `bücher.example`;
`MÜNCHEN.example` and `xn--mnchen-3ya.example.` beside a stored
`xn--mnchen-3ya.example`; `globex.example` beside a stored
`globex.example.`. Nothing written in each case.
- F2: the `child` refusal to an organization administrator (no `heldBy`,
the requested parent only, no listed subdomain, no provider id) and to a
platform administrator (`heldBy` and the subdomain), on the same
request.
- F3: a single entry stored as `' eng.acme.example '` does not shield
its parent; `' eng.globex.example '` requested beside a stored
`globex.example` is refused.
- F1: a 300 000-dot value is refused `400 VALIDATION_FAILED` at
`/sso/register` and `/sso/update-provider`, nothing written, and a
sessionless caller gets the vendor's `401`; an entry of 254 characters
is refused, one of 253 (with or without a root dot) is saved;
`providerDomains` on a 200 000-dot entry returns within a 5 s bound.
- controls that stay accepted: the single-entry subdomain beside its
parent, both ways round; `xacme.example, foo.example` beside
`acme.example`; `bucher.example` beside `bücher.example`.
## Acceptance notes
- Not filed: with a parent `acme.com` and a child provider whose whole
domain is `eng.acme.com` (the ruled-accepted configuration), a deeper
name such as `x.eng.acme.com` matches both lists at step 2, so row order
picks. The module comment says so. It is the ruled configuration, left
as it is.
- The vendor's step-2 read sees only `limit || 100` rows while this
check reads every row: filed by the seat as #32388.
- From review F5, a candidate follow-up rather than a fix here: a
single-entry subdomain typed in Unicode beside its parent is refused as
"another spelling", and the vendor will only ever match a provider
stored in Unicode for an address typed in Unicode.
## Verification
All readings at `7a24843d1c` (the final head: the F1 to F5 commits, then
`origin/main` merged).
<details>
<summary>Tests and typecheck</summary>
- `pnpm --filter @objectstack/plugin-auth test`: exit 0, Test Files 262
passed (262), Tests 4835 passed, 10 skipped (4845).
- `pnpm --filter @objectstack/plugin-auth typecheck`: exit 0,
`check:test-typecheck: OK`.
</details>
<details>
<summary>Ablations (scripts/ablation-replace.mjs, each anchor 1 to 0,
restored to the HEAD blob, `git diff HEAD` empty)</summary>
- B1, the length cap off in `assertSsoProviderDomainFree`: red, the
long-dot-run case and the over-long-entry case (2 of 29).
- B2, the trailing-dot drop off in `bareDomain`: red, the spelling case
at its dotted leg and the linear-scan case (2 of 29).
- B3, the trailing-run pattern put back in place of the scan: red, the
linear-scan case timed out at its 5000 ms bound (ran 28 553 ms; 1 of
29).
</details>
<details>
<summary>Dogfood battery and gates</summary>
- Whole battery, under the lock, no `OS_TEST_SHARD`, closure built at
this head: `pnpm --filter @objectstack/dogfood test`, VERDICT
command-exit 0, Test Files 451 passed, 3 skipped (454), Tests 3775
passed, 42 skipped (3817). One run, no failure.
- `node scripts/pm/dispatch-gates.mjs --commands`: 75 derived families,
all exit 0; `--ran` reconciliation 75 run, 0 NOT-MEASURED (a derived
zero: every line records its exit code).
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01QSeKYm8sWjp2Pk76warN7w)_
<!-- signed: domain:server#7 · os-justin ·
session_01QSeKYm8sWjp2Pk76warN7w -->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent c5758b0 commit 0208b68
4 files changed
Lines changed: 567 additions & 50 deletions
File tree
- .changeset
- 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 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| 139 | + | |
139 | 140 | | |
140 | 141 | | |
141 | 142 | | |
| |||
5744 | 5745 | | |
5745 | 5746 | | |
5746 | 5747 | | |
5747 | | - | |
5748 | | - | |
| 5748 | + | |
| 5749 | + | |
| 5750 | + | |
5749 | 5751 | | |
5750 | 5752 | | |
5751 | 5753 | | |
| |||
5793 | 5795 | | |
5794 | 5796 | | |
5795 | 5797 | | |
5796 | | - | |
| 5798 | + | |
| 5799 | + | |
| 5800 | + | |
5797 | 5801 | | |
5798 | 5802 | | |
5799 | 5803 | | |
5800 | | - | |
5801 | | - | |
5802 | | - | |
5803 | | - | |
| 5804 | + | |
| 5805 | + | |
| 5806 | + | |
| 5807 | + | |
| 5808 | + | |
| 5809 | + | |
| 5810 | + | |
| 5811 | + | |
| 5812 | + | |
| 5813 | + | |
| 5814 | + | |
5804 | 5815 | | |
5805 | 5816 | | |
5806 | 5817 | | |
5807 | 5818 | | |
5808 | 5819 | | |
5809 | | - | |
5810 | | - | |
| 5820 | + | |
| 5821 | + | |
5811 | 5822 | | |
5812 | 5823 | | |
5813 | 5824 | | |
5814 | 5825 | | |
5815 | | - | |
5816 | 5826 | | |
| 5827 | + | |
| 5828 | + | |
| 5829 | + | |
| 5830 | + | |
| 5831 | + | |
| 5832 | + | |
| 5833 | + | |
| 5834 | + | |
5817 | 5835 | | |
5818 | 5836 | | |
5819 | | - | |
| 5837 | + | |
5820 | 5838 | | |
5821 | 5839 | | |
5822 | 5840 | | |
| |||
0 commit comments