Skip to content

Commit 2d7ac40

Browse files
committed
feat(auth): close the one-step door on a managed environment, stamp its password, rename it
The door answers the cloud-managed refusal before reading a proof, writes the password-age stamp and forced-change clear, ledgers the sessions it ends, states its closing rule for existing accounts, and is renamed accept-invitation-one-step; SendTemplateInput.deliverOnly becomes deliverOnlyData. Pins every gate and state. Claude-Session: https://claude.ai/code/session_01FEkQ5nNrLRm8ssuwWcBVcw Co-authored-by: Claude <noreply@anthropic.com>
1 parent d7bec5f commit 2d7ac40

28 files changed

Lines changed: 517 additions & 199 deletions

‎.changeset/34257-one-step-invitation-acceptance.md‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ feat(auth): an invitation is accepted in one step with the proof its mail carrie
1212
Clause-②: yes (widening)
1313
Metadata-protocol: none
1414

15-
- **The invitation mail carries a mailbox proof.** The accept link in the mail carries a single-use proof bound to the invitation, its address and its expiry; a resend retires it. The proof is never at rest in clear, the stored mail row never holds the proof, and the console's copy-link action answers the link without it.
16-
- **One door redeems it.** `POST /api/v1/auth/organization/accept-invitation-with-proof` takes the invitation id, the proof, a name and a password. In one request it creates the account (or sets the password of an account whose address is not verified, ending every session that account had), verifies the address, accepts the invitation and signs in. A proof is single-use. A bad proof gets one `INVALID_TOKEN` refusal that does not say which check failed, and the real proof stays usable. The door is rate-limited per client address and per invitation, and runs the sign-up gates: who may sign up, password length, complexity and breach checks, SSO-only mode.
17-
- **An address with an account signs in as today.** When the address belongs to a verified account, an account with a linked provider, a second factor or a directory-managed account, the door answers `sign_in` and the proof stays unspent.
15+
- **The invitation mail carries a mailbox proof.** The accept link in the mail carries a single-use proof bound to the invitation, its address and its expiry; a resend retires it. The proof is never at rest in clear, the stored mail row never holds the proof, and the console's copy-link action answers the link without it. The invitation mail is sent inline, never through the durable mail queue, because the queue delivers from the stored row.
16+
- **One door redeems it.** `POST /api/v1/auth/organization/accept-invitation-one-step` takes the invitation id, the proof, a name and a password. In one request it creates the account (or sets the password of an account whose address is not verified, ending every session that account had with the reason a password reset records), verifies the address, accepts the invitation and signs in. The password-age stamp and the forced-change clear that every password change writes are written too. The proof is spent only by a request that passed every gate; one server process serializes concurrent redemptions of a proof, and across server processes single use is as strong as the store's consume. A bad proof gets one `INVALID_TOKEN` refusal that does not say which check failed, and the real proof stays usable. The door is rate-limited per client network address and per invitation, and runs the sign-up gates before anything is written: email sign-up switched off, SSO-only mode, password length, complexity and breach checks, a name for a new account, and who may sign up. A refused request leaves the proof usable.
17+
- **An address with an account signs in as today.** The door sets a password on an existing account only when the account's address is not verified and the mailbox is its one claim: an account that is verified, linked to a provider, enrolled in a second factor, provisioned by an identity provider, waiting for its first single sign-on or whose source cannot be read, or a server in SSO-only mode or with email and password off, answers `sign_in`, and the proof stays unspent.
18+
- **A cloud-managed environment refuses it.** With `OS_CLOUD_MANAGED=1` the door sets no local password: a request carrying a proof answers `409 RESOURCE_CONFLICT`, the cloud-managed refusal, before the proof is read. `CLOUD_MANAGED_REFUSAL_MESSAGES` gains the door's message. A process without the variable is unaffected.
1819
- **Without the proof, a session must hold the verified invited address.** Called with a session and no proof, the door accepts only when the session's address is the invited one and verified, and otherwise answers `verify_email`. A copied link still owes the verification mail.
19-
- **`SendTemplateInput.deliverOnly`** (`@objectstack/spec`): render values delivered with the message and never written to the stored mail row. A send carrying them is delivered inline, never through the durable queue. Only the server-side template send declares the key; `POST /email/send` and a script's `ctx.email.send` take a `SendEmailInput`, which has none.
20-
- **The accept page offers one form.** A signed-out visitor whose link carries the proof sees a name and password form, or a provider sign-in, in place of the sign-in redirect. The accept page does not keep the proof in its address. A provider sign-in returns to the page, which redeems the invitation for the new session. A link without the proof keeps today's path. The `@object-ui/auth` client gains `acceptInvitationWithProof`.
20+
- **`SendTemplateInput.deliverOnlyData`** (`@objectstack/spec`): render values delivered with the message and never written to the stored mail row, which gives no sign they were overlaid. Required template variables are checked against `data` alone. A send carrying them is delivered inline, never through the durable queue, so its sender gives up queued delivery where a queue is mounted. Only the server-side template send declares the key; `POST /email/send` and a script's `ctx.email.send` take a `SendEmailInput`, which has none.
21+
- **The accept page offers one form.** A signed-out visitor whose link carries the proof sees a name and password form, or a provider sign-in, in place of the sign-in redirect. The accept page does not keep the proof in its address. A provider sign-in returns to the page, which redeems the invitation for the new session. A link without the proof keeps today's path. The `@object-ui/auth` client gains `acceptInvitationOneStep`, with the types `AuthInvitationOneStepInput` and `AuthInvitationOneStepOutcome`.

‎docs/adr/0138-guest-model-anonymous-principal-doors-grants-and-organization.md‎

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -301,37 +301,41 @@ infrastructure. The same ruling's Q2 B leaves the verification posture as it was
301301
invitation-link sign-up still owes the verification mail.
302302

303303
**Amended 2026-11-16 — the one-step invitation acceptance and the OAuth client-name read, class-2-shaped doors.** Card
304-
[#34257](https://github.com/objectstack-ai/objectstack/issues/34257), on the owning seat's rulings in
305-
claim amendment
306-
[`6906424686`](https://github.com/objectstack-ai/objectstack/issues/34257#issuecomment-6906424686),
307-
admits one more door of class 2's shape, not a seventh class:
308-
`POST /api/v1/auth/organization/accept-invitation-with-proof`. What admits the request: the mailbox
309-
proof the invitation mail carries, a capability token minted per send. The invitation id alone, which
310-
the copied link and the invitation row carry, admits nothing. What it runs as: after validation, the
311-
creation of the invited address's account (or the replacement of the password of an unverified
312-
account with no linked provider account, revoking its sessions), the address marked verified, the
313-
invitation accepted through the vendor's own accept route, and a session for that account. The proof
314-
is never at rest in clear, the stored mail row never holds it, and it is single-use and bound to the
315-
invitation, its address and its expiry; a resend retires the old one. Every proof that does not admit
316-
gets one refusal that does not say which check failed. An address whose account is verified, is
317-
linked to a provider, or otherwise takes no password from this door is answered "sign in", with the
318-
proof unspent. It carries a rate limit per client address and per invitation, as ADR-0121 D6 requires.
319-
Enforced by `packages/plugins/plugin-auth/src/invitation-mailbox-proof.ts#buildInvitationProofDoorPlugin`,
320-
ledgered in `packages/plugins/plugin-auth/src/auth-route-ledger.ts`; it sits in the `/auth`
321-
namespace and is classified under class 2 the way the preview above is.
304+
[#34257](https://github.com/objectstack-ai/objectstack/issues/34257) admits one more door of class 2's shape, not a
305+
seventh class: `POST /api/v1/auth/organization/accept-invitation-one-step`. What admits the request: the mailbox
306+
proof the invitation mail carries, a capability token minted per send. The invitation id alone, which the copied link
307+
and the invitation row carry, admits nothing. What it runs as: after validation, the creation of the invited
308+
address's account (or the replacement of the password of an unverified account whose mailbox is its one claim,
309+
revoking its sessions), the address marked verified, the invitation accepted through the vendor's own accept route,
310+
and a session for that account. The proof is never at rest in clear, the stored mail row never holds it, and it is
311+
bound to the invitation, its address and its expiry; a resend retires the old one. It is spent only by a request that
312+
passed every gate, and one server process serializes concurrent redemptions of it; across processes, single use is
313+
as strong as the store's consume. Every proof that does not admit gets one refusal that does not say which check
314+
failed. An address whose account is verified, is linked to a provider, or otherwise takes no password from this door
315+
is answered "sign in", with the proof unspent. A cloud-managed environment sets no local password, so there the door
316+
refuses every request that carries a proof. It carries a rate limit per client network address and per invitation,
317+
as ADR-0121 D6 requires. Enforced by
318+
`packages/plugins/plugin-auth/src/invitation-mailbox-proof.ts#buildInvitationProofDoorPlugin`, ledgered in
319+
`packages/plugins/plugin-auth/src/auth-route-ledger.ts`. It is a better-auth endpoint, so it rides the `/auth`
320+
catch-all, which no route table lists door by door: the anonymous sweep's classification names it under class 2 as a
321+
door the catch-all serves, and probes it by its own path.
322322

323323
The same amendment admits a second door of class 2's shape, added by
324324
[#34168](https://github.com/objectstack-ai/objectstack/issues/34168):
325325
`GET /api/v1/auth/oauth2/client-name`, a public read. What admits the request: a request the server
326326
itself signed, which names one OAuth client. What it answers: that client's display name and nothing
327-
else, and only for the client the signed request names. Every other request gets one uniform 404.
328-
It is rate-limited per client address on the counter the invitation preview above uses, as ADR-0121 D6 requires.
329-
330-
This refines ruling [`6413975861`](https://github.com/objectstack-ai/objectstack/issues/26020#issuecomment-6413975861)
331-
Q2 B, recorded above as "an invitation-link sign-up still owes the verification mail". A
332-
proof-carrying invitation link proves the mailbox, so a sign-up through it owes no verification mail.
333-
A copied link, which carries no proof, still owes the verification mail, as Q2 B states. The vendor
334-
accept route is unchanged by this note.
327+
else, and only for the client the signed request names. Every request with a well-formed query that is
328+
not served a name gets one uniform 404; a malformed query answers 400, and a caller over the rate limit
329+
429. It is rate-limited per client network address on the counter the invitation preview above uses, as
330+
ADR-0121 D6 requires. Mounted ahead of the catch-all like the preview, it is classified under class 2 by
331+
its route.
332+
333+
This note states a refinement of ruling
334+
[`6413975861`](https://github.com/objectstack-ai/objectstack/issues/26020#issuecomment-6413975861) Q2 B, recorded
335+
above as "an invitation-link sign-up still owes the verification mail": a proof-carrying invitation link proves the
336+
mailbox, so a sign-up through it owes no verification mail, and a copied link, which carries no proof, still owes the
337+
verification mail, as Q2 B states. The refinement is the maintainer's to approve, on this note's Tier H hand-off;
338+
until that approval it binds nothing. The vendor accept route is unchanged by this note.
335339

336340
**Outside the guest model by construction**, and not on the list:
337341

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
* Nothing re-exports this module, so the published surface does not move.
5959
*/
6060

61-
import { ACCEPT_INVITATION_WITH_PROOF_PATH } from './invitation-mailbox-proof.js';
61+
import { ACCEPT_INVITATION_ONE_STEP_PATH } from './invitation-mailbox-proof.js';
6262
import { isCloudManaged } from '@objectstack/core';
6363
import { VENDOR_ROLE_SCALAR_ADMIN_PATHS } from './admin-impersonate-endpoint.js';
6464
import { setAuthActorResolver } from './auth-actor-attribution.js';
@@ -337,7 +337,7 @@ export async function globalBeforeHook(
337337
ctx?.path === '/sign-up/email' ||
338338
ctx?.path === '/reset-password' ||
339339
ctx?.path === '/change-password' ||
340-
ctx?.path === ACCEPT_INVITATION_WITH_PROOF_PATH
340+
ctx?.path === ACCEPT_INVITATION_ONE_STEP_PATH
341341
) {
342342
const candidate =
343343
(typeof ctx?.body?.password === 'string' && ctx.body.password) ||

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ export async function buildOrganizationPlugin(this: OrganizationPluginHost) {
659659
template: 'auth.invitation',
660660
to: recipientEmail,
661661
...mailLocale,
662-
...(proof ? { deliverOnly: { acceptUrl: withInvitationProof(acceptUrl, proof) } } : {}),
662+
...(proof ? { deliverOnlyData: { acceptUrl: withInvitationProof(acceptUrl, proof) } } : {}),
663663
data: {
664664
inviter: {
665665
name: inviter?.user?.name ?? inviter?.user?.email ?? 'A teammate',

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

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ import { resolveUserAuthzGrants } from '@objectstack/core';
6464
import { applyPlatformAdminImpersonation } from './admin-impersonate-endpoint.js';
6565
import { requireSecondFactorAtCodeAndLinkDoors } from './second-factor-code-and-link-doors.js';
6666
import { buildOrganizationPlugin, type OrganizationPluginHost } from './auth-manager-organization-plugin.js';
67-
import { ACCEPT_INVITATION_WITH_PROOF_PATH, buildInvitationProofDoorPlugin } from './invitation-mailbox-proof.js';
67+
import { ACCEPT_INVITATION_ONE_STEP_PATH, buildInvitationProofDoorPlugin } from './invitation-mailbox-proof.js';
6868
import {
6969
OAUTH_ORGANIZATION_CLAIM,
7070
assertScimAdminCoherence,
@@ -132,10 +132,29 @@ export interface PluginListHost {
132132
resolveAuthSecret: AuthManager['resolveAuthSecret'];
133133
resolveMembershipRole: AuthManager['resolveMembershipRole'];
134134
resolveTwoFactorAccountLockout: AuthManager['resolveTwoFactorAccountLockout'];
135+
stampPasswordChangedAt: AuthManager['stampPasswordChangedAt'];
135136
storedRecipientLocale: AuthManager['storedRecipientLocale'];
136137
validateAudienceAdmission: AuthManager['validateAudienceAdmission'];
137138
}
138139

140+
/**
141+
* better-auth's `haveIBeenPwned` default door list, as the installed vendor
142+
* declares it. Handing the plugin an explicit list replaces that default, so
143+
* the list the platform hands it is this one plus the one-step invitation
144+
* acceptance; the card's test reads the installed vendor default and pins the
145+
* two equal, so a vendor that grows its list reds that test instead of
146+
* silently losing the addition.
147+
*/
148+
export const BREACH_CHECK_VENDOR_DEFAULT_PATHS: readonly string[] = [
149+
'/sign-up/email',
150+
'/change-password',
151+
'/reset-password',
152+
'/email-otp/reset-password',
153+
'/phone-number/reset-password',
154+
'/admin/create-user',
155+
'/admin/set-user-password',
156+
];
157+
139158
/**
140159
* The body of `AuthManager.buildPluginList()`; the method's docblock and the
141160
* comments in it are its contract.
@@ -288,6 +307,7 @@ export async function buildPluginList(this: PluginListHost): Promise<any[]> {
288307
isSsoOnlyMode: () => this.isSsoOnlyMode(),
289308
getDataEngine: () => this.getDataEngine(),
290309
counterStore: () => this.config.sharedCounterStore?.() ?? Promise.reject(new Error('no shared counter store')),
310+
stampPasswordChangedAt: (userId) => this.stampPasswordChangedAt(userId),
291311
}));
292312
}
293313

@@ -314,18 +334,9 @@ export async function buildPluginList(this: PluginListHost): Promise<any[]> {
314334
if (enabled.passwordRejectBreached) {
315335
const { haveIBeenPwned } = await import('better-auth/plugins/haveibeenpwned');
316336
plugins.push(haveIBeenPwned({
317-
// The plugin's own default doors, plus the invitation proof door, which
318-
// sets a password too.
319-
paths: [
320-
'/sign-up/email',
321-
'/change-password',
322-
'/reset-password',
323-
'/email-otp/reset-password',
324-
'/phone-number/reset-password',
325-
'/admin/create-user',
326-
'/admin/set-user-password',
327-
ACCEPT_INVITATION_WITH_PROOF_PATH,
328-
],
337+
// The plugin's own default doors, plus the one-step invitation
338+
// acceptance, which sets a password too.
339+
paths: [...BREACH_CHECK_VENDOR_DEFAULT_PATHS, ACCEPT_INVITATION_ONE_STEP_PATH],
329340
customPasswordCompromisedMessage:
330341
'This password has appeared in a known data breach. Please choose a different one.',
331342
}));

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2449,6 +2449,7 @@ export class AuthManager {
24492449
resolveAuthSecret: (...a) => this.resolveAuthSecret(...a),
24502450
resolveMembershipRole: (...a) => this.resolveMembershipRole(...a),
24512451
resolveTwoFactorAccountLockout: (...a) => this.resolveTwoFactorAccountLockout(...a),
2452+
stampPasswordChangedAt: (...a) => this.stampPasswordChangedAt(...a),
24522453
storedRecipientLocale: (...a) => this.storedRecipientLocale(...a),
24532454
validateAudienceAdmission: (...a) => this.validateAudienceAdmission(...a),
24542455
};

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ import { cloudManagedRefusal } from './cloud-managed.js';
169169
import { identitySourceUnreadable, judgeSsoOnlyLocalPassword, readUserSource, ssoOnlyPasswordRefusal } from './sso-only-local-password.js';
170170
import { isPendingSsoSource, pendingSsoPasswordRefusal } from './pending-sso-marker.js';
171171
import { registerCopyInvitationLinkAction } from './invitation-link-action.js';
172+
import { ACCEPT_INVITATION_ONE_STEP_PATH } from './invitation-mailbox-proof.js';
172173
import {
173174
ALLOWED_IP_RANGES_ENV,
174175
allowedIpRangesWritePredicate,
@@ -2760,7 +2761,7 @@ export class AuthPlugin implements Plugin {
27602761
'/sign-up/email': { window, max },
27612762
'/request-password-reset': { window, max },
27622763
'/reset-password': { window, max },
2763-
'/organization/accept-invitation-with-proof': { window, max },
2764+
[ACCEPT_INVITATION_ONE_STEP_PATH]: { window, max },
27642765
// #2780 — OTP endpoints cost an SMS per hit (pumping abuse);
27652766
// the per-number cooldown (otp-send-guard.ts) is always on,
27662767
// this adds the operator-tuned per-IP dimension. The plugin

0 commit comments

Comments
 (0)