Repository navigation
Commit e735892
fix(plugin-auth)!: a locked account is refused on every door that ends in a session for it (#34139)
Clause-②: no (narrowing) — while an account's lock holds (ADR-0069 D2,
`lockoutThreshold` on), every door that ends in a session for that
account refuses it with the answer password sign-in gives under the
deployment's `lockoutRefusal`, and every password door counts its
refused attempts toward that one lock and checks it before the password.
Metadata-protocol: none
Skills-docs: none — no published skill teaches the account lockout or
these sign-in doors (`git grep -i` over `skills/` for `lockout`,
`ACCOUNT_LOCKED`, `locked_until`, `sign-in/phone-number`,
`magic-link/verify` and `phone-number/verify`: zero hits).
## 维护者速读
-
改了什么:账号被锁定期间,任何最终会发出会话的登录入口都拒绝它:短信验证码、邮件登录链接、验证邮件后自动登录、无会话打开的改邮箱确认链接、双因素验证一步(TOTP
/ 一次性码 / 备用码)、经身份提供方登录(社交、通用 OAuth、ID Token、企业
SSO)、设备授权、手机号+密码;答复与邮箱密码登录在当前 `lockoutRefusal`
设置下一致。手机号+密码与邮箱密码一样计入失败次数、成功清零、在校验密码前先查锁。没有密码的账号也会被锁定拦住。
- 为什么改:锁定规则(ADR-0069 D2)要求锁定的账号在每一扇会落成会话的门前都被拒,而不只是邮箱密码这一扇。
-
风险与回滚:只影响处于锁定期的账号与手机号密码的失败计数;未锁定账号、已过期的锁、关闭锁定的部署都不变;管理员模拟登录、已登录用户凭其存储会话做的会话轮换(开双因素、改密码并踢掉其他会话)、服务端进程内的主体会话不受影响(改密码轮换已在
WebContainer 运行时下实测)。开启锁定时,每个携带会话凭据的认证请求多一次会话行读取。回滚即 revert 本 PR。
-
先看:`packages/plugins/plugin-auth/src/auth-manager-sign-in-lockout.ts`(`refuseLockedAccountSession`、`isNotASignIn`、`recordLockoutRequest`)、`sign-in-lockout-refusal.ts`
的请求记录、`auth-manager-before-hook.ts` 的记录接线与手机门闸。
- 两分钟验证:`pnpm --filter @objectstack/plugin-auth exec vitest run
src/locked-account-every-sign-in-door.test.ts`,预期 70/70 通过。
- 需要你做的:无,席位落地。
## What changes
The rule: **a locked account is refused on every door that ends in a
session for that account, with the answer password sign-in gives under
the deployment's `lockoutRefusal`; every password door counts its
refused attempts toward the one lock and checks it before the
password.**
- **The check at session creation** (`auth-manager-sign-in-lockout.ts`,
`refuseLockedAccountSession`, composed into `session.create.before`, the
one write every sign-in door ends in). While `lockoutThreshold` is on
and the account's `locked_until` is still ahead, it refuses a new
session and writes the account's `login_failed` row with the reason
`ACCOUNT_LOCKED`. The counter is not moved. The doors this reaches: the
SMS one-time code, the emailed sign-in link (both lanes), the
verification link that signs the caller in, an address-change
confirmation opened without a session, the second-factor routes (TOTP,
one-time code, backup code), sign-in through an identity provider
(social and generic-OAuth callbacks, the ID-token sign-in, enterprise
SSO over OIDC and SAML; on a callback the refusal rides the provider
door's error redirect with the same code), and the device grant.
- **What is not a sign-in**, each exemption holding only when its
condition is established, and judged a sign-in otherwise:
- the server's in-process principal session: made outside any request,
and carrying the token prefix only the mint writes;
- an administrator's impersonation session: made on the impersonation
route, with `impersonatedBy` naming the account whose live session of
record made the request, which is not the impersonated account;
- a new session for the account whose live session of record made the
request (enrolling a second factor, a password change that ends the
other sessions, an impersonating administrator's own rotation).
- **The request record.** `recordLockoutRequest`, run by the global
before-hook while the lockout is on, records the request's path and the
account of the session of record it presents, read from the stored
`sys_session` row its token names (unexpired) before the endpoint runs,
never from a session cache or the request's own view. It is kept in the
request state, which reaches the database hooks in every supported
runtime, including the WebContainer runtime, where the endpoint context
does not. The check reads the endpoint context when it reaches the hook
and this record otherwise. The first record in a request stands.
- **The password doors** (`/sign-in/email`, `/sign-in/phone-number`):
each has its own gate before the credential check
(`admitSignInAttempt`), which counts toward the account's one lock
(reservation by compare-and-set, as before), refuses a locked account
whatever password it is sent, and is settled by the after-hook (success
resets the count). `/sign-in/phone-number` finds the account by an exact
`phone_number` match, as better-auth does. At session creation a
password door is admitted only on its gate's recorded `admitted` verdict
for this account in this request, and refused when that verdict is
absent. Under `'uniform'` a locked account at a password door gets that
door's own wrong-password answer (`INVALID_EMAIL_OR_PASSWORD`,
`INVALID_PHONE_NUMBER_OR_PASSWORD`); under `'explicit'`, `403
ACCOUNT_LOCKED`. The email door's session controls, last-login stamp and
ban-cause step are unchanged and stay email-only.
- `sign-in-lockout-refusal.ts`: `lockedAccountRefusal` is the one answer
for both settings (`'uniform'`: the vendor's code with the sentence read
off its constant, held equal to the measured `/sign-in/email` answer by
the pins), plus the request-record carrier.
- `packages/runtime/src/dispatcher-error-vocabulary.ts`: one
`foreign-vocabulary` row (shape `objlit`) for the vendor's
`INVALID_EMAIL_OR_PASSWORD` stamped in `sign-in-lockout-refusal.ts`. No
ledger entry and no `packages/spec` change.
- Docs: `content/docs/permissions/authentication.mdx` states the rule
and names every door and the accounts with no password;
`content/docs/kernel/runtime-services/audit-service.mdx` says when a
`login_failed` row is written.
- Changeset
`.changeset/plugin-auth-locked-account-every-sign-in-door.md`:
`fix(plugin-auth)!:`, patch (plugin-auth, runtime), both declarations,
ADR-0087 `not-required (no-migration-prescription)`, and a rule-level
BREAKING paragraph whose Now and Who moves name every door and
population above.
## Tests
`src/locked-account-every-sign-in-door.test.ts` (new, 70 cases): a real
`AuthManager` through `handleRequest`, with twoFactor, phoneNumber,
magicLink, admin and deviceAuthorization mounted, `lockoutThreshold: 3`,
and the account's own `locked_until`. The reference answer is always
measured: `/sign-in/email` for the same locked account in the same
deployment.
- Under both `lockoutRefusal` values, a locked account gets no session
row and the reference answer at the SMS code, the sign-in link (both
lanes), the verification link, `/two-factor/verify-totp`,
`/two-factor/verify-otp` and `/two-factor/verify-backup-code`, the
device grant and the address-change confirmation opened without a
session (its address is not moved). An identity provider's callback
redirects to the error with the reference code. Each refusal writes one
`login_failed` row for that door with `ACCOUNT_LOCKED`, and an enrolled
locked account gets no challenge at a code door.
- `/sign-in/phone-number`: one answer whatever the password, no session;
three wrong passwords lock the account and write `account_locked`; a
correct password resets the count.
- With no gate verdict recorded, a locked account gets no session at
`/sign-in/email`, and an unlocked one still signs in.
- Fail closed, one pin per exemption: a session made outside any request
without the mint token, an impersonation mark without a session of
record, the request's own view of a session, and a password door with no
verdict are each refused, and an expired session presented by the same
account exempts nothing.
- Where no endpoint context reaches the database hooks (the WebContainer
runtime, stood up by emptying the endpoint-context store for the request
under test): the correct password on the attempt that reaches the
threshold signs in and clears the count at both password doors; a
locked, signed-in account's password change still ends its other
sessions; a code door still refuses.
- CONTROLS: an unlocked account and an expired lock sign in at every
door; with the lockout off a stored lock is not read; password sign-in
is unchanged; `/sign-in/email` counts and resets as before; the
second-factor challenge, the OTP completion, the device grant, an
identity-provider sign-in and the address-change confirmation work for
an unlocked account; impersonation of a locked account, a locked
administrator's own rotation, change-password with `revokeOtherSessions`
and the in-process principal session all keep working.
<details><summary>Readings (head 4d27b2c)</summary>
- `pnpm --filter @objectstack/plugin-auth test`: Test Files 278 passed
(278), Tests 5594 passed, 10 skipped. The new file is 70 of 70 in that
run.
- `pnpm --filter @objectstack/plugin-auth typecheck`: exit 0. `pnpm
--filter @objectstack/runtime typecheck`: exit 0.
- Runtime ledger suites (`error-envelope.conformance`,
`http-dispatcher.error-leak`, `package-door-error-parity`,
`actions-validation-envelope`): 4 files, 70 tests passed.
- Red before, green after, for the runtime without endpoint context:
with the three source files taken from 4eadd3d and this head's tests,
3 of 70 fail (both password doors' threshold-reaching sign-in, and the
password change), and 70 of 70 pass on this head.
- Ablations, one at a time through `scripts/ablation-replace.mjs`. The
subject resolves from `src/`, so no rebuild is involved. Each mutation
landed by anchor count and blob hash, and was restored with the blob
equal to HEAD and `git diff HEAD` empty.
- session-creation check removed: 35 of 70 fail, among them the
backup-code, OTP, device-grant, identity-provider and address-change
pins; restored, green.
- phone-door gate removed: 4 fail; restored, green.
- phone-door settlement removed: 3 fail; restored, green.
- password-door verdict check replaced by an admit: 3 fail (the two
no-verdict pins and the unit pin); restored, green.
- outside-any-request exemption widened to admit: 1 fails; restored,
green.
- impersonation mark accepted without a session of record: 1 fails;
restored, green.
- the request's own view of its session accepted as the holder: 1 fails;
restored, green.
- the session-of-record read removed: 4 fail (impersonation, the
administrator's rotation, the password change, in both runtimes);
restored, green.
- the recorded path ignored where no endpoint context reaches the hook:
3 fail; restored, green.
- Dogfood battery, `pnpm --filter @objectstack/dogfood test` under the
verify lock on 4d27b2c: VERDICT command-exit 0, Test Files 467
passed, 3 skipped (470), Tests 3962 passed, 42 skipped (4004), no
failure.
</details>
## Acceptance notes
- The ID-token sign-in and the enterprise SSO callbacks have no pin of
their own. They end in the same session write, and the identity-provider
callback pin covers the shared callback path. Pinning them needs a
signed ID token against a provider key set, and a registered SSO
provider with discovery, which is more than this change carries.
- Where a password door's session is refused at session creation instead
of by its gate (no gate verdict recorded), the answer and the
`login_failed` reason are the general ones, not always that door's own.
Accepted: that path is reached only when the gate did not record a
verdict.
- The session-of-record read takes the bearer credential before the
session cookie, which is not the vendor's order in every case. Where
they differ, the exemption is not established and the check fails
closed. Accepted.
- `check:skill-examples` and `check:dual-build-cjs-loads` answered
PREREQUISITE NOT MET locally (exit 3; they read client package builds
this worktree does not hold), and `check:type-check-debt` exited 3 under
shared-box load. All three are NOT MEASURED here and are read from CI.
## Verification
`node scripts/pm/dispatch-gates.mjs --commands` derived 108 families for
4d27b2c, and all were run locally. The `--ran` reconciliation with
recorded exit codes: 108 accounted, 105 exit 0, 3 NOT MEASURED (named
above), 0 unrun. The seat reads the CI check-runs.
---
_Generated by [Claude
Code](https://claude.ai/code/session_017xRBcT1w3zpekijraHJE4f)_
<!-- signed: security#1 · sunhaolin · session_017xRBcT1w3zpekijraHJE4f
-->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent b17c602 commit e735892
11 files changed
Lines changed: 1361 additions & 45 deletions
File tree
- .changeset
- content/docs
- kernel/runtime-services
- permissions
- packages
- plugins/plugin-auth/src
- runtime/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 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
50 | | - | |
51 | | - | |
52 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
53 | 56 | | |
54 | 57 | | |
55 | 58 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
633 | 633 | | |
634 | 634 | | |
635 | 635 | | |
| 636 | + | |
| 637 | + | |
| 638 | + | |
| 639 | + | |
| 640 | + | |
| 641 | + | |
| 642 | + | |
636 | 643 | | |
637 | 644 | | |
638 | 645 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
46 | | - | |
| 46 | + | |
| 47 | + | |
47 | 48 | | |
48 | 49 | | |
49 | 50 | | |
| |||
235 | 236 | | |
236 | 237 | | |
237 | 238 | | |
| 239 | + | |
238 | 240 | | |
239 | 241 | | |
240 | 242 | | |
| |||
243 | 245 | | |
244 | 246 | | |
245 | 247 | | |
246 | | - | |
247 | | - | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
248 | 251 | | |
249 | 252 | | |
250 | 253 | | |
| |||
260 | 263 | | |
261 | 264 | | |
262 | 265 | | |
| 266 | + | |
263 | 267 | | |
264 | 268 | | |
265 | 269 | | |
266 | 270 | | |
267 | 271 | | |
268 | 272 | | |
269 | | - | |
270 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
271 | 277 | | |
272 | 278 | | |
273 | 279 | | |
| |||
297 | 303 | | |
298 | 304 | | |
299 | 305 | | |
300 | | - | |
301 | | - | |
302 | | - | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
303 | 312 | | |
304 | 313 | | |
305 | 314 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
| 23 | + | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
65 | | - | |
| 65 | + | |
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| |||
215 | 215 | | |
216 | 216 | | |
217 | 217 | | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
218 | 228 | | |
219 | 229 | | |
220 | 230 | | |
| |||
859 | 869 | | |
860 | 870 | | |
861 | 871 | | |
| 872 | + | |
862 | 873 | | |
863 | 874 | | |
864 | 875 | | |
865 | | - | |
866 | | - | |
867 | | - | |
868 | | - | |
869 | | - | |
870 | | - | |
871 | | - | |
872 | | - | |
| 876 | + | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
873 | 884 | | |
874 | 885 | | |
875 | 886 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| 67 | + | |
67 | 68 | | |
68 | 69 | | |
69 | 70 | | |
| |||
362 | 363 | | |
363 | 364 | | |
364 | 365 | | |
| 366 | + | |
365 | 367 | | |
366 | 368 | | |
367 | 369 | | |
368 | 370 | | |
369 | 371 | | |
370 | 372 | | |
371 | | - | |
| 373 | + | |
372 | 374 | | |
373 | 375 | | |
374 | 376 | | |
375 | 377 | | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
376 | 382 | | |
377 | 383 | | |
378 | 384 | | |
| |||
0 commit comments