Repository navigation
fix(plugin-auth): audit the forced-reset flag and its clear under the person who caused them - #31820
Conversation
… person who caused them The administrator's set-user-password and the user's own change-password each write sys_user.must_change_password as the system, with no caller on the attribution seam, so plugin-audit recorded both rows with a null actor and user_id. Both writes now build their context with authSystemWriteContext(): the forced reset opens the seam with the admitted administrator, and the change-password stamp is credited to the account's own holder when the request's session names them. Authorization is unchanged: both writes still run as the system. Claude-Session: https://claude.ai/code/session_01ADHkmShTSNgBjG5FV5GMXD Co-authored-by: Claude <noreply@anthropic.com>
… route scope Claude-Session: https://claude.ai/code/session_01ADHkmShTSNgBjG5FV5GMXD Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift Check3 anchor(s) derived from 1 changed package(s); no hand-written page names any of them, so this run has nothing to list — not a clean bill of health. This check sees only pages that NAME a derived anchor: one that documents this change in prose, or enumerates it in an authoring dialect, names none and stays invisible to it on every run. 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 90588cdb49186e42c9b8c4ff2a1b617b5fa64112 && git checkout 90588cdb49186e42c9b8c4ff2a1b617b5fa64112
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 6be71abc34cdd7adcc6057d121479ba5a11724e3 d47e8cd691a93c314b43c1ec1d079460dddd2a2e && git checkout -B drift-repro 6be71abc34cdd7adcc6057d121479ba5a11724e3 && git merge --no-ff d47e8cd691a93c314b43c1ec1d079460dddd2a2e
node scripts/docs-audit/affected-docs.mjs --json 6be71abc34cdd7adcc6057d121479ba5a11724e3 |
|
domain:server#3 · os-steve · session_01ADHkmQXLfvyB5R53VDm3Ka 席位核对 · ACCEPT · #31820 (Fixes #31804) · 2026-11-09T05:53ZHead-sha:
|
Requested by Steve · project thread
Fixes #31804
Clause-②: no. Only the audit row's content changes: no route, option or field. Measured on base 5b7269f and head: both doors answer the same status and body and write the same values (CONTROL pins below).
Metadata-protocol: none
domain:server#3· dev sessionsession_01ADHkmShTSNgBjG5FV5GMXD维护者速读
/auth/admin/set-user-password)写must_change_password=true、用户自己改密码(/auth/change-password)写must_change_password=false,这两次写入现在带上调用者,sys_audit_log的actor和user_id分别记管理员和用户本人(模拟登录时另记impersonated_by)。actor、user_id都是空,看不出是谁改的密码状态。create-user)的同一次写入也会记到管理员名下。回滚即还原本 PR。admin-user-endpoints.ts的stampMustChangePassword与runAdminSetUserPassword里的runAttributedToUser;auth-manager-password-session-policy.ts的stampPasswordChangedAt。pnpm --filter @objectstack/plugin-auth exec vitest run --maxWorkers=2 src/password-reset-ends-sessions.test.ts -t 'a password-state write',预期 4 条全绿。What changes
Step 0, on
origin/main5b7269f. A scratch probe (not committed) drove both doors over a realObjectQLon better-sqlite3 with plugin-audit's realinstallAuditWritersand read thesys_audit_logrows for the user. The card's reading reproduces onmain:actoruser_idmust_change_passwordfalse → truelast_login_at(sign-in stamp)password_changed_at+must_change_passwordtrue → falseThe same probe on this head: the set row names the administrator (
actor=user_id= the admin), the clear row names the user, the sign-in stamp row and the sign-up stamp row are unchanged.How #30989 carried identity into the audit writer (the mechanism this PR reuses; no second one):
auth-manager-request-routing.tsrunWithAuthActorScopearoundauth.handler; a framework route opens it itself withrunAttributedToUser(actor, …)AsyncLocalStoragescope per requestauth-manager-before-hook.tssetAuthActorResolver(the session's user andimpersonatedBy); SCIM: the verified connection (scimRequestConnectionId)auth-actor-attribution.tsauthSystemWriteContext()isSystem: trueplusattributedUserId/impersonatedBy/performedBy, oractor: svc:scim:…for SCIMbuildProvenance; plugin-auditaudit-writers.tsuser_id=session.userId ?? provenance.attributedUserId;actor= that, elsesession.actorBoth writes built their context as a bare
{ isSystem: true, positions: [], permissions: [] }, so nothing reached the attribution channel.admin-user-endpoints.ts):stampMustChangePasswordbuilds its context as{ ...SYSTEM_CTX, ...(await authSystemWriteContext()) }, andrunAdminSetUserPasswordruns the stamp insiderunAttributedToUser(actor, …)with the actor the route admitted (gateAdmin, which addsimpersonatedByfrom an impersonation session). Only the stamp is wrapped: the credential write and the revocation keep their contexts.auth-manager-password-session-policy.tsstampPasswordChangedAt): the context is{ ...SYSTEM_CTX, ...attribution }when the seam'sattributedUserIdis the stamped account itself, else the bare system context. On/change-passwordthe stamped account is the session's own (passwordChangeAfterEffectsAccount), so the clear names the user. The same stamp runs after/reset-passwordand/sign-up/email: the emailed-link reset carries no session and stays the system's, and a request whose session names another account never credits that account's holder.isSystem: true,positions: []andpermissions: []; the attribution keys are read by no security middleware (auth-actor-attribution.tsheader). No field-protection or read-only strip is crossed: the written fields and values are byte-identical.stampMustChangePasswordis also the create-user door's stamp, and that route already runs insiderunAttributedToUser(actor, …)(auth-plugin.ts), so the administrator-created user'smust_change_passwordset is now credited to the creating administrator too. Same defect class, same line, no other claim on the file, no new gate family; pinned below.Tests
New pins, in the existing harnesses (no new test file):
password-reset-ends-sessions.test.ts, top-leveldescribe('a password-state write names the person who caused it'), realObjectQL+ better-sqlite3 +AuthManager.handleRequest, observed on the raw engineupdate(the fix(plugin-auth,plugin-audit): a SCIM-driven write names the SCIM connection that performed it, on its audit row #30989 observation point,scim-transaction-scope.test.ts):must_change_password: truewrite carriesattributedUserId= the administrator,isSystem: true, nouserId; CONTROL: 200,data.mustChangePassword: true, the patch is exactly{ id, must_change_password: true }, the stored flag is set;impersonatedByrides beside the administrator;attributedUserId= the user; CONTROL: 200, patch keysid,must_change_password,password_changed_at, stored flag cleared; CONTROL: the sign-in stamp is the user's, as before;/reset-passwordstamp stays the system's.admin-user-endpoints.test.ts, top-leveldescribefor the create-user rider: inside the route's scope the stamp context is the system's plusattributedUserId; outside it, the bare system context.No existing test was changed.
Ablations (each mutation landed on disk, went red, restored: blob == HEAD, git diff HEAD empty)
node scripts/ablation-replace.mjs, tests importsrc(no dist leg):admin-user-endpoints.ts:context: { ...SYSTEM_CTX, ...(await authSystemWriteContext()) },→context: SYSTEM_CTX,— the forced-reset pin and the impersonation pin red (attributedUserId: "admin_password_state"expected,nullreceived;impersonatedBy: "admin_at_keyboard"expected,nullreceived); the create-user rider pin red on the same mutation.auth-manager-password-session-policy.ts: the attributed-context ternary → the bareSYSTEM_CTX— the change-password pin and the own-holder half of the negative pin red (attributedUserId= the user expected,nullreceived).attribution.attributedUserId === userId ?→attribution.attributedUserId !== undefined ?— the negative pin red (attributedUserId: nullexpected,"someone_else"received).A first attempt at (2) with the bare replacement
SYSTEM_CTXwas refused by the tool before running (the replacement text already occurs in the file) and ran nothing; it was re-run with a unique spelling.Acceptance notes
package.json, lockfile) or aCROSS_PACKAGE_TEST_INPUTS+turbo.jsonentry, both outside this card's file surface. The committed pins observe the engine context, as fix(plugin-auth,plugin-audit): a SCIM-driven write names the SCIM connection that performed it, on its audit row #30989's plugin-auth half does; plugin-audit'saudit-writers.test.tsalready pinsprovenance.attributedUserId→user_id/actor.Verification
All at head
d47e8cd6(base5b7269ff;origin/mainhas since moved by commits touching none ofplugin-auth,plugin-auditorobjectql, so no merge).pnpm --filter @objectstack/plugin-auth test— Test Files 246 passed (246), Tests 4411 passed | 10 skipped (4421); lock VERDICT command-exit 0.pnpm --filter @objectstack/plugin-auth typecheck(after a full closure build with declarations) — exit 0;check:test-typecheckOK, the ledger held (10 files / 72 errors / 23 signatures, unchanged).eslint --no-inline-config packages/plugins/plugin-auth(the package has nolintscript) — exit 0.vitest run src/password-reset-ends-sessions.test.ts -t 'a password-state write'4/4;src/admin-user-endpoints.test.ts100/100.Derived gate list (dispatch-gates --commands, 68 families) and --ran reconciliation
node scripts/pm/dispatch-gates.mjs --ran FILE— 68 derived, 67 run, 1 NOT-MEASURED, 0 UNRUN. Every run family exited 0.check-plugin-teardown-shape.mjs --self-testfirst exited 3 (fixture commit unreachable on the shallow clone); aftergit fetch --unshallow origin mainit exited 0 (48 cases).check:dts-closurefirst exited 1: the first closure build ran withOS_SKIP_DTS=1; after a forced build with declarations it exited 0 (81 packages, 256/256 declaration files).check:dual-build-cjs-loads(exit 3, PREREQUISITE NOT MET: 43 packages outside this card's build closure have nodist). CI's run is the reading.Dogfood battery: n/a (no
!in the title, no(narrowing)arm).Generated by Claude Code