Skip to content

Commit 6dd5716

Browse files
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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@objectstack/plugin-auth': patch
3+
---
4+
5+
fix(plugin-auth)!: a change to a user's credential ends every other outstanding password-reset token of that user
6+
7+
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.
8+
Metadata-protocol: none
9+
10+
<!-- adr-0087: not-required (no-migration-prescription) No key of any schema is added, removed, renamed or re-shaped, and no export or type changes. What moves is which reset links and codes stay live after a password change, and which password writes are refused, so there is nothing stored for a migration to rewrite and no tombstone. -->
11+
12+
**BREAKING** password-reset narrowing (`@objectstack/plugin-auth`): a change to a user's credential ends every other outstanding password-reset token of that user.
13+
14+
- **Now.** When a user's password is set through either storage adapter, every reset link (`/request-password-reset`) and texted reset code (`/phone-number/request-password-reset`) issued for that user beforehand is ended. In the `AuthManager` composition an ended link or code answers exactly what one never issued answers: `400 INVALID_TOKEN` at `POST /reset-password`, the `INVALID_TOKEN` redirect at the link's landing (`GET /reset-password/:token`), and the never-sent answer at `POST /phone-number/reset-password`; with a host `secondaryStorage` there, its cached copy is removed too. A password write whose outstanding tokens cannot be ended, or whose cached copies cannot be named, does not land: the door answers an error and the old password stands. So does every password write when `verification.storeIdentifier` is set to anything but `plain`, because the tokens cannot be found under it; the `AuthManager` composition never sets it.
15+
- **The raw `createObjectQLAdapter`.** It 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; compose the factory, `createObjectQLAdapterFactory`, as `AuthManager` does.
16+
- **Who moves.** A person holding a reset link or code issued before their password changed requests a new one. Nothing else changes: another user's links and codes, and a link or code requested after the change, reset as before.

‎content/docs/permissions/authentication.mdx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,14 @@ the user signs in again with the new password. It is not a setting: the former
314314
configuration that still carries it, at any value, is refused at boot — delete
315315
the key.
316316

317+
Any change to a user's password ends every other reset link and texted reset
318+
code still outstanding for that user: a completed reset, the user's own
319+
`POST /api/v1/auth/change-password`, an administrator's
320+
`POST /api/v1/auth/admin/set-user-password` and a first password set through
321+
`POST /api/v1/auth/set-initial-password`. An ended link or code answers exactly
322+
what one that was never issued answers (`400 INVALID_TOKEN` at
323+
`reset-password`); a link or code requested after the change works as usual.
324+
317325
#### Setting a first local password
318326

319327
`POST /api/v1/auth/set-initial-password` sets an **initial** local password for a

‎docs/audits/2026-08-tenant-audit-write-call-sites.counts/plugins/plugin-auth.md‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ a row or a number here — fix the code, or the census, and regenerate.
1414

1515
| Measure | Value |
1616
|---|---:|
17-
| Write call sites | 95 |
17+
| Write call sites | 98 |
1818
| Object name statically decidable | 58 |
19-
| Object name chosen at run time | 37 |
19+
| Object name chosen at run time | 40 |
2020
| Object name spelled inline | 47 |
2121
| Object name spelled through a `const` | 11 |
2222
| Object name is an `object: string` parameter | 2 |
23-
| Object name is some other run-time expression | 35 |
23+
| Object name is some other run-time expression | 38 |
2424
| Against a tenancy-enabled object | 56 |
2525
| Against an object declaring tenancy off | 2 |
2626
| Threading a tenant context | 55 |
27-
| Provably carrying none (options read, no context key) | 12 |
27+
| Provably carrying none (options read, no context key) | 15 |
2828
| …and decidably tenancy-enabled | 3 |
2929
| Options argument unreadable | 28 |
3030
| …and decidably tenancy-enabled | 16 |
3131
| Threading a decidably elevated (`isSystem`) context | 38 |
3232
| Threading a decidably non-elevated context | 0 |
3333
| Threading a context of undecidable elevation | 45 |
34-
| Receiver carried a readable engine type | 69 |
34+
| Receiver carried a readable engine type | 72 |
3535
| Receiver erased, placed by the object NAME | 24 |
3636
| Receiver erased, placed by an `object: string` PARAMETER | 1 |
3737
| Receiver erased, placed by an `UNTYPED_RECEIVERS` row | 1 |
@@ -69,6 +69,7 @@ a row or a number here — fix the code, or the census, and regenerate.
6969
| `packages/plugins/plugin-auth/src/auth-plugin.ts` | `update` | `sys_oauth_application` | enabled | PROVABLY NONE | 1 |
7070
| `packages/plugins/plugin-auth/src/auth-plugin.ts` | `update` | `sys_user` | enabled | elevated | 1 |
7171
| `packages/plugins/plugin-auth/src/auth-plugin.ts` | `update` | `SystemObjectName.USER` | undecidable | elevated | 1 |
72+
| `packages/plugins/plugin-auth/src/credential-change-ends-reset-tokens.ts` | `delete` | `VERIFICATION` | undecidable | PROVABLY NONE | 3 |
7273
| `packages/plugins/plugin-auth/src/default-organization-invariant.ts` | `insert` | `sys_organization` | enabled | elevated | 1 |
7374
| `packages/plugins/plugin-auth/src/demo-staff.ts` | `update` | `sys_user` | enabled | elevated | 1 |
7475
| `packages/plugins/plugin-auth/src/demo-staff.ts` | `insert` | `sys_user_permission_set` | enabled | elevated | 1 |

0 commit comments

Comments
 (0)