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
21 changes: 21 additions & 0 deletions .changeset/social-creation-needs-provider-verified-address.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
'@objectstack/plugin-auth': patch
---

fix(plugin-auth)!: a self-serve social creation is admitted only with a provider-verified address under an address-based posture

Clause-②: no (narrowing: a creation admitted today is refused; owes one CONTRACT_REVIEW_TIER review before the queue)
Metadata-protocol: none
Skills-docs: none — no skill under `skills/**` teaches the audience posture or a social-provider sign-in; `content/docs/permissions/authentication.mdx` and `content/docs/deployment/tenancy-modes.mdx` gain the rule in this change.

<!-- adr-0087: not-required (no-migration-prescription) No schema key, accepted value or metadata type is added, removed, renamed or re-shaped. The moved answer is an account the admission gate does not create, so there is nothing stored for a migration to rewrite and no tombstone. -->

**BREAKING** for a deployment under the `email_domain` audience posture, or under `open` while email verification is in force, where people create their account by signing in through a social provider that reports the address unverified.

- Under `email_domain`, and under `open` while email verification is in force (the default there; only the deployment can declare it off), a new account through a social provider (`socialProviders`) is created only when the provider reports the address verified. Any other is refused `403 SELF_REGISTRATION_CLOSED` at the admission gate, as `invite_only` already refuses it: no account, no session, no membership. A browser sign-in redirects with `error=SELF_REGISTRATION_CLOSED`.
- A pending invitation addressed to that person does not admit the creation either, under both postures: the invitation is matched by the same address.
- The rule is told by the creation class, not by a list of providers, so a social provider added later is covered without being named.

Unchanged: a social provider that reports the address verified, which is admitted and bound as before; identity providers an operator registers (`oidcProviders` entries and SSO providers); accounts an administrator creates, SCIM provisioning and accounts a boot command provisions; the first account of a fresh install; email-and-password, magic-link and email-OTP sign-ups; `open` with the deployment's email verification declared off; and the `invite_only` posture.

What to do: a person refused this way verifies the address with the social provider and signs in again, or, where the deployment offers it, signs up with email and password and completes the verification mail. An invited person can also open the invitation mail's own link, which verifies the address and accepts in one step.
13 changes: 12 additions & 1 deletion content/docs/deployment/self-hosting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,12 @@ posture, and while the account's address is unverified it joins no
organization: it joins by accepting the invitation once the address is
verified, and the acceptance writes the membership the invitation names. Verifying the address binds nothing by itself.
An address on the list is admitted by its domain, invitation or not, and the
membership policy binds it at creation as before.
membership policy binds it at creation as before. Both admissions have one
exception: under this posture a sign-in through a social provider creates an
account only when the provider reports the address verified, and is otherwise
refused `403 SELF_REGISTRATION_CLOSED`, whatever the list or an invitation
says ([Authentication](/docs/permissions/authentication#2-handle-callback)).
Once the provider verifies the address, the next sign-in is admitted.

**Accepting, declining and listing an invitation need a verified email
address, on every deployment.** The invitation's `id`, which its link carries,
Expand Down Expand Up @@ -861,6 +866,12 @@ on `open`, keep verification on and connect a mail transport.
`emailAndPassword.requireEmailVerification: false` in the stack config. A
sign-up is then signed in at once and no verification mail is sent.

Under `email_domain`, and under `open` while verification is in force, a new
account through a social provider is created only when the provider reports
the address verified; otherwise the sign-in is refused
`403 SELF_REGISTRATION_CLOSED` and nothing is written
([Authentication](/docs/permissions/authentication#2-handle-callback)).

The `open` opt-out is for a deployment with no mail transport that trusts
whoever can reach it, such as a pre-production environment. It is loud and it
has a cost:
Expand Down
6 changes: 5 additions & 1 deletion content/docs/deployment/tenancy-modes.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,11 @@ The reconciler:
invitation addressed to it admitted: that account joins by accepting the
invitation, which needs a verified address
([Self-hosting](/docs/deployment/self-hosting)). Under `email_domain` an
address on the allowlist is admitted by its domain and is bound;
address on the allowlist is admitted by its domain and is bound. A sign-in
through a social provider that did not verify the address creates no
account to bind under `email_domain`, or under `open` while email
verification is in force: the audience gate refuses it
([Authentication](/docs/permissions/authentication));
- binds only to an **unambiguous** target org — that is `tenancy.defaultOrgId()`,
which returns the single-org default organization under `single` and `null`
under any walled **request** (invitations, `add-member` and SSO provisioning
Expand Down
13 changes: 13 additions & 0 deletions content/docs/permissions/authentication.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,19 @@ the callback redirects with `error=account_not_linked`. The platform identity pr
(`objectstack-cloud`) is the one exception, and an unlinked provider never re-links
itself. See [Linking to an existing account](/docs/permissions/sso#linking-to-an-existing-account).

A sign-in that would create a new account through a social provider is judged by the
deployment's audience posture. Under `email_domain`, and under `open` while email
verification is in force (the default; only the deployment can declare it off), the
account is created only when the provider reports the address verified. Otherwise the
sign-in is refused `403 SELF_REGISTRATION_CLOSED` (the callback redirects with
`error=SELF_REGISTRATION_CLOSED`), as it is under `invite_only`, and nothing is written:
no account, no session, no membership. A pending invitation addressed to the person does
not change this, because it is matched by the same address; once the provider verifies
the address, the next sign-in is admitted. The rule covers every provider in
`socialProviders`, a provider added later included. Identity providers an operator
registers (`oidcProviders` entries and SSO providers) are not affected, and neither is
the first account of a fresh install.

---

## Enterprise Authentication Hardening (ADR-0069)
Expand Down
140 changes: 140 additions & 0 deletions packages/plugins/plugin-auth/src/audience-posture.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1128,3 +1128,143 @@ describe('a sign-up admitted by its invitation alone (isAdmittedByInvitationAlon
expect(alone({ audience: { ...DOMAIN, invalid: { raw: "'bogus'" } } })).toBe(false);
});
});

describe('a self-serve social creation under an address-based posture is admitted only with a provider-verified address', () => {
const DOMAIN = audience({ posture: 'email_domain', allowedEmailDomains: ['acme.com'], selfRegistrationPermissionSet: 'portal_user' });
const OPEN_POSTURE = audience({ posture: 'open', selfRegistrationPermissionSet: 'portal_user' });
const decide = (over: Partial<Parameters<typeof decideAudienceAdmission>[0]> = {}) =>
decideAudienceAdmission({
audience: DOMAIN,
creationClass: 'self-serve',
method: 'oauth',
email: 'user@acme.com',
hasPendingInvitation: false,
isBootstrap: false,
...over,
});
const expectRefused = (verdict: ReturnType<typeof decideAudienceAdmission>, label?: string) => {
expect(verdict.admit, label).toBe(false);
if (!verdict.admit) expect(verdict.code, label).toBe(SELF_REGISTRATION_CLOSED);
};

it('email_domain: an address on the allowlist is refused unless the provider reported it verified, `true` and nothing else', () => {
for (const emailVerified of [false, undefined, null, 'true', 1]) expectRefused(decide({ emailVerified }), String(emailVerified));
expect(decide({ emailVerified: true })).toEqual({ admit: true, grantPermissionSet: true });
});

it('email_domain: verification is in force whatever the deployment declares', () => {
for (const declaredEmailVerification of [undefined, true, false]) {
expectRefused(decide({ emailVerified: false, declaredEmailVerification }), String(declaredEmailVerification));
}
});

it('email_domain: a pending invitation addressed to the creation does not admit it while the provider did not verify the address', () => {
expectRefused(decide({ email: 'contractor@partner.example', hasPendingInvitation: true, emailVerified: false }));
expectRefused(decide({ hasPendingInvitation: true, emailVerified: false }));
expect(decide({ email: 'contractor@partner.example', hasPendingInvitation: true, emailVerified: true })).toEqual({
admit: true,
grantPermissionSet: false,
});
});

it('open: refused while email verification is in force (undeclared or declared true), an invitation included', () => {
for (const declaredEmailVerification of [undefined, true]) {
expectRefused(decide({ audience: OPEN_POSTURE, emailVerified: false, declaredEmailVerification }), String(declaredEmailVerification));
}
expectRefused(decide({ audience: OPEN_POSTURE, emailVerified: false, hasPendingInvitation: true }));
expect(decide({ audience: OPEN_POSTURE, emailVerified: true })).toEqual({ admit: true, grantPermissionSet: true });
});

it('CONTROL: open with email verification declared off by the deployment admits as before', () => {
expect(decide({ audience: OPEN_POSTURE, emailVerified: false, declaredEmailVerification: false })).toEqual({
admit: true,
grantPermissionSet: true,
});
});

it('CONTROL: the operator-registered provider class and the operator class are admitted whatever the provider said', () => {
for (const aud of [DOMAIN, OPEN_POSTURE]) {
for (const [creationClass, method] of [['provider', 'oauth'], ['provider', 'sso-oidc'], ['provider', 'sso-saml'], ['operator', 'admin'], ['operator', 'scim']] as const) {
expect(decide({ audience: aud, creationClass, method, emailVerified: false }), `${aud.posture} ${creationClass} ${method}`).toEqual({
admit: true,
grantPermissionSet: false,
});
}
}
});

it('CONTROL: every other self-serve method is judged as before', () => {
for (const method of ['email-password', 'magic-link', 'email-otp', undefined]) {
expect(decide({ method, emailVerified: false }), String(method)).toEqual({ admit: true, grantPermissionSet: true });
expect(decide({ audience: OPEN_POSTURE, method, emailVerified: false }), String(method)).toEqual({ admit: true, grantPermissionSet: true });
}
});

it('the bootstrap carve-out stays ahead of the rule: the first account of a fresh install is admitted', () => {
for (const aud of [DOMAIN, OPEN_POSTURE]) {
expect(decide({ audience: aud, isBootstrap: true, emailVerified: false })).toEqual({ admit: true, grantPermissionSet: false });
}
});

it('CONTROL: under invite_only the invitation proof carries the rule, and the decision reads as before', () => {
expectRefused(decide({ audience: audience(), emailVerified: false }));
expect(decide({ audience: audience(), emailVerified: true, hasPendingInvitation: true })).toEqual({ admit: true, grantPermissionSet: false });
});

it('the refusal names the posture it was judged under', () => {
for (const aud of [DOMAIN, OPEN_POSTURE]) {
const verdict = decide({ audience: aud, emailVerified: false });
expect(verdict.admit).toBe(false);
if (!verdict.admit) expect(verdict.message).toContain(aud.posture);
}
});
});

describe('the admission gate: a self-serve social creation needs a provider-verified address under an address-based posture', () => {
const nonBootstrapCtx = { context: { adapter: { findOne: async () => ({ id: 'usr_existing' }) } } };
const gateOf = (manager: AuthManager) => (user: Record<string, unknown>, source: Record<string, unknown>) =>
(manager as any).validateAudienceAdmission({ user, source: { action: 'create-user', ...source } }, nonBootstrapCtx);
const social = (providerId = 'google') => ({ method: 'oauth', oauth: { providerId } });

it('email_domain: refused unless the provider verified the address, for any social provider; an oidcProviders entry and an SSO provider are admitted whatever they said', async () => {
const engine = createMemoryEngine();
seedExistingUser(engine);
seedPermissionSet(engine, 'portal_user');
const gate = gateOf(
makeManager(engine, {
getTenancy: SINGLE_TENANCY,
audience: { posture: 'email_domain', allowedEmailDomains: ['acme.com'], selfRegistrationPermissionSet: 'portal_user' },
oidcProviders: [
{ providerId: 'okta', clientId: 'x', clientSecret: 'y', discoveryUrl: 'https://idp.example/.well-known/openid-configuration' },
],
}),
);
expect((await gate({ email: 'jit@acme.com', emailVerified: false }, social()))?.error).toBe(SELF_REGISTRATION_CLOSED);
expect((await gate({ email: 'jit@acme.com' }, social()))?.error).toBe(SELF_REGISTRATION_CLOSED);
expect((await gate({ email: 'jit@acme.com', emailVerified: false }, social('a-provider-configured-later')))?.error).toBe(
SELF_REGISTRATION_CLOSED,
);
expect(await gate({ email: 'jit@acme.com', emailVerified: true }, social())).toBeUndefined();

expect(await gate({ email: 'jit@acme.com', emailVerified: false }, social('okta'))).toBeUndefined();
expect(await gate({ email: 'jit@acme.com', emailVerified: false }, { method: 'sso-oidc', sso: { providerId: 'acme' } })).toBeUndefined();
});

it('open: refused while email verification is in force, admitted once the deployment declares it off', async () => {
const forced = createMemoryEngine();
seedExistingUser(forced);
seedPermissionSet(forced, 'portal_user');
const open = { posture: 'open', selfRegistrationPermissionSet: 'portal_user' };
const forcedGate = gateOf(makeManager(forced, { getTenancy: SINGLE_TENANCY, audience: open }));
expect((await forcedGate({ email: 'joiner@anywhere.com', emailVerified: false }, social()))?.error).toBe(SELF_REGISTRATION_CLOSED);
expect(await forcedGate({ email: 'joiner@anywhere.com', emailVerified: true }, social())).toBeUndefined();

const off = createMemoryEngine();
seedExistingUser(off);
seedPermissionSet(off, 'portal_user');
const offGate = gateOf(
makeManager(off, { getTenancy: SINGLE_TENANCY, audience: open, emailAndPassword: { requireEmailVerification: false } }),
);
expect(await offGate({ email: 'joiner@anywhere.com', emailVerified: false }, social())).toBeUndefined();
});
});
Loading
Loading