Repository navigation
fix(plugin-auth): an MFA-held sign-in records the hold on its own login row - #30950
Conversation
…in row A sign-in that ADR-0069 D3 enforced MFA holds is not a refused one: the credential check passes, the session is minted and the user can still reach /two-factor/* to enroll. Its login row now records the hold as context.reason (MFA_REQUIRED) and context.rule (mfa_required), asked once in session.create.after of the same posture computation the session gate asks (resolveUserAuthGates), never per session read. Claude-Session: https://claude.ai/code/session_016WV4cwTfQ1ifwQY2EUnSUt Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016WV4cwTfQ1ifwQY2EUnSUt Co-authored-by: Claude <noreply@anthropic.com>
…al boot Claude-Session: https://claude.ai/code/session_016WV4cwTfQ1ifwQY2EUnSUt Co-authored-by: Claude <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016WV4cwTfQ1ifwQY2EUnSUt Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 1 package(s): 24 hand-written doc(s) name something this change touched — list omitted above 15 rows. Re-derive on the tree named below: ⛔ 6 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 88191d36c6e44f3797e608d175fb8ba689625577 && git checkout 88191d36c6e44f3797e608d175fb8ba689625577
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 616311c126bc66879f04dc997700a0d09d9613c1 60164041c04b1e5f9d0c3a6e2a5f34134b9cbef1 && git checkout -B drift-repro 616311c126bc66879f04dc997700a0d09d9613c1 && git merge --no-ff 60164041c04b1e5f9d0c3a6e2a5f34134b9cbef1
node scripts/docs-audit/affected-docs.mjs --json 616311c126bc66879f04dc997700a0d09d9613c1
|
|
domain:server#3 · os-elon-musk · session_016WV4cytQjG9X1CrCgytUM5 ACCEPT · #30924 PR1 · 2026-11-06T14:11Z · Head-sha: 席位核对
|
Requested by Elon · project thread
domain:server#3 · os-elon-musk · session_016WV4cwTfQ1ifwQY2EUnSUt
Refs #30924
Clause-②: no
Metadata-protocol: none
维护者速读
login审计记录现在会写上reason: MFA_REQUIRED、rule: mfa_required。login记录也已经写了,所以挂起记在这条记录上,不另写一条互相矛盾的login_failed。session-policy-hold.ts(要记哪些挂起、模拟登录的会话怎么判);②auth-manager-database-hooks.ts的sessionCreateAfter;③auth-manager.ts增补的两行(席位批准)。pnpm --filter @objectstack/plugin-auth exec vitest run src/auth-account-event-audit.test.ts,预期[#30924]那组 4 个用例全绿。What changes
A sign-in held by ADR-0069 D3 enforced MFA now records the hold on its own
loginrow. The condition: the requirement is on, the account never enrolled, and its grace window has lapsed. The row'smetadatagainsreason: "MFA_REQUIRED"(the posture's machine code, the same vocabulary a refused sign-in'sreasonuses) andrule: "mfa_required"(the policy's name), besideendpoint.session.create.after(auth-manager-database-hooks.ts), the hook that already writes theloginrow, once per session created. It asks the same posture computation the session gate asks:AuthManager.resolveUserAuthGates, for the session's user in the session's active organization.session-policy-hold.tsfollows the splitcomputeAuthGatemakes. Every posture holds a session the user signed in to themselves; only anaccount-scope posture holds an impersonation session.AUDITED_SESSION_HOLD_RULES, which today is justMFA_REQUIRED→mfa_required. Adding another posture is one more entry. A user held by both the forced reset and MFA has the MFA hold recorded.login,logout,login_failedandaccount_lockedrow. None of them carries the attempted credential.session-policy-hold.tsis package-internal, andloginEventFor's signature is unchanged, so the published surface ofauth-session-audit.tsdoes not move (Clause-②: no).Why the
loginrow, not alogin_failed(seat ruling, fork 2 option B). Measured onorigin/main0e882086, an MFA-held/sign-in/emailanswers 200 with a session token and writes aloginrow. The hold is computed on every session read:resolveUserAuthGatesran 0 times during the sign-in and once for each of 3get-sessioncalls. So:login_failedbeside theloginwould contradict it, and a brute-force reader countinglogin_failedwould count users who are signed in;For the cloud#3668 consumer:
loginrow:action = 'login',metadata.reason = 'MFA_REQUIRED',metadata.rule = 'mfa_required', withuser_id,tenant_id,ip_address,user_agentandcreated_at.login_failedrows withmetadata.rule = 'ip_allow_list'. They arrive in PR 2 of this series.Seat-approved surface addendum: in
auth-manager.ts, only thecomposeDatabaseHookshost literal changes. One member joins theDatabaseHooksHostPick union and one forwarding closure is added forresolveUserAuthGates. Nothing else in the file is touched.Overlap with #30922: that card's WIP commit
15ec27e3onclaude/issue-30922-per-org-access-policyaddsjudgeSessionScopingto the same Pick union line, plus a closure besidelinkingContext, inauth-manager.ts. It does the same in theDatabaseHooksHostinterface and thecomposeDatabaseHooksthisPick inauth-manager-database-hooks.ts. Whichever PR lands second gets a one-line textual conflict, and the resolution keeps both members.Changeset:
'@objectstack/plugin-auth': patch.Why
#30924: plugin-auth writes no audit row when policy holds or refuses a sign-in, so the Enterprise enforcement report (cloud#3668) has nothing to read. This is PR 1 of the two-PR series in the card's Claim. PR 2 carries the IP allow-list rows: the deployment gate and #30922's per-organization refusal. It also carries the plugin-audit change that admits a row with no resolvable account, and the flood bound. PR 2 opens after #30922 merges.
Tests
auth-session-audit.test.ts, new top-level describe, at the composition seam (the realcomposeDatabaseHooks, with the posture answer stubbed on the manager):reason+rule, and the posture is asked once with('usr_1', { organizationId: 'org_1' });impersonated_byandactor;auth-account-event-audit.test.ts, new top-level describe, on a realAuthManagerover the in-memory engine and real better-auth:loginevent carrying the hold, no account event, and no password material;get-sessionreads, each answeredauthGate: MFA_REQUIRED, still leave exactly one event;login_failedwithINVALID_EMAIL_OR_PASSWORDand no hold.auth-session-audit-trail.dogfood.test.ts, new top-level describe on a booted showcase withAuditPlugin.auth.mfa_requiredis turned on through the settings service and the account's grace is lapsed. Then:get-sessionanswersMFA_REQUIRED;loginrow insys_audit_lognames the hold (metadatahasendpoint,reason,rule), with nologin_failedand no credential anywhere in the member's rows.Acceptance notes
resolveUserAuthGatessees an organization's ownrequire_mfathrough the lazily refreshed "does any org require MFA" cache. The session gate reads the same cache. A sign-in in the moment after boot, before the first refresh lands, records no hold for a per-org requirement, exactly as the gate does not hold that first read. The global requirement has no such window.AUDITED_SESSION_HOLD_RULES; acredential-scope entry would then be skipped on impersonation sessions by the scope filter already in place.Verification
All readings on head
60164041(merge base4d56914aonmain), in this checkout.auth-session-audit.test.ts+auth-account-event-audit.test.ts→ 45 passed (45).scripts/ablation-replace.mjs,withSessionPolicyHold(login, hold)→logininsessionCreateAfter): 4 failed | 41 passed. The 4 are the MFA-held, reset+MFA, impersonation and real-sign-in cases; every control stayed green. Restored, blob back, tree clean.auth-session-audit-trail.dogfood.test.ts→ 6 passed (6). Same ablation, rebuilt, withablation-dist-preflight.mjs --absentproving the marker leftdist/: the#30924case failed (1 failed | 5 skipped under-t 30924). Restored, rebuilt, marker back indist/,git status --porcelainempty.@objectstack/plugin-authfull suite 228 files, 4108 passed | 10 skipped.@objectstack/plugin-auditauth-event-audit.test.ts17 passed (17).@objectstack/plugin-authtypecheck (source + tests) exit 0.eslint --no-inline-configon the 7 changed source and test files exit 0.os-verify-lock,turbo run build→ 119 successful, 119 total.scripts/pm/dispatch-gates.mjs --ran→ 67 derived, 67 run, 0 NOT-MEASURED; all 67 exit 0. These includecheck:auth-mount-ledger,check:tenant-audit-census,check:durability-log-level,check:dts-closure,check:published-files,check:issue-citationsand the changeset gates.Human Minimum
packages/specholds no runtime logic. (No spec change.)pnpm lintpasses. (CI owns the repo-wide lint run.)main, one pull request (PR 1 of the claimed two-PR series).packages/spectouched: not touched.content/docs/references/,packages/*/CHANGELOG.mdorcontent/docs/releases/.Generated by Claude Code