Repository navigation
Commit 6dd5716
fix(plugin-auth)!: a change to a user's credential ends every other outstanding password-reset token of that user (#34667)
Clause-②: no (narrowing) — a password write through either of this
plugin's storage adapters (the factory `AuthManager` composes, and the
exported raw `createObjectQLAdapter`) ends every other password-reset
link and texted reset code still outstanding for that user, in the same
request and before the new password is written. In the `AuthManager`
composition that is every door that sets a password: a completed reset
(`POST /reset-password`, `POST /phone-number/reset-password`), the
user's own `POST /change-password`, an administrator's `POST
/admin/set-user-password`, and a first password (`POST
/set-initial-password`). No request, response or metadata shape is
added, removed or re-shaped; a link or code requested after the change
resets as usual.
Metadata-protocol: none
Skills-docs: updated here —
`content/docs/permissions/authentication.mdx` states the rule; no skill
under `skills/**` teaches the reset doors.
## 维护者速读
- 改了什么:用户的密码只要经本插件的存储适配器被写入(完成重置、本人改密、管理员设密、首次设密,以及导出的原始
`createObjectQLAdapter`),该用户此前发出、尚未使用的其他重置链接和短信重置码一律作废;改动之后再申请的链接/验证码照常可用。
- 为什么改:安全加固,规则是「凭据一变,之前的重置凭证全部失效」。
- 风险与回滚:每次写密码多一次读和一两次按条件删除(配置了二级缓存时先读后按 id
删);作废失败、缓存键无法确定、或部署把验证标识存成非明文时,这次写密码直接报错、旧密码不变(宁可失败,不留活凭证)。回滚 = revert 本
PR。
-
先看:`packages/plugins/plugin-auth/src/credential-change-ends-reset-tokens.ts`(规则、两条删除路径与三种拒绝)、`packages/plugins/plugin-auth/src/objectql-adapter.ts`
中工厂适配器与原始适配器的 create / update / updateMany
接线(均在写入之前)、`packages/plugins/plugin-auth/src/credential-change-ends-reset-tokens.test.ts`。
- 两分钟验证:`pnpm --filter @objectstack/plugin-auth exec vitest run
src/credential-change-ends-reset-tokens.test.ts`,预期 17/17 通过。
- 需要你做的:无,席位落地。
## What changes
- **The rule** —
`packages/plugins/plugin-auth/src/credential-change-ends-reset-tokens.ts`
(new): a change to a user's credential ends every other outstanding
password-reset token of that user — the emailed reset links and the
texted reset code for the phone number the user holds — and, with a host
`secondaryStorage` in the `AuthManager` composition, their cached
copies. An ended token answers exactly what a token never issued
answers. With no cache, each token shape is ended by one predicate
delete; with a cache, the links are read first so each cached copy can
be named, and exactly those rows are deleted. A password write is
refused, and the old password stands, when its tokens cannot be ended,
when a cached link's key cannot be named, when the verification store
keeps identifiers other than plain (`verification.storeIdentifier`), or
when the account row it targets names no user.
- **The wiring** —
`packages/plugins/plugin-auth/src/objectql-adapter.ts`: both storage
adapters call the rule for every `sys_account` write that carries
`password`, before the write lands: the factory `AuthManager` composes
(`create`, `update`, `updateMany`) and the exported raw
`createObjectQLAdapter` (the same three verbs). The raw adapter is
handed none of better-auth's options, so through it the rule covers the
token rows only; a host that pairs it with a `secondaryStorage` or a
`verification.storeIdentifier` setting is outside the rule.
- **Docs** — `content/docs/permissions/authentication.mdx` states the
rule beside the reset section.
- **Census** — the tenant-audit census is regenerated over current
`main` for this change's three engine write sites (`node
scripts/tenant-audit-census.mjs --write`); `main`'s census is now
sharded per package, so the only moved artefact is the plugin-auth shard
(`docs/audits/2026-08-tenant-audit-write-call-sites.counts/plugins/plugin-auth.md`):
write call sites 95 → 98, object name chosen at run time 37 → 40, other
run-time expression 35 → 38, provably carrying no context 12 → 15,
readable engine type 69 → 72; repository total 325.
- **Changeset** — `@objectstack/plugin-auth` patch, BREAKING narrowing,
ADR-0087 `not-required`; it scopes the rule to the two storage adapters
and states what the raw one does not cover.
The eight plugin-auth files held by #34333 are untouched.
## Tests
`packages/plugins/plugin-auth/src/credential-change-ends-reset-tokens.test.ts`
— every door through the real routes (a real `AuthManager` over a real
`ObjectQL` engine on better-sqlite3, behind
`AuthPlugin.registerAuthRoutes` on a Hono app):
- a completed reset ends the user's other reset links, whichever was
spent first; the ended link answers what a never-issued link answers, at
`POST /reset-password` and at its landing (`GET
/reset-password/:token`); the password is the one the spent link set;
- `POST /change-password`, `POST /admin/set-user-password` (for a user
with a local password and for one without) and `POST
/set-initial-password` each end every link outstanding before them; a
link requested afterwards resets (the control);
- a password write through the exported `createObjectQLAdapter` ends the
holder's earlier link;
- a password change ends the outstanding texted reset code (it answers
what a never-sent code answers); a code requested afterwards resets; a
completed texted-code reset ends the outstanding links;
- another user's links are untouched (the control);
- with a `secondaryStorage` cache, an ended link's and an ended texted
code's cached copies are gone, and the link answers what a never-issued
link answers;
- a password write does not land — the old password stands and the
outstanding link resets — when a token delete fails, and when a cached
link's key cannot be named;
- the composed verification store carries no identifier-storage setting
(a closed key set, with and without a cache); a password write under a
setting other than plain is refused, and so is one whose target names no
user.
## Acceptance notes
- None beyond the scope stated in the changeset.
## Verification
Head `1e66034e6a`. The pins, the ablation, the suite, typecheck and the
gates were read at `5f08f64e63`; the one commit after it, `1e66034e6a`,
merges `main` commits that touch only `ui/**` and `.changeset/**`, and
the census gate was re-run there.
- **The pins** — `credential-change-ends-reset-tokens.test.ts`: 17/17
passed.
- **Ablation** (one shot, at `6aa9ab8204`, the rule's entry point in
`credential-change-ends-reset-tokens.ts` made inert through
`scripts/ablation-replace.mjs`): 15 of 17 red, then restored — blob
equal to `HEAD`, `git diff HEAD` empty. The two that stay green are by
design: the cross-user control, and the composed-configuration pin,
which reads the auth instance and not the rule.
- **plugin-auth** — `pnpm --filter @objectstack/plugin-auth test`: exit
0, Test Files 283 passed (283), Tests 5923 passed / 10 skipped (5933).
`pnpm --filter @objectstack/plugin-auth typecheck`: exit 0 (including
`check:test-typecheck`, debt ledger unchanged).
- **Census** — `node scripts/check-tenant-audit-census.mjs`: exit 0 at
`5f08f64e63` and at `1e66034e6a` (325 write call sites certified across
18 package shards); `--self-test` exit 0.
- **Dogfood battery** — not re-run this round: the change since the
battery's green reading at `f389175cb7` (478 passed / 3 skipped files)
is the seam module, its wiring in both adapters, its pins, the changeset
and the census.
- **Derived gates** — `node scripts/pm/dispatch-gates.mjs --commands`
(100 families), each run with its exit code captured before any pipe,
then `--ran` reconciled: 98 exit 0; 1 NOT MEASURED — `pnpm
check:dual-build-cjs-loads` exit 3 (prerequisite: a full repository
build), left to CI; 1 exit 1 — `pnpm check:docs-transcript-drift`, on
three pages this diff does not touch
(`content/docs/deployment/validating-metadata.mdx`,
`content/docs/getting-started/build-with-claude-code.mdx`,
`content/docs/ui/react-pages.mdx`), whose stated author-time rule count
is one above what `packages/lint/src/authoring-rules.ts` derives; this
tree is byte-identical to `main` on those pages and on `packages/lint`,
so the reading is `main`'s own. `check:docs`, `check:skill-examples` and
`check:type-check-debt` were re-run after their prerequisite builds:
exit 0 each.
<details><summary>Gate readings</summary>
- `node scripts/check-tenant-audit-census.mjs`: exit 0 — 325 write call
sites certified across 18 package shards.
- `pnpm --filter @objectstack/spec run check:docs`: exit 0 — 248
generated files in sync.
- `pnpm --filter @objectstack/spec run check:skill-examples`: exit 0 —
347 prose examples type-check across 3 surfaces.
- `pnpm check:type-check-debt`: exit 0 — 0 raw tsc errors above any
recorded number.
- `pnpm check:nul-bytes`: exit 0 at `1e66034e6a`.
- `node scripts/pm/dispatch-gates.mjs --ran`: 100 derived families
accounted for — 99 run, 1 NOT MEASURED.
</details>
---
_Generated by [Claude
Code](https://claude.ai/code/session_01QSeKYn5CmmdShCJifm6WYj)_
<!-- signed: security#2 · os-justin · session_01QSeKYn5CmmdShCJifm6WYj
-->
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent 8f36b06 commit 6dd5716
6 files changed
Lines changed: 866 additions & 7 deletions
File tree
- .changeset
- content/docs/permissions
- docs/audits/2026-08-tenant-audit-write-call-sites.counts/plugins
- packages/plugins/plugin-auth/src
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
314 | 314 | | |
315 | 315 | | |
316 | 316 | | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
317 | 325 | | |
318 | 326 | | |
319 | 327 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
| 23 | + | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| |||
0 commit comments