Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
70706ba
feat(email): deliver-only template values never reach the stored mail…
claude Nov 16, 2026
cca4679
feat(auth): the invitation mail carries a mailbox proof that one door…
claude Nov 16, 2026
ee8037c
test(auth): pin one-step invitation acceptance rules
claude Nov 16, 2026
5e664ba
fix(auth): the one-step door answers the standard rate-limit code
claude Nov 16, 2026
e6df379
docs(adr): ADR-0138 notes the one-step invitation acceptance door
claude Nov 16, 2026
be7d4b0
feat(ui-auth): the auth client redeems an invitation in one step
claude Nov 16, 2026
fa8bbd6
feat(app-shell): the accept page offers one form to a visitor holding…
claude Nov 16, 2026
2a24099
chore(changeset): one-step invitation acceptance
claude Nov 16, 2026
4427a90
Merge origin/main into claude/area-A1-34257
claude Nov 16, 2026
85b6f0a
test(auth): the plugin list carries the one-step door; a redeemed pro…
claude Nov 16, 2026
5a3f2c1
test(auth): annotate the one-step harness matcher's return type
claude Nov 16, 2026
bb6f322
docs(adr): ADR-0138 names the OAuth client-name read beside the one-s…
claude Nov 16, 2026
16d71d9
fix(auth): the one-step door answers registered codes; its test doubl…
claude Nov 16, 2026
ec9f03b
fix(auth): the one-step door answers in the envelope
claude Nov 16, 2026
fcc0f01
Merge origin/main into claude/area-A1-34257
claude Nov 16, 2026
9b95ba9
chore(changeset): state the one-step acceptance at rule level
claude Nov 16, 2026
fbe5bfd
test(auth): pin every gate of the invitation proof door
claude Nov 16, 2026
d7bec5f
docs(auth): name the door's rate limit per client address
claude Nov 16, 2026
2d7ac40
feat(auth): close the one-step door on a managed environment, stamp i…
claude Nov 16, 2026
4de8ae8
test(auth): make the mismatched proof always differ from the real one
claude Nov 16, 2026
b60bbe4
Merge remote-tracking branch 'origin/main' into claude/area-A1-34257
claude Nov 16, 2026
0e8a0d3
fix(auth): the one-step door's closing rule is an allow-list, and it …
claude Nov 16, 2026
518f1d6
fix(auth): standing grants count as claims in the one-step door's clo…
claude Nov 16, 2026
25e5034
Merge remote-tracking branch 'origin/main' into claude/area-A1-34257
claude Nov 16, 2026
3e35729
fix(auth): every user-keyed store the plugin mounts is classified for…
claude Nov 16, 2026
3c49959
test(auth): pin the one-step door's claim stores by name
claude Nov 16, 2026
bdc4812
fix(auth): the one-step door reads a sign-in identity on the user row…
claude Nov 16, 2026
7774f4a
test(auth): pin the user row reading of the one-step door
claude Nov 16, 2026
1022695
Merge origin/main into claude/area-A1-34257
claude Nov 16, 2026
2633dc1
fix(auth): the one-step door takes every reading again once the sessi…
claude Nov 16, 2026
9bb1e6a
test(auth): a proof spent after admission revokes no session at the o…
claude Nov 16, 2026
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
23 changes: 23 additions & 0 deletions .changeset/34257-one-step-invitation-acceptance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
'@objectstack/spec': patch
'@objectstack/plugin-email': patch
'@objectstack/plugin-auth': patch
'@objectstack/platform-objects': patch
'@object-ui/auth': patch
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
---

feat(auth): an invitation is accepted in one step with the proof its mail carries

Clause-②: yes (widening)
Metadata-protocol: none

- **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.
- **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, in an order that matches the vendor's order), 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. On an account whose password it replaces, the password history is consulted before the proof is spent and extended after, as the reset door does. 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.
- **An address with an account signs in as today.** The door sets a password on an existing account only when it reads all of these: the address is not verified; the account's only sign-in account is its email and password one, or it has none; it has no second factor, enabled or enrolled; its user row holds no phone number, verified or not; it holds no standing grant (an API key, an OAuth client consent, an OAuth access or refresh token, an OAuth client, a device authorization, an SSO provider, a SCIM credential or a link to an identity provider's directory, revoked or expired ones included); its identity source is local; and the server allows a local password here (not SSO-only, email and password on). Every other account answers `sign_in`, including one in a state no rule names and one whose reading fails, and the proof stays unspent. Every reading is taken again once the account's sessions are revoked and before the password is written; an account that no longer passes then answers `sign_in` with its sessions revoked, and the proof stays unspent. Every store this plugin mounts that is keyed by a user, and every column of the vendor's user model with every plugin this plugin can mount, is classified as a claim the judge reads or as no claim, and a test holds each classification to what is mounted. The classification covers what this plugin mounts and nothing another package mounts.
- **`sys_device_code` gains an index on `user_id`** (`@objectstack/platform-objects`), so the door reads a user's device authorizations by an indexed lookup, as it reads every other standing grant.
- **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.
- **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.
- **`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.
- **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`.
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,53 @@ under class 2, ahead of the allowlist, so it is judged as this door and not as c
infrastructure. The same ruling's Q2 B leaves the verification posture as it was: an
invitation-link sign-up still owes the verification mail.

**Amended 2026-11-16 — the one-step invitation acceptance and the OAuth client-name read, class-2-shaped doors.** Card
[#34257](https://github.com/objectstack-ai/objectstack/issues/34257) admits one more door of class 2's shape, not a
seventh class: `POST /api/v1/auth/organization/accept-invitation-one-step`. What admits the request: the mailbox proof
the invitation mail carries, a capability token minted per send. The invitation id alone, which the copied link and
the invitation row carry, admits nothing. What it runs as: after validation, the creation of the invited address's
account (or the replacement of the password of an unverified account the rule below admits, revoking its sessions),
the address marked verified, the invitation accepted through the vendor's own accept route, and a session for that
account. The proof is never at rest in clear, the stored mail row never holds it, and it is bound to the invitation,
its address and its expiry; a resend retires the old one. It is spent only by a request that passed every gate, and
one server process serializes concurrent redemptions of it; across processes, single use is as strong as the store's
consume. Every proof that does not admit gets one refusal that does not say which check failed. The door sets a
password on an existing account only when it reads all of these: the address is not verified; the account's only
sign-in account is its email and password one, or it has none; it has no second factor, enabled or enrolled; its user
row holds no phone number, verified or not; it holds no standing grant (an API key, an OAuth client consent, an OAuth
access or refresh token, an OAuth client, a device authorization, an SSO provider, a SCIM credential or a link to an
identity provider's directory, revoked or expired ones included); its identity source is local; and the server allows
a local password here (not SSO-only, email and password on). Every other account answers `sign_in`, including one in a
state no rule names and one whose reading fails, and the proof stays unspent. Every reading is taken again once the
account's sessions are revoked and before the password is written; an account that no longer passes then answers
`sign_in` with its sessions revoked, and the proof stays unspent. Every store this plugin mounts that is
keyed by a user, and every column of the vendor's user model with every plugin this plugin can mount, is classified as
a claim the judge reads or as no claim, and a test holds each classification to what is mounted. The classification
covers what this plugin mounts and nothing another package mounts. A cloud-managed environment sets no local password,
so there the door refuses every request that carries a proof. It carries a rate limit per client network address and
per invitation, as ADR-0121 D6 requires. Enforced by
`packages/plugins/plugin-auth/src/invitation-mailbox-proof.ts#buildInvitationProofDoorPlugin`, ledgered in
`packages/plugins/plugin-auth/src/auth-route-ledger.ts`. It is a better-auth endpoint, so it rides the `/auth`
catch-all, which no route table lists door by door: the anonymous sweep's classification names it under class 2 as a
door the catch-all serves, and probes it by its own path.

The same amendment admits a second door of class 2's shape, added by
[#34168](https://github.com/objectstack-ai/objectstack/issues/34168):
`GET /api/v1/auth/oauth2/client-name`, a public read. What admits the request: a request the server
itself signed, which names one OAuth client. What it answers: that client's display name and nothing
else, and only for the client the signed request names. Every request with a well-formed query that is
not served a name gets one uniform 404; a malformed query answers 400, and a caller over the rate limit
429. It is rate-limited per client network address on the counter the invitation preview above uses, as
ADR-0121 D6 requires. Mounted ahead of the catch-all like the preview, it is classified under class 2 by
its route.

This note states a refinement of ruling
[`6413975861`](https://github.com/objectstack-ai/objectstack/issues/26020#issuecomment-6413975861) Q2 B, recorded
above as "an invitation-link sign-up still owes the verification mail": a proof-carrying invitation link proves the
mailbox, so a sign-up through it owes no verification mail, and a copied link, which carries no proof, still owes the
verification mail, as Q2 B states. The refinement is the maintainer's to approve, on this note's Tier H hand-off;
until that approval it binds nothing. The vendor accept route is unchanged by this note.

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

- the control-plane allowlist (`packages/core/src/security/auth-gate.ts#isAuthGateAllowlisted`:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ export const SysDeviceCode = ObjectSchema.create({
{ fields: ['device_code'], unique: 'global' },
{ fields: ['user_code'], unique: 'global' },
{ fields: ['status'], unique: false },
// The one-step invitation door reads a user's device authorizations by
// this column (`plugin-auth` `invitation-mailbox-proof.ts`).
{ fields: ['user_id'], unique: false },
],

enable: {
Expand Down
4 changes: 3 additions & 1 deletion packages/plugins/plugin-auth/src/auth-manager-before-hook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
* Nothing re-exports this module, so the published surface does not move.
*/

import { ACCEPT_INVITATION_ONE_STEP_PATH } from './invitation-mailbox-proof.js';
import { isCloudManaged } from '@objectstack/core';
import { VENDOR_ROLE_SCALAR_ADMIN_PATHS } from './admin-impersonate-endpoint.js';
import { setAuthActorResolver } from './auth-actor-attribution.js';
Expand Down Expand Up @@ -360,7 +361,8 @@ export async function globalBeforeHook(
if (
ctx?.path === '/sign-up/email' ||
ctx?.path === '/reset-password' ||
ctx?.path === '/change-password'
ctx?.path === '/change-password' ||
ctx?.path === ACCEPT_INVITATION_ONE_STEP_PATH
) {
const candidate =
(typeof ctx?.body?.password === 'string' && ctx.body.password) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
* Nothing re-exports this module, so the published surface does not move.
*/

import { mintInvitationProof, withInvitationProof } from './invitation-mailbox-proof.js';
import type { OrganizationOptions } from 'better-auth/plugins/organization';
import { isCloudManaged } from '@objectstack/core';
import { MEMBERSHIP_ROLE_DELEGATED_ADMIN, MEMBERSHIP_ROLE_EXTERNAL } from '@objectstack/spec';
Expand Down Expand Up @@ -647,11 +648,18 @@ export async function buildOrganizationPlugin(this: OrganizationPluginHost) {
if (this.config.logger) this.config.logger.warn(msg, meta);
else console.warn(msg, meta);
}
// [#34257] The mail's link carries the invitation's mailbox proof; the
// copied link and the stored mail row never do. Minted only for a send
// that goes out; one that cannot be minted goes out as today's link.
const proof = expiry.expiresAt === undefined
? undefined
: await mintProofForSend({ id: String(invitation.id), email: recipientEmail, expiresAt: invitation.expiresAt });
try {
await emailService.sendTemplate({
template: 'auth.invitation',
to: recipientEmail,
...mailLocale,
...(proof ? { deliverOnlyData: { acceptUrl: withInvitationProof(acceptUrl, proof) } } : {}),
data: {
inviter: {
name: inviter?.user?.name ?? inviter?.user?.email ?? 'A teammate',
Expand Down Expand Up @@ -736,6 +744,28 @@ export async function buildOrganizationPlugin(this: OrganizationPluginHost) {
* than rendered as `Invalid Date`; the template declares the variable
* required, so that send is refused rather than sent with a dangling sentence.
*/
/**
* Mint the invitation's mailbox proof through the verification store of the
* request that sends the mail (better-auth calls `sendInvitationEmail` inside
* invite-member, a resend included). No endpoint context, or a store that
* refuses the write: no proof, and the mail carries today's link.
*/
async function mintProofForSend(invitation: { id: string; email: string; expiresAt: unknown }): Promise<string | undefined> {
try {
const { getCurrentAuthEndpointContext } = await import('@better-auth/core/context');
const ctx: any = getCurrentAuthEndpointContext();
const store = ctx?.context?.internalAdapter;
if (!store) return undefined;
return await mintInvitationProof(store, invitation);
} catch (err: any) {
console.warn(
`[AuthManager] invitation mail: no mailbox proof for invitation '${invitation.id}' (${err?.message ?? err}); ` +
'the mail carries the accept link without it',
);
return undefined;
}
}

function invitationExpiryArg(expiresAt: unknown): { expiresAt?: string } {
if (!(expiresAt instanceof Date) && typeof expiresAt !== 'string' && typeof expiresAt !== 'number') return {};
const instant = new Date(expiresAt);
Expand Down
40 changes: 40 additions & 0 deletions packages/plugins/plugin-auth/src/auth-manager-plugin-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import { resolveUserAuthzGrants } from '@objectstack/core';
import { applyPlatformAdminImpersonation } from './admin-impersonate-endpoint.js';
import { requireSecondFactorAtCodeAndLinkDoors } from './second-factor-code-and-link-doors.js';
import { buildOrganizationPlugin, type OrganizationPluginHost } from './auth-manager-organization-plugin.js';
import { ACCEPT_INVITATION_ONE_STEP_PATH, buildInvitationProofDoorPlugin } from './invitation-mailbox-proof.js';
import {
OAUTH_ORGANIZATION_CLAIM,
assertScimAdminCoherence,
Expand Down Expand Up @@ -121,17 +122,41 @@ export interface PluginListHost {
getDataEngine: AuthManager['getDataEngine'];
getEmailService: AuthManager['getEmailService'];
getMcpResourceUrl: AuthManager['getMcpResourceUrl'];
getApi: AuthManager['getApi'];
isPlatformAdminUserId: AuthManager['isPlatformAdminUserId'];
isSsoOnlyMode: AuthManager['isSsoOnlyMode'];
jwtSigningFailureReported: AuthManager['jwtSigningFailureReported'];
multiOrgPostureEffective: AuthManager['multiOrgPostureEffective'];
orgRolesMap: AuthManager['orgRolesMap'];
reconcileScimUserLifecycle: AuthManager['reconcileScimUserLifecycle'];
resolveAuthSecret: AuthManager['resolveAuthSecret'];
resolveMembershipRole: AuthManager['resolveMembershipRole'];
resolveTwoFactorAccountLockout: AuthManager['resolveTwoFactorAccountLockout'];
assertPasswordNotReused: AuthManager['assertPasswordNotReused'];
recordPasswordHistory: AuthManager['recordPasswordHistory'];
stampPasswordChangedAt: AuthManager['stampPasswordChangedAt'];
storedRecipientLocale: AuthManager['storedRecipientLocale'];
validateAudienceAdmission: AuthManager['validateAudienceAdmission'];
}

/**
* better-auth's `haveIBeenPwned` default door list, as the installed vendor
* declares it. Handing the plugin an explicit list replaces that default, so
* the list the platform hands it is this one plus the one-step invitation
* acceptance; the card's test reads the installed vendor default and pins the
* two equal, so a vendor that grows its list reds that test instead of
* silently losing the addition.
*/
export const BREACH_CHECK_VENDOR_DEFAULT_PATHS: readonly string[] = [
'/sign-up/email',
'/change-password',
'/reset-password',
'/email-otp/reset-password',
'/phone-number/reset-password',
'/admin/create-user',
'/admin/set-user-password',
];

/**
* The body of `AuthManager.buildPluginList()`; the method's docblock and the
* comments in it are its contract.
Expand Down Expand Up @@ -276,6 +301,18 @@ export async function buildPluginList(this: PluginListHost): Promise<any[]> {
};
return buildOrganizationPlugin.call(host);
});
// [#34257] The one-step acceptance door for the invitation mail's mailbox
// proof (`invitation-mailbox-proof.ts`), beside the plugin it accepts through.
plugins.push(await buildInvitationProofDoorPlugin({
getApi: () => this.getApi(),
validateAudienceAdmission: (...a) => this.validateAudienceAdmission(...(a as Parameters<AuthManager['validateAudienceAdmission']>)),
isSsoOnlyMode: () => this.isSsoOnlyMode(),
getDataEngine: () => this.getDataEngine(),
counterStore: () => this.config.sharedCounterStore?.() ?? Promise.reject(new Error('no shared counter store')),
stampPasswordChangedAt: (userId) => this.stampPasswordChangedAt(userId),
assertPasswordNotReused: (userId, candidate, verify) => this.assertPasswordNotReused(userId, candidate, verify),
recordPasswordHistory: (userId, oldHash) => this.recordPasswordHistory(userId, oldHash),
}));
}

if (enabled.twoFactor) {
Expand All @@ -301,6 +338,9 @@ export async function buildPluginList(this: PluginListHost): Promise<any[]> {
if (enabled.passwordRejectBreached) {
const { haveIBeenPwned } = await import('better-auth/plugins/haveibeenpwned');
plugins.push(haveIBeenPwned({
// The plugin's own default doors, plus the one-step invitation
// acceptance, which sets a password too.
paths: [...BREACH_CHECK_VENDOR_DEFAULT_PATHS, ACCEPT_INVITATION_ONE_STEP_PATH],
customPasswordCompromisedMessage:
'This password has appeared in a known data breach. Please choose a different one.',
}));
Expand Down
12 changes: 9 additions & 3 deletions packages/plugins/plugin-auth/src/auth-manager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,13 @@ describe('AuthManager', () => {
warnSpy.mockRestore();

// [#28367] The agent forward view rides right after bearer(), on every instance.
expect(capturedConfig.plugins.map((p: any) => p.id)).toEqual(['bearer', 'objectstack-agent-forward-identity-view', 'organization']);
// [#34257] The one-step invitation door rides right after organization().
expect(capturedConfig.plugins.map((p: any) => p.id)).toEqual([
'bearer',
'objectstack-agent-forward-identity-view',
'organization',
'invitation-mailbox-proof',
]);
});

it('should register organization plugin with schema mapping when enabled', async () => {
Expand Down Expand Up @@ -1635,9 +1641,9 @@ describe('AuthManager', () => {
await manager.getAuthInstance();
warnSpy.mockRestore();

expect(capturedConfig.plugins).toHaveLength(5);
expect(capturedConfig.plugins).toHaveLength(6);
expect(capturedConfig.plugins.map((p: any) => p.id).sort()).toEqual(
['bearer', 'magic-link', 'objectstack-agent-forward-identity-view', 'organization', 'two-factor'],
['bearer', 'invitation-mailbox-proof', 'magic-link', 'objectstack-agent-forward-identity-view', 'organization', 'two-factor'],
);
});
});
Expand Down
Loading
Loading