Skip to content

Commit ca290cc

Browse files
committed
fix(plugin-auth)!: an invited sign-up the posture's rule admits is refused when the declared set cannot be resolved
Ruling A: one rule for invited and uninvited self-registration. Adds the unresolvable-set pins for an invited sign-up under open and email_domain (on the allowlist) with the off-allowlist control, rewrites the presented-invitation row that pinned the removed branch, states the fail-closed refusal in the module doc and self-hosting.mdx, moves the changeset to a BREAKING narrowing, and registers the ADR-0087 semantic entry self-registration-permission-set-reaches-invited-sign-ups. Claude-Session: https://claude.ai/code/session_01FEkQ5pb2t8Z8C64PkPyVt1 Co-authored-by: Claude <noreply@anthropic.com>
1 parent 41d1882 commit ca290cc

6 files changed

Lines changed: 130 additions & 27 deletions

File tree

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
---
22
'@objectstack/plugin-auth': patch
3+
'@objectstack/spec': patch
34
---
45

5-
fix(plugin-auth): an invited sign-up the audience posture's own rule admits receives the declared self-registration permission set
6+
fix(plugin-auth)!: an invited sign-up the audience posture's own rule admits receives the declared self-registration permission set, and is refused when that set cannot be resolved
67

7-
Clause-②: yes (widening)
8+
Clause-②: no (narrowing)
89
Metadata-protocol: none
10+
Skills-docs: none — no skill under `skills/**` teaches the audience posture's invitation sign-up or `selfRegistrationPermissionSet`; `content/docs/deployment/self-hosting.mdx` gains the rule in this change.
911

10-
Under the `email_domain` audience posture, a self-serve sign-up whose address is on `allowedEmailDomains` is admitted by its domain, invitation or not; under `open`, every self-serve sign-up is. Such a sign-up now receives the declared `selfRegistrationPermissionSet` whether or not it also holds a pending invitation. Before, a pending invitation addressed to it was read ahead of the posture, and the sign-up was admitted with no self-registration grant, though the membership settle already treated an on-allowlist address as domain-admitted and bound it at creation. The admission verdict and the membership settle now read one classification of "admitted by the posture's rule".
12+
<!-- adr-0087: registered self-registration-permission-set-reaches-invited-sign-ups -->
1113

12-
The invitation still places the sign-up as it names: once the address is verified and the invitation accepted, the membership and role the invitation names are written beside the grant.
14+
**BREAKING** for a deployment under the `open` audience posture, or under `email_domain` for an address on `allowedEmailDomains`, whose declared `selfRegistrationPermissionSet` cannot be resolved (no such set, or the set is switched off) and that relies on an invited person still being able to sign up.
1315

14-
Unchanged: under `invite_only` an invitation admits with no self-registration grant; under `email_domain` an address off the allowlist that an invitation admitted gets the account and no grant, and is not bound while its address is unverified; operator, bootstrap and SSO-provider creations; a social-provider creation whose address the provider did not verify is still refused under `email_domain`, and under `open` while email verification is in force; an undeclared or unresolvable set still refuses the sign-up.
16+
- Under `open`, and under `email_domain` for an address on the allowlist, a self-serve sign-up is admitted by the posture's own rule, invitation or not. It now receives the declared `selfRegistrationPermissionSet` whether or not it also holds a pending invitation. Before, a pending invitation addressed to it was read ahead of the posture in `decideAudienceAdmission` (`audience-posture.ts`), and the sign-up was admitted with no self-registration grant, though the membership settle already treated it as admitted by the posture and bound it at creation. The verdict and the settle now read one classification, the module-private `isAdmittedByPostureRule`.
17+
- When the declared set cannot be resolved, such an invited sign-up is now refused `403 AUTH_CONFIG_ERROR`, naming the set, as an uninvited one already was. No account is created. Before, the invitation admitted it without the set.
18+
- The invitation still places the sign-up as it names: once the address is verified and the invitation accepted, the membership and role it names are written beside the grant.
1519

16-
No authorable key, accepted value or default changes; `selfRegistrationPermissionSet` keeps its meaning, the set each self-registrant receives, and is now applied to the invited sign-ups its posture admits.
20+
Unchanged: under `invite_only` an invitation admits with no self-registration grant; under `email_domain` an address off the allowlist that an invitation admitted gets the account and no grant, and is not bound while its address is unverified, whatever state the declared set is in; operator, bootstrap and SSO-provider creations; a social-provider creation whose address the provider did not verify is still refused under `email_domain`, and under `open` while email verification is in force; `admin_full_access` is still refused as the self-registration set.
21+
22+
No authorable key, accepted value or default changes; `selfRegistrationPermissionSet` keeps its meaning, the set each self-registrant receives, and now reaches the invited sign-ups its posture admits.
23+
24+
What to do: keep `selfRegistrationPermissionSet` naming a permission set that exists and is switched on. A person refused this way signs up again once an administrator has corrected the setting or switched the set on, or an administrator creates the account directly. An invitation can expire while the set is broken; send it again after the fix.

‎content/docs/deployment/self-hosting.mdx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,17 @@ Once the provider verifies the address, the next sign-in is admitted.
795795
Under `open` every address is admitted by the posture, invitation or not, so an
796796
invited sign-up likewise receives the declared set beside its invitation.
797797

798+
**A sign-up the posture admits needs its declared set, invited or not.** When
799+
`selfRegistrationPermissionSet` cannot be resolved (no such set, or the set is
800+
switched off), every sign-up the posture's own rule admits is refused
801+
`403 AUTH_CONFIG_ERROR`, and the message names the set: any address under
802+
`open`, an address on the list under `email_domain`, with or without a pending
803+
invitation. Nothing is created, and the deployment logs the same reason at
804+
error level. Correct the setting, or switch the set on, and the next sign-up is
805+
admitted. A pending invitation does not admit such a sign-up without the set.
806+
The two admissions an invitation makes alone, under `invite_only` and for an
807+
address off the list under `email_domain`, ask for no set and are unaffected.
808+
798809
**Accepting, declining and listing an invitation need a verified email
799810
address, on every deployment.** The invitation's `id`, which its link carries,
800811
proves nothing about the mailbox. From a session whose address is not

‎packages/plugins/plugin-auth/src/audience-posture.test.ts‎

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,47 @@ describe('end of the chain: better-auth pipeline over the memory engine (#11739)
949949
expect((engine.tables.get('sys_user') ?? []).length).toBe(1);
950950
});
951951

952+
// An invited sign-up the posture's own rule admits is a self-registrant: it
953+
// asks for the declared set like an uninvited one, so a set that cannot be
954+
// resolved refuses it too. The invitation does not admit it without the grant.
955+
it.each([
956+
['open', 'missing', { posture: 'open' }, 'invited@anywhere.com'],
957+
['open', 'switched off', { posture: 'open' }, 'invited@anywhere.com'],
958+
['email_domain (on the allowlist)', 'missing', { posture: 'email_domain', allowedEmailDomains: ['acme.com'] }, 'invited@acme.com'],
959+
['email_domain (on the allowlist)', 'switched off', { posture: 'email_domain', allowedEmailDomains: ['acme.com'] }, 'invited@acme.com'],
960+
] as const)('%s: an invited sign-up whose declared set is %s is refused AUTH_CONFIG_ERROR, like an uninvited one', async (_posture, state, posture, email) => {
961+
const engine = createMemoryEngine();
962+
seedExistingUser(engine);
963+
if (state === 'switched off') {
964+
seedPermissionSet(engine, 'member_default');
965+
engine.tables.set('sys_metadata_activation', [
966+
{ id: 'act_member', metadata_type: 'permission', name: 'member_default', package_id: 'pkg', active: false },
967+
]);
968+
}
969+
seedPendingInvitation(engine, email);
970+
const set = state === 'missing' ? 'ghost' : 'member_default';
971+
const manager = makeManager(engine, { audience: { ...posture, selfRegistrationPermissionSet: set } });
972+
const res = await signUp(manager, email);
973+
expect(res.status).toBe(403);
974+
const body = await res.json();
975+
expect(body.code).toBe(AUDIENCE_CONFIG_ERROR);
976+
expect(String(body.message)).toContain(`'${set}'`);
977+
expect((engine.tables.get('sys_user') ?? []).length).toBe(1);
978+
});
979+
980+
it('CONTROL: email_domain, an invited sign-up OFF the allowlist is admitted by its invitation alone, asking for no set, so a missing set does not refuse it', async () => {
981+
const engine = createMemoryEngine();
982+
seedExistingUser(engine);
983+
seedPendingInvitation(engine, 'contractor@external.com');
984+
const manager = makeManager(engine, {
985+
audience: { posture: 'email_domain', allowedEmailDomains: ['acme.com'], selfRegistrationPermissionSet: 'ghost' },
986+
});
987+
const res = await signUp(manager, 'contractor@external.com');
988+
expect(res.status, await res.clone().text()).toBeLessThan(300);
989+
expect((engine.tables.get('sys_user') ?? []).length).toBe(2);
990+
expect(engine.tables.get('sys_user_permission_set') ?? []).toEqual([]);
991+
});
992+
952993
it('[ADR-0131 D3] the set ROW\'s `active` switches nothing: a row flagged off still admits and grants', async () => {
953994
// The resolver reads no catalog row, so the row flag is not a deactivation.
954995
const engine = createMemoryEngine();

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,13 @@
6161
* `email_domain` an explicit invitation also trumps the domain list — an
6262
* operator inviting an external contractor must not dead-end them), except a
6363
* social-provider creation whose address the provider did not verify under a
64-
* posture whose admission rests on the address (below). Without
65-
* this carve-out the posture would be "admin-create only" and the invitation
66-
* surface would be dead for new users — the invite dead-end class.
64+
* posture whose admission rests on the address (below), and except a creation
65+
* the posture's own rule already admits ({@link isAdmittedByPostureRule}): that
66+
* one is a self-registrant, invitation or not, so it asks for the declared
67+
* self-registration set and is refused with the uninvited sign-up when the set
68+
* cannot be resolved — the invitation does not admit it without the grant.
69+
* Without this carve-out the posture would be "admin-create only" and the
70+
* invitation surface would be dead for new users — the invite dead-end class.
6771
*
6872
* What "holding" means is {@link invitationProofFor}'s answer. Under
6973
* `invite_only` a self-serve sign-up is admitted only by the invitation it
@@ -125,7 +129,8 @@
125129
* ("a valid posture said no") because sending the debugger to re-read a
126130
* setting that looks exactly as they left it is the recorded failure mode. A
127131
* declared permission set that cannot be resolved refuses admission the same
128-
* way: admitting a self-registrant WITHOUT the declared grant would be the
132+
* way, for every sign-up the posture's rule admits, invited or not: admitting
133+
* a self-registrant WITHOUT the declared grant would be the
129134
* ADR-0078 "declared but inert" defect at runtime, and fail-open is the one
130135
* direction this gate must never take.
131136
*/

‎packages/plugins/plugin-auth/src/presented-invitation.test.ts‎

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ describe('under invite_only, the other creation doors', () => {
345345
});
346346
});
347347

348-
describe('open and email_domain match an invitation by address, as before', () => {
348+
describe('email_domain matches an invitation by address, as before', () => {
349349
const gate = (manager: AuthManager, email: string) =>
350350
(manager as unknown as {
351351
validateAudienceAdmission(data: unknown, ctx?: unknown): Promise<{ error: string } | undefined>;
@@ -354,20 +354,23 @@ describe('open and email_domain match an invitation by address, as before', () =
354354
{ body: {} },
355355
);
356356

357-
// Under `open` an uninvited sign-up is admitted WITH the declared set, which
358-
// this store cannot resolve (it would answer AUTH_CONFIG_ERROR), and under
359-
// `email_domain` this address is off the list: so `undefined` below can only
360-
// be the invitation carve-out, matched by address.
361-
for (const audience of [
362-
{ posture: 'open', selfRegistrationPermissionSet: 'member_default' },
363-
{ posture: 'email_domain', allowedEmailDomains: ['elsewhere.example'], selfRegistrationPermissionSet: 'member_default' },
364-
]) {
365-
it(`${audience.posture}: an email-and-password sign-up holding an invitation is admitted with no id`, async () => {
366-
const d = await deployment();
367-
await d.invite(INVITEE);
368-
const manager = makeManager(d.engine, { audience });
369-
expect(await gate(manager, INVITEE)).toBeUndefined();
370-
expect((await gate(manager, OTHER))?.error).not.toBeUndefined();
371-
});
372-
}
357+
// This address is off the list, and this store cannot resolve the declared
358+
// set (a sign-up the posture's rule admits would answer AUTH_CONFIG_ERROR):
359+
// so `undefined` below can only be the invitation carve-out, matched by
360+
// address, which asks for no set. Under `open` the posture's rule admits
361+
// every address, so an invitation decides nothing there: an invited sign-up
362+
// asks for the declared set like an uninvited one, and an unresolvable set
363+
// refuses both (`audience-posture.test.ts`, the end of the chain).
364+
const audience = {
365+
posture: 'email_domain',
366+
allowedEmailDomains: ['elsewhere.example'],
367+
selfRegistrationPermissionSet: 'member_default',
368+
};
369+
it('email_domain: an email-and-password sign-up off the list holding an invitation is admitted with no id', async () => {
370+
const d = await deployment();
371+
await d.invite(INVITEE);
372+
const manager = makeManager(d.engine, { audience });
373+
expect(await gate(manager, INVITEE)).toBeUndefined();
374+
expect((await gate(manager, OTHER))?.error).not.toBeUndefined();
375+
});
373376
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
import type { SemanticMigration } from '../../types.js';
4+
5+
// The upgrade-guide entry of the change of meaning the plugin-auth admission
6+
// verdict landed (ruling record 7063136215, option A): one rule for an invited
7+
// and an uninvited self-registration. No key of any schema is added, removed,
8+
// renamed or re-shaped, so there is no tombstone and no D2 conversion: whether
9+
// the declared set is the one an invited person should receive, and repairing
10+
// a set that cannot be resolved, are the operator's to judge.
11+
export const entry: SemanticMigration = {
12+
id: 'self-registration-permission-set-reaches-invited-sign-ups',
13+
surface:
14+
'system.AuthConfig.audience.selfRegistrationPermissionSet under the `open` posture, and under `email_domain` '
15+
+ 'for an address on `allowedEmailDomains`: a self-serve sign-up that also holds a pending invitation',
16+
replacement:
17+
'Keep `selfRegistrationPermissionSet` naming a permission set that exists and is switched on, and confirm it '
18+
+ 'is the access an invited person the posture admits should hold beside the membership and role the '
19+
+ 'invitation names. A person who must join without that set is created by an administrator instead',
20+
reason:
21+
'The admission verdict read a pending invitation before the posture\'s own rule, so an invited sign-up the '
22+
+ 'posture admits (any address under `open`, an address on the allowlist under `email_domain`) was admitted '
23+
+ 'with no self-registration grant, whether or not the declared set could be resolved, while the membership '
24+
+ 'settle already classified the same sign-up as admitted by the posture. It is now a self-registrant, '
25+
+ 'invitation or not: it receives the declared set, and when the set cannot be resolved (not in the security '
26+
+ 'catalog, or switched off in the activation ledger) it is refused 403 AUTH_CONFIG_ERROR like an uninvited '
27+
+ 'sign-up; no account is created. Unchanged: under `invite_only`, and for an address off the allowlist under '
28+
+ '`email_domain`, an invitation admits by itself and asks for no set. There is no mechanical rewrite: which '
29+
+ 'set the operator meant is not in the stack',
30+
acceptanceCriteria:
31+
'Under the deployment\'s posture, an invited sign-up whose address the posture admits completes sign-up and '
32+
+ 'holds the declared set (a `sys_user_permission_set` row naming it) beside the membership its accepted '
33+
+ 'invitation writes, and with the set name pointed at a set that does not exist the same sign-up answers '
34+
+ '403 AUTH_CONFIG_ERROR naming the set',
35+
};

0 commit comments

Comments
 (0)