Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .changeset/credential-change-ends-reset-tokens.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'@objectstack/plugin-auth': patch
---

fix(plugin-auth)!: a change to a user's credential ends every other outstanding password-reset token of that user

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

<!-- 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. -->

**BREAKING** password-reset narrowing (`@objectstack/plugin-auth`): a change to a user's credential ends every other outstanding password-reset token of that user.

- **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.
- **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.
- **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.
8 changes: 8 additions & 0 deletions content/docs/permissions/authentication.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,14 @@ the user signs in again with the new password. It is not a setting: the former
configuration that still carries it, at any value, is refused at boot — delete
the key.

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

#### Setting a first local password

`POST /api/v1/auth/set-initial-password` sets an **initial** local password for a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,24 @@ a row or a number here — fix the code, or the census, and regenerate.

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