You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a27d88d
Browse filesBrowse the repository at this point in the historyBrowse files
fix(plugin-auth)!: under local sign-in off, the last identity provider is the last way in; the direct sign-in door keeps ?redirect= (#33623)
Part of #33358
Clause-②: yes (narrowing) — narrowed: with direct sign-in on and its
local sign-in path `off` (`directSignIn.localSignIn: 'off'`, or
`OS_AUTH_DIRECT_SIGN_IN_LOCAL_PATH=off`), `POST
/api/v1/auth/sso/delete-provider` on the last identity provider answers
`409 DELETE_RESTRICTED` and deletes nothing while email and password is
switched on, where it deleted the row; email and password, and phone
sign-in, no longer count as a way in there, because the sign-in page
does not offer them. Widened: module exports (not on the package entry)
`pageOffersLocalSignIn`, `pageOffersEmailPassword` and
`carriedRedirect`, an optional `localSignIn` on
`SignInMethodConfigView.features`, and an `asThePageOffers` option on
`otherSignInMethods`; the refusal under `off` answers with a new
message, the copy key `enterpriseSsoLocalOff`, in all 11 locales.
Metadata-protocol: none
Skills-docs: none — no skill under `skills/**` teaches direct sign-in,
the provider delete or the boot report;
`content/docs/permissions/sso.mdx` gains the rule in this change.
## 维护者速读
- **改了什么**:直接登录把本地登录路径设为 `off`
时,登录页不再显示邮箱/密码和手机登录;现在"保留最后一种登录方式"的检查也不再把它们算作登录方式,所以删除最后一个身份提供方会被拒绝(409),启动时也会报错提示。另外,直接登录入口把人送回登录页时(身份提供方报错、被限流、无法发起)会带上原来的
`?redirect=`。
- **为什么改**:之前在 `off`
下删掉最后一个身份提供方会成功,随后登录页只显示"没有可用的登录方式",所有人(包括管理员)被锁在外面;深链接用户在出错后重试会落到首页而不是原来要去的页面。
- **风险与回滚**:只影响开启直接登录且本地登录路径为 `off` 的自托管部署(之前允许的删除现在被拒,属于收窄,已标
BREAKING);`hidden`(默认)和未开启直接登录的部署行为不变。回滚即 revert 本 PR。
-
**先看**:`packages/plugins/plugin-auth/src/sign-in-method-floor.ts`(`ssoProviderDeleteRefusal`
与 `resolveNoSignInMethodReport`
两处判断)、`packages/plugins/plugin-auth/src/direct-sign-in.ts`(`carriedRedirect`
与两个落地地址)、`.changeset/33358-local-sign-in-off-floor.md`。
- **两分钟验证**:`pnpm --filter @objectstack/plugin-auth exec vitest run
src/sign-in-method-floor.test.ts src/direct-sign-in.test.ts`,预期全部通过,其中包含
`under the local sign-in path off, deleting the last provider is
refused` 与 `keeps the page's ?redirect=` 几条。
- **需要你做的**:无,席位落地。
## What changes
Items covered from #33358: **1** (N7, the sign-in method floor and the
boot report), **3** (the provider-error return address keeps
`?redirect=`) and **4** (the rate-limited landing keeps `?redirect=`).
Items **2** (the IP allow-list landing on the direct sign-in door) and
**5** (the N13 sign-out note) remain on the card for a later round.
**Item 1 — the floor counts what the sign-in page offers.** The page
decides what it draws from `features.localSignIn`, which
`getPublicConfig()` serves only while direct sign-in is on: under
`'off'` `LoginForm` draws no email and password and no phone sign-in.
The floor now reads the same served value with the same predicate
(`pageOffersLocalSignIn(config)` is `config.features?.localSignIn !==
'off'`, exactly the page's test), so:
- `ssoProviderDeleteRefusal` (the `/sso/delete-provider` door) and
`resolveNoSignInMethodReport` (the boot report) count email and password
only when it is on **and** the page offers it
(`pageOffersEmailPassword`), and count phone sign-in only when the page
offers it (`otherSignInMethods(..., { asThePageOffers: true })`).
- The 409 under `off` carries a new localized copy,
`enterpriseSsoLocalOff` (11 locales), chosen by
`!pageOffersLocalSignIn(config)` whatever email and password says,
because the existing copy's remedy, "turn email and password sign-in
back on", draws nothing under `off`. Its remedy: register another
identity provider, set up another sign-in method, or set the local
sign-in path back to `hidden` with email and password sign-in on.
- The boot report under `off` (chosen the same way) names
`OS_AUTH_DIRECT_SIGN_IN_LOCAL_PATH=hidden` as the recovery, plus
`OS_AUTH_EMAIL_PASSWORD_ENABLED=true` when email and password is off
too; it no longer says "no phone-number sign-in" there.
Phone sign-in is included as a bounded in-place fix: it is the same
defect class (a local way in the page does not draw under `off`, counted
anyway), a mechanical change in the same file, held by this claim, in
the same gate family. Without it a deployment with phone sign-in on and
`off` would pass the same delete and reach the same "No sign-in method
is available" page.
**Items 3 and 4 — the door's landings keep `?redirect=`.** The Console
hands the door its own path and query as `callbackURL` (for example
`/_console/login?redirect=%2Fapps%2Fcrm&direct=returned`).
`carriedRedirect(kept)` reads `redirect` from the already-kept return
path, carries it only when it is sent once and is itself a kept return
path (`keptReturnPath`, the door's existing same-origin rule), and both
landings now use it: the `errorCallbackURL` handed to the vendor
(`/login?redirect=...`; better-auth appends its `error` to it) and the
door's own landing (`/login?error=...&redirect=...`, the rate-limited
one and the unavailable one alike). With no `?redirect=`, or a foreign
one, both are the bare page exactly as before.
Docs: `content/docs/permissions/sso.mdx` says both rules, names the two
checks this PR changes (the provider delete and the boot report, email
and password and phone sign-in alike), and says the settings save is
still open on #33358.
## Tests
- `src/sign-in-method-floor.test.ts`, the composition (real kernel,
sqlite, AuthPlugin and settings): under `directSignIn: { localSignIn:
'off' }` with email and password on, deleting the last provider answers
409 `DELETE_RESTRICTED` with `enterpriseSsoLocalOff` and the row stays;
CONTROL: under `hidden` the same delete is 200 and the row is gone; a
boot under `off` with no provider reports `no_sign_in_method_at_boot`
naming `OS_AUTH_DIRECT_SIGN_IN_LOCAL_PATH=hidden`; CONTROL: the same
boot under `hidden` says nothing.
- Same file, the judge over a fake: under `off`, neither email and
password nor phone sign-in counts (delete refused, boot report said);
CONTROL under `hidden`: both count as before; phone alone under `off`
with email and password off is refused with `enterpriseSsoLocalOff` and
its boot report names both settings without "no phone-number sign-in";
CONTROL: email and password off under `hidden` keeps the `enterpriseSso`
copy and the `OS_AUTH_EMAIL_PASSWORD_ENABLED=true` report. Composition:
a boot under `off` with email and password off names
`OS_AUTH_DIRECT_SIGN_IN_LOCAL_PATH=hidden and
OS_AUTH_EMAIL_PASSWORD_ENABLED=true`.
- `src/direct-sign-in.test.ts`: the vendor's `errorCallbackURL` keeps
`?redirect=`; the rate-limited landing keeps it; CONTROL: with no
`?redirect=` both landings are the bare page, as before; a foreign
`?redirect=` is dropped and the landings are the bare page, pinned over
every spelling in `FOREIGN_RETURN_PATHS` (24: absolute,
protocol-relative, backslash, `javascript:`, control characters,
percent-encoded forms, `/..//`, empty, over-long).
## Acceptance notes
- The card names the setting `OS_AUTH_LOCAL_SIGN_IN=off`; the variable
in the code is `OS_AUTH_DIRECT_SIGN_IN_LOCAL_PATH`
(`directSignIn.localSignIn`). The premise holds otherwise.
- Not changed here, same family: the auth **settings save** door
(`signInMethodFloorPredicate`) still counts email and password on under
`off`, so under `off` a save that switches off Google as the last social
provider passes. Its refusal copy speaks of turning email and password
back on, so a fix there needs its own copy. Reported to the seat for the
card rather than widened here.
- Not changed here: the 503 copy (`enterpriseSsoUnverified`) still says
"with email and password off"; under `off` with email and password on it
is slightly inaccurate, but it is still the right refusal.
## Verification
Review#3 delta: head `cc741c8ef3` answers M1 and N1 to N4 of contract
record 6888499485; the runs below the dogfood paragraph were taken at
`2a03b651b6` and the delta's runs are in the first fold. Earlier head
`2a03b651b6` (merge base `c32bb6ccb` = `origin/main` at the time;
`origin/main` had not moved when re-fetched before opening).
**Dogfood battery** (the title carries `!`): `pnpm --filter
@objectstack/dogfood test` under the verify lock, dependency closure
built first, on head `2a03b651b6`. It was still running when this PR
opened; its verdict (Test Files, Tests, every failure named) goes into
the `os-dev-report` comment on #33358, and the PR's own `Dogfood
Regression Gate` runs it in the queue.
<details><summary>Review#3 delta, local runs on head
cc741c8</summary>
- `pnpm --filter @objectstack/plugin-auth test` (verify lock): `Test
Files 274 passed (274)`, `Tests 5336 passed | 10 skipped (5346)`,
`VERDICT command-exit 0`.
- `pnpm --filter @objectstack/plugin-auth typecheck`: `VERDICT
command-exit 0`, `check:test-typecheck: OK` (ledger unchanged). eslint
`--no-inline-config` on the three changed `.ts` files: exit 0.
`check-nul-bytes`: OK.
- M1 ablations (scripts/ablation-replace.mjs, landed and restored, blob
equal to HEAD): delete copy chosen by email and password again: 1 failed
/ 41; boot report branched by email and password again: 2 failed / 41.
- Narrowed gate re-run (declared): `check-adr-0087-registration`,
`check-empty-changeset`, `check-changeset-no-major`,
`check:doc-authoring`, `check:issue-citations`,
`check-closing-keyword-parity`, `check:doc-anchors`,
`check-affected-docs`: all exit 0. The full derived set was not re-run
for the delta; CI runs it.
- Dogfood battery not re-run: the delta changes copy and report-text
selection and test pins only; the runtime decision (refuse or allow,
report or not) is unchanged from `2a03b651b6`, where the battery was
green.
</details>
<details><summary>Local runs on head 2a03b65</summary>
- `pnpm --filter @objectstack/plugin-auth test` (verify lock): `Test
Files 274 passed (274)`, `Tests 5312 passed | 10 skipped (5322)`,
`VERDICT command-exit 0`.
- `pnpm --filter @objectstack/plugin-auth build && pnpm --filter
@objectstack/plugin-auth typecheck`: `VERDICT command-exit 0`;
`check:test-typecheck: OK` (10 files / 72 errors / 23 pinned signatures
held in the existing ledger, unchanged).
- `eslint --no-inline-config` on the four changed source files: exit 0.
`node scripts/check-nul-bytes.mjs`: OK.
- Single files: `src/sign-in-method-floor.test.ts` 40/40,
`src/direct-sign-in.test.ts` 87/87.
</details>
<details><summary>Ablations (one per fix; each mutation landed on disk
via scripts/ablation-replace.mjs and was restored, blob equal to HEAD
and git diff HEAD empty)</summary>
- Delete door back to `config.emailPassword?.enabled !== false`: 2
failed / 38 (the composition delete under `off`, the judge case).
- Boot report back to `config.emailPassword?.enabled !== false`: 2
failed / 38 (the composition boot under `off`, the judge case).
- `errorCallbackURL` back to the bare `/login`: 1 failed / 87 (keeps the
page's `?redirect=`).
- The door's landing without the carried redirect: 1 failed / 87 (the
rate-limited landing).
The tests import `src/` directly (no `dist/` in the path), so no rebuild
leg was needed.
</details>
<details><summary>Derived gate families (dispatch-gates --commands, 97
families)</summary>
97 run: 94 exit 0; 3 exit 3 `PREREQUISITE NOT MET`, read as NOT MEASURED
and left to CI: `check:skill-examples` (no `packages/client-react/dist`
in this worktree), `check:dual-build-cjs-loads` (several packages
unbuilt), `check:type-check-debt` (its re-measure prerequisite).
`dispatch-gates --ran`: 97 derived, 97 run, 0 UNRUN.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_016WV4d1NJYFGVi2FRztyBNo)_
<!-- signed: domain:server#5 · os-elon-musk ·
session_016WV4d1NJYFGVi2FRztyBNo -->
---------
Co-authored-by: Claude <noreply@anthropic.com>
fix(auth)!: under direct sign-in's local sign-in path `off`, the last identity provider is the last way in; the door's landings on the sign-in page keep its `?redirect=`
6
+
7
+
Clause-②: yes (narrowing) — narrowed: with direct sign-in on and its local sign-in path `off` (`directSignIn.localSignIn: 'off'`, or `OS_AUTH_DIRECT_SIGN_IN_LOCAL_PATH=off`), `POST /api/v1/auth/sso/delete-provider` on the last identity provider answers `409 DELETE_RESTRICTED` and deletes nothing while email and password is switched on, where it deleted the row; email and password, and phone sign-in, no longer count as a way in there, because the sign-in page does not offer them. Widened: module exports (not on the package entry) `pageOffersLocalSignIn`, `pageOffersEmailPassword` and `carriedRedirect`, an optional `localSignIn` on `SignInMethodConfigView.features`, and an `asThePageOffers` option on `otherSignInMethods`. The refusal under `off` answers with a new message, the copy key `enterpriseSsoLocalOff`, in all 11 locales.
8
+
Metadata-protocol: none
9
+
Skills-docs: none — no skill under `skills/**` teaches direct sign-in, the provider delete or the boot report; `content/docs/permissions/sso.mdx` gains the rule in this change.
10
+
11
+
<!-- adr-0087: not-required (no-migration-prescription) No schema key, accepted value or metadata type is added, removed, renamed or re-shaped. The moved answer is a runtime refusal at one auth door under a deployment switch, so there is nothing stored for a migration to rewrite and no tombstone. -->
12
+
13
+
**BREAKING** for a deployment running direct sign-in with the local sign-in path `off`: Setup's **Delete SSO Provider** on the last identity provider is refused `409 DELETE_RESTRICTED` (nothing deleted) unless another way in the sign-in page offers remains (another identity provider row, a social or OIDC provider with a client ID and secret, or a host sign-in handoff), even with email and password switched on, and even with phone sign-in switched on. Before, the delete went through and the sign-in page then showed "No sign-in method is available". A boot in that state now reports at error under `no_sign_in_method_at_boot`.
14
+
15
+
Unchanged: the local sign-in path `hidden` (the default) and direct sign-in off, where email and password and phone sign-in count as before; the server's own password sign-in, which `off` never changed.
16
+
17
+
What to do: nothing, unless you delete the last identity provider under `off`. Register another identity provider first, or set `OS_AUTH_DIRECT_SIGN_IN_LOCAL_PATH=hidden` (with email and password sign-in on) and restart.
18
+
19
+
Also fixed: the direct sign-in door hands the identity provider a sign-in page error address that keeps the page's `?redirect=`, and its own landing on the sign-in page (no provider to start, a refused or rate-limited start) keeps it too. A `?redirect=` that is not a same-origin path is dropped, by the return path's own rule.
0 commit comments