Skip to content

fix(plugin-auth): audit the forced-reset flag and its clear under the person who caused them - #31820

Merged
objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/project-thread-ux9sz7
Nov 9, 2026
Merged

objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/project-thread-ux9sz7

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

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 session session_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)。
  • 为什么改:卡 plugin-auth audit: the admin set-user-password and the user's change-password write a sys_user audit row (must_change_password) with actor and user_id null #31804。main 上这两行审计的 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/main 5b7269f. A scratch probe (not committed) drove both doors over a real ObjectQL on better-sqlite3 with plugin-audit's real installAuditWriters and read the sys_audit_log rows for the user. The card's reading reproduces on main:

Write Door actor user_id
must_change_password false → true admin set-user-password null null
last_login_at (sign-in stamp) sign-in the user the user
password_changed_at + must_change_password true → false change-password null null

The 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):

Hop Where What it carries
request scope auth-manager-request-routing.ts runWithAuthActorScope around auth.handler; a framework route opens it itself with runAttributedToUser(actor, …) one AsyncLocalStorage scope per request
who auth-manager-before-hook.ts setAuthActorResolver (the session's user and impersonatedBy); SCIM: the verified connection (scimRequestConnectionId) resolved lazily, once per request
write context auth-actor-attribution.ts authSystemWriteContext() isSystem: true plus attributedUserId / impersonatedBy / performedBy, or actor: svc:scim:… for SCIM
engine → audit ObjectQL buildProvenance; plugin-audit audit-writers.ts user_id = session.userId ?? provenance.attributedUserId; actor = that, else session.actor

Both writes built their context as a bare { isSystem: true, positions: [], permissions: [] }, so nothing reached the attribution channel.

  • The forced reset (admin-user-endpoints.ts): stampMustChangePassword builds its context as { ...SYSTEM_CTX, ...(await authSystemWriteContext()) }, and runAdminSetUserPassword runs the stamp inside runAttributedToUser(actor, …) with the actor the route admitted (gateAdmin, which adds impersonatedBy from an impersonation session). Only the stamp is wrapped: the credential write and the revocation keep their contexts.
  • The user's change (auth-manager-password-session-policy.ts stampPasswordChangedAt): the context is { ...SYSTEM_CTX, ...attribution } when the seam's attributedUserId is the stamped account itself, else the bare system context. On /change-password the stamped account is the session's own (passwordChangeAfterEffectsAccount), so the clear names the user. The same stamp runs after /reset-password and /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.
  • Authorization is unchanged. Both writes keep isSystem: true, positions: [] and permissions: []; the attribution keys are read by no security middleware (auth-actor-attribution.ts header). No field-protection or read-only strip is crossed: the written fields and values are byte-identical.
  • Bounded rider, declared. stampMustChangePassword is also the create-user door's stamp, and that route already runs inside runAttributedToUser(actor, …) (auth-plugin.ts), so the administrator-created user's must_change_password set 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-level describe('a password-state write names the person who caused it'), real ObjectQL + better-sqlite3 + AuthManager.handleRequest, observed on the raw engine update (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):
    • forced reset: the must_change_password: true write carries attributedUserId = the administrator, isSystem: true, no userId; CONTROL: 200, data.mustChangePassword: true, the patch is exactly { id, must_change_password: true }, the stored flag is set;
    • forced reset from an impersonation session: impersonatedBy rides beside the administrator;
    • change-password: the clear carries attributedUserId = the user; CONTROL: 200, patch keys id, must_change_password, password_changed_at, stored flag cleared; CONTROL: the sign-in stamp is the user's, as before;
    • negative pin: a stamp inside another account's scope stays the system's, inside the holder's own scope it is credited; CONTROL: the emailed-link /reset-password stamp stays the system's.
  • admin-user-endpoints.test.ts, top-level describe for the create-user rider: inside the route's scope the stamp context is the system's plus attributedUserId; 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 import src (no dist leg):

  1. 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, null received; impersonatedBy: "admin_at_keyboard" expected, null received); the create-user rider pin red on the same mutation.
  2. auth-manager-password-session-policy.ts: the attributed-context ternary → the bare SYSTEM_CTX — the change-password pin and the own-holder half of the negative pin red (attributedUserId = the user expected, null received).
  3. same file: attribution.attributedUserId === userId ? → attribution.attributedUserId !== undefined ? — the negative pin red (attributedUserId: null expected, "someone_else" received).

A first attempt at (2) with the bare replacement SYSTEM_CTX was 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

Verification

All at head d47e8cd6 (base 5b7269ff; origin/main has since moved by commits touching none of plugin-auth, plugin-audit or objectql, 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-typecheck OK, the ledger held (10 files / 72 errors / 23 signatures, unchanged).
  • Package lint, eslint --no-inline-config packages/plugins/plugin-auth (the package has no lint script) — exit 0.
  • New pins alone: vitest run src/password-reset-ends-sessions.test.ts -t 'a password-state write' 4/4; src/admin-user-endpoints.test.ts 100/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-test first exited 3 (fixture commit unreachable on the shallow clone); after git fetch --unshallow origin main it exited 0 (48 cases).
  • check:dts-closure first exited 1: the first closure build ran with OS_SKIP_DTS=1; after a forced build with declarations it exited 0 (81 packages, 256/256 declaration files).
  • NOT MEASURED: check:dual-build-cjs-loads (exit 3, PREREQUISITE NOT MET: 43 packages outside this card's build closure have no dist). CI's run is the reading.

Dogfood battery: n/a (no ! in the title, no (narrowing) arm).


Generated by Claude Code

… 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>
@github-actions github-actions Bot added size/m documentation Improvements or additions to documentation tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface labels Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

📓 Docs Drift Check

3 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
  • the SDK route bridge reached 65 of 231 client-bound route-ledger rows — the other 166 have no registrar path: tail to select them, so pages documenting THEIR client methods cannot appear above, on this or any run. Of those 166: 0 are remediable by widening that discovery convention (an in-repo file declares the path; the convention did not scan it); 59 are structural — on a ledger where NOT ONE row is declared in-repo, so no discovery change reaches them at any price; 107 are undecided (no in-repo declaration, on a ledger that has other in-repo registrars — absence and an unreadable spelling are not distinguishable here). The rows themselves: node scripts/docs-audit/affected-docs.mjs --bridge-coverage
  • a page that states a rule by its inputs shares no identifier with the emitter that implements the rule, so an emitter-only diff cannot list it — not on this run and not on any run. Measured on fix(driver-sql): emit varchar(maxLength) for a text field a declared index keys on #11430: content/docs/protocol/objectql/types.mdx documents the text-family column mapping by the ObjectQL type names it maps FROM (text / textarea / html) while the diff changed createColumn; it went unlisted, and it was the page that diff falsified, in four places. No shared token exists to detect this on, so a rule your change carries has to be re-read by hand in the pages that restate it.
  • a key NAME is not a key, so the hand re-read the line above prescribes can land on the wrong schema. The same spelling is authorable on one governed type and a [REMOVED] tombstone on another for each of active, aria, joins, objects, template, tools and version (censused on [finding] tools is a key on BOTH AgentSchema (tombstoned, dead) and SkillSchema (live, cloud-attested), so a name-based search attributes skill examples to the agent key — it produced a false stop-the-line alarm on PR #19059 #19093 over the liveness ledger's governed types, top-level keys); nothing in a search result distinguishes the two, so a grep hit on a LIVE example reads as evidence about the DEAD key. Measured on fix(spec): the agent.tools liveness row says dead — it claimed live on a key the schema tombstoned #19059: content/docs/ai/agents.mdx was reported as contradicting the agent.tools tombstone over its tools: example at :161, which is inside the defineSkill({ block opened at :155 — the page was already correct. Settle ownership by PARSING the value against both schemas, never by the name: that literal PASSES SkillSchema, and as an AgentSchema it FAILS at tools with the tombstone prescription. ⛔ These names are not the whole class — a key retired through a .strict() guidance map leaves no tombstone in the walked shape and none of them here (tool.category, live as AIToolDefinition.category).

Coarse fallback — 22 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): node scripts/docs-audit/affected-docs.mjs --json 6be71abc34cdd7adcc6057d121479ba5a11724e3 → packageMentionDocs.

Which tree this was computed on

This run read content/docs from 90588cdb49186e42c9b8c4ff2a1b617b5fa64112 — the merge of head d47e8cd691a93c314b43c1ec1d079460dddd2a2e into base 6be71abc34cdd7adcc6057d121479ba5a11724e3, which is what actions/checkout gives a pull_request run. Not the PR head.

A worktree cut from an older main holds a different content/docs, so re-deriving there can legitimately return a different list — that is a different tree, not a wrong row. To answer on the same tree:

# 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

⚠️ That checkout carried uncommitted changes, so the commit above does not fully identify what was read.

@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

domain:server#3 · os-steve · session_01ADHkmQXLfvyB5R53VDm3Ka

席位核对 · ACCEPT · #31820 (Fixes #31804) · 2026-11-09T05:53Z

Head-sha: d47e8cd6

  • Form: draft to main. The first content line is Fixes #31804, and the whole card lands here. Clause-②: no, because only the audit row's content changes. Metadata-protocol: none. Patch changeset.

  • Premise measured: a real-writer probe on main 5b7269ff (sqlite plus plugin-audit's installAuditWriters) finds actor and user_id null on both must_change_password rows, while the sign-in stamp is attributed. The fix reuses fix(plugin-auth,plugin-audit): a SCIM-driven write names the SCIM connection that performed it, on its audit row #30989's seam (authSystemWriteContext / runAttributedToUser), with no second mechanism:

    • the forced-reset stamp runs attributed to the admin;
    • the change-password stamp takes the seam's attribution only when it names the stamped account itself.

    Both writes stay isSystem with empty positions and permissions. Values and responses are unchanged (CONTROL pins).

  • Pins and ablations: 3 ablations, each red and then restored clean. plugin-auth: 4411/4411, typecheck 0, lint 0.

  • Gates (check-runs on this head): 50 runs, 35 success, 15 skipped, 0 other. check-governed-merges --pr 31820: NOT governed, 249 changed lines. K = 8 first-parent commits on main since the PR base, and a local merge with main is clean. dispatch-gates: 68 derived, 67 run, 1 not measured (dual-build-cjs-loads, its prerequisite build exited 3); CI's build lanes on this head are green.

  • Accepted deviations, each a seat ruling:

    1. The committed pins observe the engine context, the same 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; the real-writer probe is the measured premise.
    2. Bounded rider: create-user shares the stamp helper, so its row now names the admin. This is declared and pinned.
  • Out of scope: none filed on GitHub.

  • Landing: ready and auto-merge in this stroke. On merge: a landing record on plugin-auth audit: the admin set-user-password and the user's change-password write a sys_user audit row (must_change_password) with actor and user_id null #31804, pm:dispatched removed, and the card closed by Fixes.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 9, 2026 05:53
@objectstack-fleet
objectstack-fleet Bot enabled auto-merge November 9, 2026 05:53
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 9, 2026
Merged via the queue into main with commit 4ed2092 Nov 9, 2026
51 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/project-thread-ux9sz7 branch November 9, 2026 06:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation size/m tests tooling Fix lands in tooling, not a product package — enters pm:queue only with Unblocks: or a named surface

Projects

None yet

1 participant