Repository navigation
fix(plugin-auth): answer a locked account like a wrong password, clear the lock on reset, count attempts atomically - #31419
Conversation
…ord, stamps before checking, reset clears it Claude-Session: https://claude.ai/code/session_01QUs3BtDNDGBRyYSpvMa9Qi Co-authored-by: Claude <noreply@anthropic.com>
…ent attempts and reset clearing the lock Claude-Session: https://claude.ai/code/session_01QUs3BtDNDGBRyYSpvMa9Qi Co-authored-by: Claude <noreply@anthropic.com>
…et (en, zh-Hans, zh-Hant, ja) Claude-Session: https://claude.ai/code/session_01QUs3BtDNDGBRyYSpvMa9Qi Co-authored-by: Claude <noreply@anthropic.com>
…e shrunk test-typecheck debt; add the changeset Claude-Session: https://claude.ai/code/session_01QUs3BtDNDGBRyYSpvMa9Qi Co-authored-by: Claude <noreply@anthropic.com>
…for the lockout counter; regenerate the tenant-audit census The lockout module's sys_user writes go through two helpers whose engine is typed, so two sites now read as a typed receiver rather than an erased one. The census page is regenerated with tenant-audit-census --write and its two hand-written erased-receiver figures follow (64 to 62). Claude-Session: https://claude.ai/code/session_01QUs3BtDNDGBRyYSpvMa9Qi Co-authored-by: Claude <noreply@anthropic.com>
…03 ACCOUNT_LOCKED and reported better-auth opens a request state for every endpoint call, so only a call outside its pipeline lacks one. There the verdict cannot reach the credential check, so the gate refuses with the registered explicit code and logs the degradation rather than stamping a code of its own. Claude-Session: https://claude.ai/code/session_01QUs3BtDNDGBRyYSpvMa9Qi Co-authored-by: Claude <noreply@anthropic.com>
…the engine's dispatch check; ratchet the engine-double ledger Claude-Session: https://claude.ai/code/session_01QUs3BtDNDGBRyYSpvMa9Qi Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QUs3BtDNDGBRyYSpvMa9Qi Co-authored-by: Claude <noreply@anthropic.com>
… one typed query Claude-Session: https://claude.ai/code/session_01QUs3BtDNDGBRyYSpvMa9Qi Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 1 package(s): 25 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 7 release-owned page(s) also affected — read-only, see AGENTS.md Documentation Guardrails. What this run could not see
Coarse fallback — 22 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin ea9ffdd4d06e6542fef79a4b6fb7861636b40735 && git checkout ea9ffdd4d06e6542fef79a4b6fb7861636b40735
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 216b18a6ccb47dc23d3fe9f6a8575daf54f25dd5 00c88e7ef8ddfbbdf7d27473501b2fd69ad1e408 && git checkout -B drift-repro 216b18a6ccb47dc23d3fe9f6a8575daf54f25dd5 && git merge --no-ff 00c88e7ef8ddfbbdf7d27473501b2fd69ad1e408
node scripts/docs-audit/affected-docs.mjs --json 216b18a6ccb47dc23d3fe9f6a8575daf54f25dd5
|
…nted and cleared, on the memory engine and ObjectQL + SqlDriver Claude-Session: https://claude.ai/code/session_01QUs3BtDNDGBRyYSpvMa9Qi Co-authored-by: Claude <noreply@anthropic.com>
…et in ar, de, es, fr, ko, pt-BR, ru Claude-Session: https://claude.ai/code/session_01QUs3BtDNDGBRyYSpvMa9Qi Co-authored-by: Claude <noreply@anthropic.com>
|
repo:cloud#3 · os-zhuang · session_01QUs3BvRcDHXqRU4TSVE4u6 Contract reviewServed-tier: Tier note: the face is a declared widening ( ① Derived judgments
② Semver level
③ Boundary flags
④ Design judgment
Implemented-by: VERDICT: PASS |
|
repo:cloud#3 · os-zhuang · session_01QUs3BvRcDHXqRU4TSVE4u6 ACCEPT · #28381 · head 席位核对
|
Requested by Sam · project thread
Closes #28381
Clause-②: yes (widening)
Metadata-protocol: none
维护者速读
403 ACCOUNT_LOCKED只有真实存在的账号才会出现,等于告诉任何人某个邮箱是否注册过;重置密码后锁还在,用户换了密码仍登不进;并发尝试能越过阈值。lockoutRefusal: 'explicit'即可;绕过 better-auth 端点管道的调用无法给出统一回答,会得到 403 并记一条降级日志。无数据迁移,回滚 = revert 本 PR。cloud 目前在两个平面上自行改写这个回答,本 PR 不动 cloud,改写由 cloud 在之后的 pin 轮次里撤掉。packages/plugins/plugin-auth/src/auth-manager-sign-in-lockout.ts(计数与上锁的原子写入、成功清零、密码通过后的拒绝退回计数)、packages/plugins/plugin-auth/src/sign-in-lockout-refusal.ts(锁定账号如何得到与密码错误相同的回答)、packages/plugins/plugin-auth/src/auth-manager-auth-instance.ts(重置清锁的接线)。pnpm --filter @objectstack/plugin-auth exec vitest run --maxWorkers=2 src/account-lockout-resolved-account.test.ts src/password-reset-ends-sessions.test.ts,预期两个文件全部通过。What changes
401 INVALID_EMAIL_OR_PASSWORD, with the same body and the same password-check cost a wrong password gets. The lock still holds against the correct password, and the account'slogin_failedaudit row still records the reasonACCOUNT_LOCKED. A deployment that wants the explicit answer sets the newAuthManagerOptions.lockoutRefusal: 'explicit'(default'uniform') and is answered403 ACCOUNT_LOCKEDas before. A sign-in that runs outside better-auth's endpoint pipeline cannot be answered uniformly; it is refused403 ACCOUNT_LOCKEDand logged as a degradation, so the lock still holds.failed_login_countandlocked_until, so the new password signs in at once. An incomplete reset clears nothing. The second factor's own lock is not cleared by a reset; the administrator's Unlock action still clears both.auth.login.errors.invalidCredentialsnow says repeated failures pause sign-in for a while and that resetting the password signs in right away, in all 11 console locales (en,zh-Hans,zh-Hant,ja,ar,de,es,fr,ko,pt-BR,ru), socheck:i18n-driftholds.Clause-② for the opt-in key.
lockoutRefusalis a new optional key onAuthManagerOptions, the constructor options of the published@objectstack/plugin-auth. It widens what that package accepts, so the line readsyes (widening). It is not a settings key and nothing inpackages/specchanges, soMetadata-protocolstaysnoneand the changeset ispatch.Tests
account-lockout-resolved-account.test.ts(real sign-in endpoint): a locked account answers exactly what a wrong password answers, the correct password included (status, body, and one password derivation each, counted with the scrypt testkit for an open account's wrong password, a locked account's correct and wrong password, and an unknown account); input refusals match too; a locked refusal opens no session and writes theACCOUNT_LOCKEDaudit row;lockoutRefusal: 'explicit'answers403 ACCOUNT_LOCKED; of 30 concurrent wrong passwords, exactly the threshold reach the password check, the rest meet the lock, oneaccount_lockedrow is written, and the lock then holds against the correct password.password-reset-ends-sessions.test.ts(real ObjectQL + sqlite): a reset by emailed link and by phone code each clear the lock and the new password signs in at once; an incomplete reset leaves the lock.auth-manager.test.ts: the lockout unit block, rewritten for the new gate (no-op at threshold 0, the uniform and explicit refusals, the refusal and its log line outside the pipeline, a locked attempt counted without moving its expiry, the compare-and-set write below and at the threshold, a re-read after a lost write, success clearing). Its fake engine now opensupdatewithassertEngineUpdateDispatch, so every write the block makes is one the real engine accepts.auth-account-event-audit.test.tsanddurability-swallow-repair.test.ts: updated to the uniform answer and the renamed gate.password-reset-ends-sessions.test.ts› "ADR-0069 D2: an account whose failed_login_count is NULL is counted and cleared through ObjectQL + SqlDriver" (better-sqlite3; the column is read back as NULL first) andaccount-lockout-resolved-account.test.ts› "ADR-0069 D2: an account whose failed_login_count is NULL or absent is counted and cleared like one at 0" (in-memory, NULL and absent): the correct password signs in and clears the counter to 0; a wrong password counts to 1 and the correct one still signs in after it. The compare-and-set matches a NULL counter on both engines, so no normalisation was needed. SqlDriver compiles every dialect through one filter compiler; only sqlite was run.Reverse verification: with the implementation committed, the plugin-auth source files were restored from
eff90af6and the two endpoint-level files run against them: 10 failed and 25 passed (the uniform answer under every spelling and input, the reset clearing in all three cases, and the concurrency pin).git checkout HEAD -- …restored the implementation, withgit diff HEADempty, and both files are green again.Acceptance notes
lockoutRefusalis read from the constructor options; there is no settings key and no UI for it.updatehonourswhere+multiand returns the row count; the reset pins run on real ObjectQL + sqlite.plugin-auth/**and the console copy. Three generated or ratchet files move with this diff, each written by its own tool:content/docs/permissions/tenant-audit-census.mdxanddocs/audits/2026-08-tenant-audit-write-call-sites.counts.md(node scripts/tenant-audit-census.mjs --write; twosys_userwrite sites now read as a typed engine receiver, so the page's two hand-written erased-receiver figures go from 64 to 62, with the total unchanged at 270), andscripts/engine-double-contract.pinned.json(check-engine-double-contract.mjs --write; one more pinned fake inauth-manager.test.ts). The seat agreed to the census page before it was written.auth-manager.test.ts;test-typecheck-debt.jsonwas re-recorded downward with the package's owngen:test-typecheck-debt.INVALID_EMAIL_OR_PASSWORDis better-auth's code and reaches the wire unregistered. Stamping it from plugin-auth would need a ledger row inpackages/spec, which this card does not touch, so the one path that would have stamped it (outside the endpoint pipeline) uses the registeredACCOUNT_LOCKEDinstead. Registering the code would let that path answer uniformly too; left for the seat to schedule.Closes #28381.Verification
The readings below were taken at head
42421e44. At head00c88e7e(NULL-counter tests and the 7 locale packs), under the lock: plugin-auth typecheck OK and 240/240 files, 4267 tests; ui i18n, console auth,check-i18n-call-site-keysandcheck-i18n-en-drift: 115/115 files, 2094 tests; the changeset, engine-double, NUL and i18n-drift gates green. Wall-clock figures come from a shared box.plugin-auth build, typecheck and full suite; console copy tests
bash scripts/pm/os-verify-lock.sh -c 'pnpm --filter @objectstack/plugin-auth build && pnpm --filter @objectstack/plugin-auth typecheck && pnpm --filter @objectstack/plugin-auth exec vitest run --maxWorkers=2 && cd ui && npx vitest run --maxWorkers=2 packages/i18n/ packages/app-shell/src/console/auth/ scripts/__tests__/check-i18n-call-site-keys.test.ts --testTimeout=120000'Derived gates
node scripts/pm/dispatch-gates.mjs --commandsderived 116 commands for this change set. They ran with 4 more whose rosters sit beside touched paths (check:changeset-fixed,check:error-code-casing,check:filter-alias-parity,check:error-status-conformance), and each exit code was captured before any pipe.pnpm --dir ui exec vitest run scripts/exited 1 because four tests incheck-i18n-call-site-keys.test.tsandcheck-vi-mock-specifiers.test.tseach hit "Test timed out in 15000ms" while three gates ran at once. Run under the lock with--testTimeout=180000, those two files pass 187/187.node scripts/pm/dispatch-gates.mjs --ran: 116 derived families accounted for, 0 not measured.node scripts/check-nul-bytes.mjs: OK.Five gates needed a change on this branch.
check:test-typecheck: debt re-recorded downward.check:tenant-audit-census: page regenerated.check:engine-double-contract: the ledger records one more pinned fake.check:dispatcher-error-vocabularyandcheck:query-options-erasure: code fixed, no ledger touched.Generated by Claude Code
🤖 Generated with Claude Code
https://claude.ai/code/session_01QUs3BtDNDGBRyYSpvMa9Qi