Skip to content

Commit 0f9dab0

Browse files
committed
feat(spec)!: retire emailAndPassword.revokeSessionsOnPasswordReset
A completed password reset always ends every session the account holds, and there is no setting. The key becomes a retiredKey() tombstone with an exported prescription; plugin-auth's entry guard refuses the retired key at any value with the same text, since the manager takes its configuration unparsed. Registers the retired key and the D3 semantic entry, adds the step-18 rationale fragment, a retirement pin with a tree-scoped absence scan, and updates HARDENING.md and the authentication docs. Claude-Session: https://claude.ai/code/session_01WGufzgjTaf6BB6T3vxdisU Co-authored-by: Claude <noreply@anthropic.com>
1 parent 21510bb commit 0f9dab0

15 files changed

Lines changed: 445 additions & 71 deletions
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@objectstack/spec': minor
3+
'@objectstack/plugin-auth': minor
4+
---
5+
6+
feat(spec)!: retire `emailAndPassword.revokeSessionsOnPasswordReset` — a completed password reset always ends every session the account holds, and there is no setting (#29909)
7+
8+
Clause-②: no (narrowing) — `EmailAndPasswordConfig.revokeSessionsOnPasswordReset` becomes a `retiredKey()` tombstone, so the schema parse and `tsc` refuse it at any value, and plugin-auth's entry guard refuses it at any value too, `true` included, which it accepted before. Nothing is widened.
9+
Metadata-protocol: narrowed
10+
11+
<!-- adr-0087: registered email-and-password-revoke-sessions-on-reset-retired -->
12+
13+
**BREAKING** for a configuration that still writes `emailAndPassword.revokeSessionsOnPasswordReset`, at any value.
14+
15+
- **`@objectstack/spec`.** `EmailAndPasswordConfig.revokeSessionsOnPasswordReset` is retired (ADR-0049 enforce-or-remove). A completed self-service password reset already ended every session the account holds, on every reset door, and an explicit `false` was already refused at boot, so the key could hold one value only. It is now a tombstone: a typed configuration that writes it fails `tsc`, and `AuthConfigSchema` / `EmailAndPasswordConfigSchema` refuse it with the prescription. The authorable-surface row reads `[RETIRED]`, `RETIRED_KEYS_BY_MAJOR[18]` lists `system/EmailAndPasswordConfig:revokeSessionsOnPasswordReset`, and the upgrade guide carries the semantic entry `email-and-password-revoke-sessions-on-reset-retired`. The prescription is exported as `REVOKE_SESSIONS_ON_PASSWORD_RESET_RETIRED` (`@objectstack/spec/system`). No ADR-0087 conversion: the key lives in the configuration a host hands the auth plugin, never in a stack or a stored row, so `os migrate meta` has nothing to rewrite.
16+
- **`@objectstack/plugin-auth`.** The auth manager takes its configuration unparsed, so it refuses the retired key itself, where the configuration enters: at construction, which stops the boot, and on a configuration patch, where the standing configuration keeps ruling. It now refuses `true` as well as `false`, with the tombstone's own prescription. `true` asked for what the platform does anyway; the key is to be deleted either way. The auth instance still sets better-auth's own option of that name itself, so a completed reset ends the account's sessions exactly as before.
17+
- **Unchanged.** What a password reset does: every self-service reset door ends every session the account holds, and each ended session is stamped `revoke_reason: password_reset`. An absent key is accepted, as before.
18+
19+
**The remedy.** Delete `revokeSessionsOnPasswordReset` from the `emailAndPassword` block of the auth configuration, whatever it holds; nothing replaces it.

‎content/docs/permissions/authentication.mdx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,10 @@ const response = await fetch('http://localhost:3000/api/v1/auth/reset-password',
309309

310310
A completed reset ends every existing session of the account — the emailed link
311311
and the phone OTP reset alike, the same as an administrator's forced reset — so
312-
the user signs in again with the new password. It is not a setting:
313-
`emailAndPassword.revokeSessionsOnPasswordReset: false` is refused at boot.
312+
the user signs in again with the new password. It is not a setting: the former
313+
`emailAndPassword.revokeSessionsOnPasswordReset` key is retired, and a
314+
configuration that still carries it, at any value, is refused at boot — delete
315+
the key.
314316

315317
#### Setting a first local password
316318

‎docs/HARDENING.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ ObjectStack uses [better-auth](https://www.better-auth.com/) via
260260
| Session TTL | 7 days | `session.expiresIn` (seconds) |
261261
| Access token TTL | inherited from session | configure in better-auth |
262262
| Refresh | better-auth `/auth/get-session` rolls TTL | `session.updateAge` (seconds) |
263-
| Revocation | Sign-out deletes the `session` row. A revoke, and a completed password reset (which ends every session of the account), keep the row stamped `revoked_at` / `revoke_reason` (`password_reset` for the reset) and refuse it | — always on (`revokeSessionsOnPasswordReset: false` is refused at boot) |
263+
| Revocation | Sign-out deletes the `session` row. A revoke, and a completed password reset (which ends every session of the account), keep the row stamped `revoked_at` / `revoke_reason` (`password_reset` for the reset) and refuse it | — unconditional; no setting (the retired `emailAndPassword.revokeSessionsOnPasswordReset` key is refused at any value) |
264264
| Idle / absolute / concurrent caps | Off (opt-in) | `session_idle_timeout_minutes` / `session_absolute_max_hours` / `max_concurrent_sessions_per_user` (Setup → Authentication) |
265265
| Email verify TTL | 1 hour | `emailVerification.expiresIn` |
266266

@@ -277,7 +277,7 @@ curl -H "Authorization: Bearer $TOK" $API/data/account
277277
# → 401 Unauthorized
278278

279279
# 3. Confirm a completed password reset ends the user's other sessions
280-
# (always on: a session signed in before the reset answers 401 after it)
280+
# (unconditional: a session signed in before the reset answers 401 after it)
281281
```
282282

283283
## CORS

‎packages/plugins/plugin-auth/src/auth-manager-auth-instance.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,8 +384,10 @@ export async function createAuthInstance(this: AuthInstanceHost): Promise<Auth<a
384384
...(this.config.emailAndPassword?.autoSignIn != null
385385
? { autoSignIn: this.config.emailAndPassword.autoSignIn } : {}),
386386
// A completed password reset ends the account's other sessions, on
387-
// every reset door, always — not a deployment option. An explicit
388-
// `false` never reaches here: the manager refuses it at entry.
387+
// every reset door, always — not a deployment option. This is
388+
// better-auth's own option, set here and never read from the host
389+
// configuration: the spec key of the same name is retired, and the
390+
// manager refuses it at entry at any value.
389391
// `password-reset-ends-sessions.ts` holds the rule and the wiring.
390392
revokeSessionsOnPasswordReset: true,
391393
// #14319 — better-auth calls this as `sendResetPassword(data, ctx.request)`.

‎packages/plugins/plugin-auth/src/auth-manager.test.ts‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,7 +2057,6 @@ describe('AuthManager', () => {
20572057
maxPasswordLength: 64,
20582058
requireEmailVerification: true,
20592059
autoSignIn: false,
2060-
revokeSessionsOnPasswordReset: true,
20612060
},
20622061
});
20632062
await manager.getAuthInstance();
@@ -2069,8 +2068,10 @@ describe('AuthManager', () => {
20692068
maxPasswordLength: 64,
20702069
requireEmailVerification: true,
20712070
autoSignIn: false,
2072-
revokeSessionsOnPasswordReset: true,
20732071
});
2072+
// better-auth's own option, set by the auth instance whatever the host
2073+
// passes (the spec key of that name is retired; the manager refuses it).
2074+
expect(capturedConfig.emailAndPassword.revokeSessionsOnPasswordReset).toBe(true);
20742075
expect(typeof capturedConfig.emailAndPassword.sendResetPassword).toBe('function');
20752076
});
20762077
});

‎packages/plugins/plugin-auth/src/auth-manager.ts‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,9 +1606,10 @@ export class AuthManager {
16061606
assertScimAdminCoherence(config.plugins);
16071607

16081608
// A completed password reset ends the account's other sessions, always;
1609-
// an explicit `revokeSessionsOnPasswordReset: false` is refused here, at
1610-
// boot, rather than silently overridden (`password-reset-ends-sessions.ts`).
1611-
// `applyConfigPatch` re-runs it on the merged result.
1609+
// the retired `emailAndPassword.revokeSessionsOnPasswordReset` is refused
1610+
// here at any value, at boot, rather than silently ignored
1611+
// (`password-reset-ends-sessions.ts`). `applyConfigPatch` re-runs it on the
1612+
// merged result.
16121613
assertPasswordResetEndsSessions(config.emailAndPassword);
16131614

16141615
// The mobile sign-in hand-off's registered app schemes — same
@@ -2083,8 +2084,8 @@ export class AuthManager {
20832084
assertScimAdminCoherence(next.plugins);
20842085
}
20852086
// Same entry validation the constructor runs, on the MERGED block: a patch
2086-
// cannot ask a completed password reset to keep the account's other
2087-
// sessions. Refused loudly and the standing config keeps ruling.
2087+
// cannot write the retired `revokeSessionsOnPasswordReset`, at any value.
2088+
// Refused loudly and the standing config keeps ruling.
20882089
if ('emailAndPassword' in patch) {
20892090
assertPasswordResetEndsSessions(next.emailAndPassword);
20902091
}

‎packages/plugins/plugin-auth/src/password-reset-ends-sessions.test.ts‎

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
* - a reset that does not complete (a token that does not match) ends nothing;
2020
* - with no configuration at all, the auth instance asks better-auth to end
2121
* sessions on every reset door;
22-
* - an explicit `revokeSessionsOnPasswordReset: false` is refused at
23-
* construction and on a configuration patch, where the standing
24-
* configuration keeps ruling; `true` is accepted;
22+
* - the retired `revokeSessionsOnPasswordReset` is refused at any value, with
23+
* the spec tombstone's prescription, at construction and on a
24+
* configuration patch, where the standing configuration keeps ruling; an
25+
* absent key passes;
2526
* - a session a password reset ends leaves a revocation trail: on each reset
2627
* door every session the account held is still a `sys_session` row
2728
* afterwards, stamped `revoked_at` and `revoke_reason: password_reset`, and
@@ -35,6 +36,7 @@ import { SqlDriver } from '@objectstack/driver-sql';
3536
import { AuthManager } from './auth-manager.js';
3637
import { runAdminSetUserPassword, type AdminUserEndpointDeps } from './admin-user-endpoints.js';
3738
import { authIdentityObjects } from './manifest.js';
39+
import { REVOKE_SESSIONS_ON_PASSWORD_RESET_RETIRED } from '@objectstack/spec/system';
3840
import { assertPasswordResetEndsSessions } from './password-reset-ends-sessions.js';
3941
import { memoizeScrypt } from './__tests__/scrypt-memo.testkit';
4042
import { sqliteEnginePool } from './__tests__/sqlite-engine-pool.testkit';
@@ -51,6 +53,8 @@ const EMAIL = 'reset-ends-sessions@example.com';
5153
const FIRST = 'F1rst!Password-For-Reset';
5254
const SECOND = 'S3cond!Password-After-Reset';
5355
const SYS = { context: { isSystem: true } } as never;
56+
/** The retired configuration key, spelled once. */
57+
const RETIRED = 'revokeSessionsOnPasswordReset';
5458

5559
const engines = sqliteEnginePool(async () => {
5660
const engine = new ObjectQL();
@@ -325,31 +329,49 @@ describe('a session a password reset ends leaves a revocation trail', () => {
325329
}, 60_000);
326330
});
327331

328-
describe('revokeSessionsOnPasswordReset: false is refused, never silently overridden', () => {
329-
it('is refused at construction', () => {
330-
expect(
331-
() =>
332-
new AuthManager({
333-
secret: SECRET,
334-
baseUrl: BASE,
335-
emailAndPassword: { enabled: true, revokeSessionsOnPasswordReset: false },
336-
} as never),
337-
).toThrow(/revokeSessionsOnPasswordReset: false is not supported/);
338-
});
332+
describe('the retired revokeSessionsOnPasswordReset is refused at any value, never silently ignored', () => {
333+
// The manager takes its configuration unparsed, so the spec tombstone never
334+
// sees a host's object: this guard answers it with the tombstone's own text.
335+
const PRESCRIPTION =
336+
/^\[auth\] `emailAndPassword\.revokeSessionsOnPasswordReset` was removed in @objectstack\/spec 18 \(ADR-0049 enforce-or-remove\) — .*Delete the key; nothing replaces it\.$/s;
339337

340-
it('is refused on a configuration patch, and the standing configuration keeps ruling', () => {
341-
const manager = new AuthManager({ secret: SECRET, baseUrl: BASE, emailAndPassword: { enabled: true, minPasswordLength: 10 } } as never);
342-
expect(() =>
343-
manager.applyConfigPatch({ emailAndPassword: { revokeSessionsOnPasswordReset: false, minPasswordLength: 20 } } as never),
344-
).toThrow(/revokeSessionsOnPasswordReset: false is not supported/);
345-
const standing = (manager as unknown as { config: { emailAndPassword?: Record<string, unknown> } }).config.emailAndPassword;
346-
expect(standing?.minPasswordLength).toBe(10);
347-
expect(standing && 'revokeSessionsOnPasswordReset' in standing).toBe(false);
338+
it('the refusal is the spec tombstone\'s prescription, word for word', () => {
339+
expect(() => assertPasswordResetEndsSessions({ revokeSessionsOnPasswordReset: true })).toThrow(
340+
`[auth] ${REVOKE_SESSIONS_ON_PASSWORD_RESET_RETIRED}`,
341+
);
348342
});
349343

350-
it('accepts true and an absent key', () => {
351-
expect(() => assertPasswordResetEndsSessions({ revokeSessionsOnPasswordReset: true })).not.toThrow();
344+
for (const value of [false, true, 'false', 0, null]) {
345+
it(`is refused at construction: ${JSON.stringify(value)}`, () => {
346+
expect(
347+
() =>
348+
new AuthManager({
349+
secret: SECRET,
350+
baseUrl: BASE,
351+
emailAndPassword: { enabled: true, revokeSessionsOnPasswordReset: value },
352+
} as never),
353+
).toThrow(PRESCRIPTION);
354+
});
355+
}
356+
357+
for (const value of [false, true]) {
358+
it(`is refused on a configuration patch, and the standing configuration keeps ruling: ${value}`, () => {
359+
const manager = new AuthManager({ secret: SECRET, baseUrl: BASE, emailAndPassword: { enabled: true, minPasswordLength: 10 } } as never);
360+
expect(() =>
361+
manager.applyConfigPatch({ emailAndPassword: { revokeSessionsOnPasswordReset: value, minPasswordLength: 20 } } as never),
362+
).toThrow(PRESCRIPTION);
363+
const standing = (manager as unknown as { config: { emailAndPassword?: Record<string, unknown> } }).config.emailAndPassword;
364+
expect(standing?.minPasswordLength).toBe(10);
365+
expect(standing && RETIRED in standing).toBe(false);
366+
});
367+
}
368+
369+
it('CONTROL: an absent key, an undefined one and no block at all pass, and the manager is built', () => {
352370
expect(() => assertPasswordResetEndsSessions({})).not.toThrow();
371+
expect(() => assertPasswordResetEndsSessions({ [RETIRED]: undefined })).not.toThrow();
353372
expect(() => assertPasswordResetEndsSessions(undefined)).not.toThrow();
373+
expect(
374+
() => new AuthManager({ secret: SECRET, baseUrl: BASE, emailAndPassword: { enabled: true, minPasswordLength: 10 } } as never),
375+
).not.toThrow();
354376
});
355377
});

‎packages/plugins/plugin-auth/src/password-reset-ends-sessions.ts‎

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,36 +38,43 @@
3838
* `/sign-out` alone. And the account's API keys are untouched; the forced
3939
* reset's key revocation is its own switch.
4040
*
41-
* ## The declared key
41+
* ## The retired key
4242
*
43-
* `emailAndPassword.revokeSessionsOnPasswordReset` is still declared by the
43+
* `emailAndPassword.revokeSessionsOnPasswordReset` is RETIRED from the
4444
* published configuration schema (`@objectstack/spec`,
45-
* `EmailAndPasswordConfigSchema`). `true` is what the platform does anyway and
46-
* is accepted. An explicit `false` asks for something the platform no longer
47-
* does, so {@link assertPasswordResetEndsSessions} REFUSES it where the
48-
* configuration enters the manager — at construction, which stops the boot, and
49-
* on a configuration patch, where the standing configuration keeps ruling —
50-
* rather than overriding it silently: a declaration that reads as in force and
51-
* is not is the ADR-0049 hazard, and refusing is how this plugin treats every
52-
* other declaration it will not honour (`assertAudienceConfig`,
53-
* `assertScimAdminCoherence`).
45+
* `EmailAndPasswordConfigSchema`): it could hold only one value, so it is a
46+
* `retiredKey()` tombstone, and a typed or parsed configuration that writes it
47+
* fails `tsc` or the parse with the prescription. The manager never parses its
48+
* configuration through that schema, so {@link assertPasswordResetEndsSessions}
49+
* holds the same line where the configuration enters the manager — at
50+
* construction, which stops the boot, and on a configuration patch, where the
51+
* standing configuration keeps ruling — and REFUSES the key at any value, with
52+
* the tombstone's own prescription. `true` asked for what the platform does
53+
* anyway and `false` for what it no longer does; either way the key is to be
54+
* deleted, and a declaration that reads as a setting when there is none is the
55+
* ADR-0049 hazard. Refusing is how this plugin treats every other declaration
56+
* it will not honour (`assertAudienceConfig`, `assertScimAdminCoherence`).
57+
* better-auth's own option of the same name is set by the auth instance, never
58+
* read from the host configuration.
5459
*/
5560

56-
import type { EmailAndPasswordConfig } from '@objectstack/spec/system';
61+
import { REVOKE_SESSIONS_ON_PASSWORD_RESET_RETIRED } from '@objectstack/spec/system';
62+
63+
/** The retired configuration key this guard refuses. */
64+
const RETIRED_KEY = 'revokeSessionsOnPasswordReset';
5765

5866
/**
59-
* Refuse an `emailAndPassword` block that asks a completed password reset to
60-
* keep the account's other sessions. Absent and `true` pass; see the header.
67+
* Refuse an `emailAndPassword` block that still writes the retired
68+
* `revokeSessionsOnPasswordReset`, whatever it holds. An absent key (or one
69+
* holding `undefined`, which the schema's tombstone accepts too) passes; see
70+
* the header.
6171
*/
62-
export function assertPasswordResetEndsSessions(
63-
emailAndPassword: Pick<NonNullable<EmailAndPasswordConfig>, 'revokeSessionsOnPasswordReset'> | undefined,
64-
): void {
65-
if (emailAndPassword?.revokeSessionsOnPasswordReset === false) {
66-
throw new Error(
67-
'[auth] emailAndPassword.revokeSessionsOnPasswordReset: false is not supported: a completed ' +
68-
"password reset always ends the account's other sessions, on every reset door, the same as " +
69-
"an administrator's forced reset. Remove the key (true is accepted and changes nothing). " +
70-
'Refused rather than ignored, so the configuration never reads as keeping sessions it does not keep.',
71-
);
72+
export function assertPasswordResetEndsSessions(emailAndPassword: unknown): void {
73+
if (
74+
emailAndPassword !== null
75+
&& typeof emailAndPassword === 'object'
76+
&& (emailAndPassword as Record<string, unknown>)[RETIRED_KEY] !== undefined
77+
) {
78+
throw new Error(`[auth] ${REVOKE_SESSIONS_ON_PASSWORD_RESET_RETIRED}`);
7279
}
7380
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
// #29909 — ADR-0049 enforce-or-remove, by the maintainer's ruling on that card:
4+
// a completed self-service password reset always ends every session the
5+
// account holds, and there is no setting. plugin-auth made the behaviour
6+
// unconditional first (it sets better-auth's own option itself and refused an
7+
// explicit `false`), which left `EmailAndPasswordConfig.revokeSessionsOnPasswordReset`
8+
// able to hold one value only. Tombstoned with `retiredKey()`. No D2
9+
// conversion: host plugin configuration, not a stack collection member, not a
10+
// stored row. The D3 record is `email-and-password-revoke-sessions-on-reset-retired`.
11+
export const entry = 'system/EmailAndPasswordConfig:revokeSessionsOnPasswordReset';

0 commit comments

Comments
 (0)