Skip to content

Commit e735892

Browse files
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
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
'@objectstack/plugin-auth': patch
3+
'@objectstack/runtime': patch
4+
---
5+
6+
fix(plugin-auth)!: a locked account is refused on every door that ends in a session for it
7+
8+
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. No request, response or metadata shape is added, removed or re-shaped; an unlocked account, an expired lock and a deployment with the lockout off sign in exactly as before.
9+
Metadata-protocol: none
10+
11+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped, and no export or type changes. What moves is which answer a locked account gets at the sign-in doors, the existing lockout refusal, so there is nothing for a migration to rewrite and no tombstone. -->
12+
13+
**BREAKING** sign-in narrowing for locked accounts (`@objectstack/plugin-auth`): a locked account is refused on every door that ends in a session for it, with the answer password sign-in gives.
14+
15+
- **Now.** While the lock holds, every door that ends in a new session for the account issues none and answers as `POST /sign-in/email` does: `403 ACCOUNT_LOCKED` under `lockoutRefusal: 'explicit'`, `401 INVALID_EMAIL_OR_PASSWORD` otherwise. That is `POST /phone-number/verify`; `GET /magic-link/verify` (JSON and `callbackURL` lanes); `GET /verify-email` when it signs the caller in, an address-change confirmation opened without a session included; the second-factor step (`/two-factor/verify-totp`, `/two-factor/verify-otp`, `/two-factor/verify-backup-code`); sign-in through an identity provider (social and generic-OAuth callbacks and the ID-token sign-in, enterprise SSO over OIDC and SAML); and the device grant (`POST /device/token`). `POST /sign-in/phone-number` checks the lock before the password and answers a locked account the same whatever password it is sent: `403 ACCOUNT_LOCKED` under `'explicit'`, that door's own wrong-password answer (`401 INVALID_PHONE_NUMBER_OR_PASSWORD`) otherwise. Its wrong passwords count toward the account's one lock and a correct one resets the count, as at `/sign-in/email`. Each refused attempt writes its `login_failed` row with the reason `ACCOUNT_LOCKED`. Not sign-ins, and unchanged: an administrator's impersonation, 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), and the server's in-process principal session. A session for a locked account made any other way is refused.
16+
- **Who moves.** A client that signs an account in through a one-time code, a sign-in link, an address-change confirmation without a session, the second-factor step, an identity provider, the device grant or the phone-number password door: while the account is locked it now receives the lockout refusal. That includes accounts with no password at all, which the lock now reaches on doors that never asked for one, and phone-number password failures now lock the account after `lockoutThreshold` attempts. An administrator clears a lock early with the **Unlock** action, as before.
17+
18+
`@objectstack/runtime`: the dispatcher error-vocabulary ledger classifies the `INVALID_EMAIL_OR_PASSWORD` stamp in `@objectstack/plugin-auth` as better-auth's own vocabulary; no behaviour changes.

‎content/docs/kernel/runtime-services/audit-service.mdx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,12 @@ services.audit.recordAuthEvent(event: {
4747
- `login` / `logout` are **session events**: a sign-in that minted a session, and a
4848
sign-out.
4949
- `login_failed` / `account_locked` are **account events**: a refused sign-in — a
50-
password sign-in that named an existing account, or any `/sign-in/*` request the IP
51-
allow-list refused (ADR-0069 D5) — and the refused sign-in that stamped the account
52-
lockout (`lockoutThreshold`, ADR-0069 D2). They exist without any session.
50+
password sign-in (email or phone number) that named an existing account, a sign-in
51+
the account lockout refused at any other door that ends in a session (a one-time
52+
code, a sign-in link, the second-factor step, an identity provider's callback, the
53+
device grant; `reason: 'ACCOUNT_LOCKED'`), or any `/sign-in/*` request the IP
54+
allow-list refused (ADR-0069 D5) — and the refused password sign-in that stamped the
55+
account lockout (`lockoutThreshold`, ADR-0069 D2). They exist without any session.
5356
- **`userId`** must be a real `sys_user` id when given — it lands on the strict `user_id`
5457
lookup. On an account event it is the account the sign-in named. Every event names one
5558
except a `login_failed` refused before any account could be resolved: the deployment's

‎content/docs/permissions/authentication.mdx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,13 @@ credential check resolves the address to. So every refused sign-in on that accou
633633
counts toward its one lock, whichever spelling of the address it used. A lock refuses
634634
every sign-in that resolves to the account, the correct password included, and a
635635
successful sign-in under any spelling clears the counter.
636+
Every password sign-in door (email and password, phone number and password) counts
637+
toward that one lock and checks it before the password, and a locked account is
638+
refused, with the answer password sign-in gives, on every door that ends in a session
639+
for it: one-time codes, sign-in links, an address-change confirmation opened without a
640+
session, the second-factor step, sign-in through an identity provider (social, generic
641+
OAuth, enterprise SSO) and the device grant, so the lock also reaches an account that
642+
has no password.
636643

637644
Setting `lockout_threshold` to `0` disables the **password-stage** lockout only.
638645
Two-factor verification keeps a built-in limit of 10 attempts per 15 minutes,

‎packages/plugins/plugin-auth/src/auth-manager-after-hook.ts‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
import { codeSelfServiceRefusal } from './account-self-service-refusal-code.js';
4444
import { BANNED_USER_CODE, causeBannedUserRefusal } from './banned-user-refusal-cause.js';
4545
import type { AuthManager } from './auth-manager.js';
46-
import { refusalCodeOf, SIGN_IN_EMAIL_PATH } from './auth-session-audit.js';
46+
import { refusalCodeOf } from './auth-session-audit.js';
47+
import { passwordSignInDoorOf } from './auth-manager-sign-in-lockout.js';
4748
import { narrowDirectoryForExternalCaller } from './external-directory-door.js';
4849
import { SESSION_SCOPING_REFUSAL } from './organization-access-policy.js';
4950
import { refuseIntrospectionForBannedSubject } from './oauth-token-read-ban-refusal.js';
@@ -235,6 +236,7 @@ export async function globalAfterHook(this: AfterHookHost, ctx: any) {
235236
if (ctx?.path === '/sso/register' || ctx?.path === '/sso/update-provider') await this.settleSsoSignOutOfIdp(ctx);
236237

237238
// ── ADR-0069 D2: account lockout (counter) ──────────────────
239+
// On every password door (`/sign-in/email`, `/sign-in/phone-number`).
238240
// better-auth catches an INVALID_EMAIL_OR_PASSWORD APIError and runs
239241
// the after-hook with it on `ctx.context.returned`; a success leaves
240242
// the session payload there. The gate stamped this attempt as a
@@ -243,8 +245,9 @@ export async function globalAfterHook(this: AfterHookHost, ctx: any) {
243245
// names is neither: the password passed and a policy then refused the
244246
// sign-in, so the stamp is handed back and the counter is left as it
245247
// stood. Its `login_failed` row is still written below.
246-
if (ctx?.path === SIGN_IN_EMAIL_PATH) {
247-
const email = typeof ctx?.body?.email === 'string' ? ctx.body.email : '';
248+
const passwordDoor = passwordSignInDoorOf(ctx);
249+
if (passwordDoor) {
250+
const { door, identifier: email } = passwordDoor;
248251
if (email) {
249252
let succeeded = true;
250253
try {
@@ -260,14 +263,17 @@ export async function globalAfterHook(this: AfterHookHost, ctx: any) {
260263
: await refusedAfterTheCredential(ctx?.context?.returned)
261264
? 'refused-after-credential'
262265
: 'refused',
266+
door,
263267
);
264268
// A refused sign-in writes `login_failed`, and the one that
265269
// stamped the lockout also writes `account_locked`. A successful
266270
// one is recorded as `login` by the session hook, unchanged. A
267271
// sign-in refused because the account is locked had its row
268272
// written by the gate, with the lock as its reason.
269-
if (!succeeded && !settlement.refusedByLock) await this.auditRefusedSignIn(ctx, email, settlement);
270-
if (succeeded) {
273+
if (!succeeded && !settlement.refusedByLock) await this.auditRefusedSignIn(ctx, email, settlement, door);
274+
// The session controls and the last-login stamp below are the email
275+
// door's, as before.
276+
if (succeeded && door === 'email') {
271277
const uid = ctx?.context?.returned?.user?.id;
272278
// [ADR-0069 TL;DR 6] The cap of the organization the new session
273279
// was scoped to at creation (ADR-0093 D9), never above the
@@ -297,9 +303,12 @@ export async function globalAfterHook(this: AfterHookHost, ctx: any) {
297303
// `details.cause: 'scim_deactivated'`; an administrator's ban is
298304
// answered as before. See `banned-user-refusal-cause.ts`. It throws
299305
// on a match, so it stays after the settlement and the refusal's
300-
// `login_failed` row above.
301-
await causeBannedUserRefusal(ctx);
302-
return;
306+
// `login_failed` row above. The phone door goes on to the hooks below,
307+
// as before.
308+
if (door === 'email') {
309+
await causeBannedUserRefusal(ctx);
310+
return;
311+
}
303312
}
304313

305314
// ── ADR-0069 D1: on a successful change/reset — stamp

‎packages/plugins/plugin-auth/src/auth-manager-before-hook.ts‎

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
* the same cloud-as-IdP authorization gate, the same break-glass
2121
* last-local-credential refusal, the same audience posture and uniqueness
2222
* refusal on password sign-up, the same cloud-managed invite-member refusal,
23-
* the same account lockout gate, and the same first-user `disableSignUp` flip
24-
* — in the same order.
23+
* the same account lockout gate (on every password door), and the same
24+
* first-user `disableSignUp` flip — in the same order.
2525
*
2626
* ## How the moved body reaches the class
2727
*
@@ -62,7 +62,7 @@ import { isCloudManaged } from '@objectstack/core';
6262
import { VENDOR_ROLE_SCALAR_ADMIN_PATHS } from './admin-impersonate-endpoint.js';
6363
import { setAuthActorResolver } from './auth-actor-attribution.js';
6464
import { AuthManager } from './auth-manager.js';
65-
import { SIGN_IN_EMAIL_PATH } from './auth-session-audit.js';
65+
import { passwordSignInDoorOf, recordLockoutRequest } from './auth-manager-sign-in-lockout.js';
6666
import { CLOUD_MANAGED_REFUSAL_CODE, CLOUD_MANAGED_REFUSAL_MESSAGES } from './cloud-managed.js';
6767
import {
6868
isLastLocalCredentialHolder,
@@ -215,6 +215,16 @@ export async function globalBeforeHook(
215215
// states the rule and how each credential is read.
216216
await refuseRequestNamingDifferentAccounts(ctx);
217217

218+
// ── ADR-0069 D2: what this request is, for the lock at session creation ──
219+
// Its path, and the session of record it presents, read from the store
220+
// before the endpoint runs (and before it can replace that row), so the
221+
// lock's refusal at session creation tells a sign-in from a new session for
222+
// an account the caller is already signed in as by the session of record,
223+
// never by the request's own view of it, and judges the same request where
224+
// the endpoint context does not reach the database hooks. Lockout on only;
225+
// see `auth-manager-sign-in-lockout.ts`.
226+
await recordLockoutRequest.call(this, ctx);
227+
218228
// ── [#33203] Cloud-managed: no reset door sets a local password ──
219229
// A hosted environment sets no local password for anyone, a platform
220230
// administrator included (ruling 10 of cloud#4465, `cloud-managed.ts`).
@@ -859,17 +869,18 @@ export async function globalBeforeHook(
859869
});
860870

861871
// ── ADR-0069 D2: account lockout (gate) ─────────────────────
872+
// On every password door (`/sign-in/email`, `/sign-in/phone-number`),
862873
// BEFORE better-auth checks the password: the attempt is stamped as a
863874
// failure (settled by the after-hook once the check answers), and a
864875
// locked identity is refused — a lock must hold even against the
865-
// correct password. The refusal is the one a wrong password gets, made
866-
// by better-auth's own credential check (`sign-in-lockout-refusal.ts`),
867-
// unless the deployment opted into `403 ACCOUNT_LOCKED`. It is a
868-
// refused sign-in, so it writes its `login_failed` row
869-
// (`auth-session-audit.ts`, account events).
870-
if (ctx?.path === SIGN_IN_EMAIL_PATH) {
871-
const email = typeof ctx?.body?.email === 'string' ? ctx.body.email : '';
872-
if (email) await this.admitSignInAttempt(email, ctx);
876+
// correct password. The refusal is the one a wrong password gets at that
877+
// door, made by better-auth's own credential check
878+
// (`sign-in-lockout-refusal.ts`), unless the deployment opted into `403
879+
// ACCOUNT_LOCKED`. It is a refused sign-in, so it writes its
880+
// `login_failed` row (`auth-session-audit.ts`, account events).
881+
const passwordDoor = passwordSignInDoorOf(ctx);
882+
if (passwordDoor) {
883+
if (passwordDoor.identifier) await this.admitSignInAttempt(passwordDoor.identifier, ctx, passwordDoor.door);
873884
return;
874885
}
875886

‎packages/plugins/plugin-auth/src/auth-manager-database-hooks.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import { readRequestClientAddress } from './request-client-address.js';
6464
import { SESSION_SCOPING_REFUSAL } from './organization-access-policy.js';
6565
import { readSessionUserRow, refuseAgentAccountCredential } from './service-account-identity.js';
6666
import { refuseInactiveUserSession, SESSION_ADMISSION_ROW_FIELDS } from './user-session-admission.js';
67+
import { LOCKED_ACCOUNT_ROW_FIELDS, refuseLockedAccountSession } from './auth-manager-sign-in-lockout.js';
6768
import { PLATFORM_IDP_PROVIDER_ID } from './implicit-account-linking.js';
6869
import { PENDING_SSO_SOURCE } from './pending-sso-marker.js';
6970

@@ -362,17 +363,22 @@ export function composeDatabaseHooks(
362363
// before the host's hook and every step below, so no sign-in method,
363364
// impersonation or minted session gets a session for one, whatever runs
364365
// after it. See service-account-identity.ts.
366+
const SESSION_USER_ROW_FIELDS = [...SESSION_ADMISSION_ROW_FIELDS, ...LOCKED_ACCOUNT_ROW_FIELDS];
365367
const sessionBefore = async (session: any, ctx: any) => {
366368
// [#33181] The same one read of the row carries the columns the next
367369
// refusal judges: a pending person holds no session but the platform
368370
// sign-in's, and a ban holds on a kernel without the vendor admin plugin
369371
// (whose own hook enforces it where it is mounted). See
370372
// user-session-admission.ts.
371-
const userRow = await readSessionUserRow(this.config.dataEngine, session, SESSION_ADMISSION_ROW_FIELDS);
373+
const userRow = await readSessionUserRow(this.config.dataEngine, session, SESSION_USER_ROW_FIELDS);
372374
await refuseInactiveUserSession(this.config.dataEngine, session, {
373375
row: userRow,
374376
enforceBan: async () => !(await this.isAdminPluginMounted()),
375377
});
378+
// ADR-0069 D2: a locked account is refused on every door that ends in a
379+
// session for that account, with the answer password sign-in gives. See
380+
// auth-manager-sign-in-lockout.ts.
381+
await refuseLockedAccountSession.call(this, session, ctx, userRow);
376382
const captured = await captureSessionAddress(session);
377383
const result = sessionActiveOrgBefore ? await sessionActiveOrgBefore(captured, ctx) : undefined;
378384
if (result === false) return false;

0 commit comments

Comments
 (0)