From 9f4fd3cd4e27ba1666021e9d5990faf8c684efac Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Nov 2026 12:08:09 +0000 Subject: [PATCH 1/3] fix(plugin-auth)!: a self-serve social creation is admitted only with a provider-verified address under an address-based posture Under the email_domain audience posture, and under open while email verification is in force, a self-serve creation through a social provider is admitted only when the provider verified the address. Any other is refused SELF_REGISTRATION_CLOSED at the admission gate, as invite_only refuses it: no account row, no session, no membership. A pending invitation addressed to it does not admit it either. The operator-registered provider class, the operator class and the bootstrap carve-out are unaffected; open with the deployment's verification declared off admits as before. Claude-Session: https://claude.ai/code/session_01ASNY8VyogmQQgdcx5jLwwc Co-authored-by: Claude --- .../plugin-auth/src/audience-posture.test.ts | 140 ++++++++++++++++++ .../plugin-auth/src/audience-posture.ts | 85 ++++++++++- .../src/auth-manager-membership-admission.ts | 7 + ...tation-acceptance-verified-address.test.ts | 114 ++++++++++++-- 4 files changed, 332 insertions(+), 14 deletions(-) diff --git a/packages/plugins/plugin-auth/src/audience-posture.test.ts b/packages/plugins/plugin-auth/src/audience-posture.test.ts index 27c8e56cf09..52692b2c82e 100644 --- a/packages/plugins/plugin-auth/src/audience-posture.test.ts +++ b/packages/plugins/plugin-auth/src/audience-posture.test.ts @@ -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[0]> = {}) => + decideAudienceAdmission({ + audience: DOMAIN, + creationClass: 'self-serve', + method: 'oauth', + email: 'user@acme.com', + hasPendingInvitation: false, + isBootstrap: false, + ...over, + }); + const expectRefused = (verdict: ReturnType, 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, source: Record) => + (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(); + }); +}); diff --git a/packages/plugins/plugin-auth/src/audience-posture.ts b/packages/plugins/plugin-auth/src/audience-posture.ts index af38cf7f46e..f2f2b8a423f 100644 --- a/packages/plugins/plugin-auth/src/audience-posture.ts +++ b/packages/plugins/plugin-auth/src/audience-posture.ts @@ -59,7 +59,9 @@ * self-serve sign-up route. So a self-serve creation holding a PENDING, * unexpired `sys_invitation` row is admitted under every posture (under * `email_domain` an explicit invitation also trumps the domain list — an - * operator inviting an external contractor must not dead-end them). Without + * operator inviting an external contractor must not dead-end them), except a + * social-provider creation whose address the provider did not verify under a + * posture whose admission rests on the address (below). Without * this carve-out the posture would be "admin-create only" and the invitation * surface would be dead for new users — the invite dead-end class. * @@ -78,6 +80,21 @@ * the deployment's organization while its address is unverified, and joins by * accepting the invitation. * + * ## A social provider's word on the address + * + * Under a posture whose admission rests on the address — `email_domain` + * always, `open` while email verification is in force + * ({@link resolveEmailVerificationRequirement}) — a self-serve creation through + * a social provider is admitted only when the provider verified the address + * (`emailVerified` `true`). Otherwise {@link decideAudienceAdmission} refuses it + * `SELF_REGISTRATION_CLOSED`, as `invite_only` refuses it through the + * invitation proof: no account row, no session, no membership, and a pending + * invitation addressed to it does not admit it either. The rule is keyed on the + * creation class, so a social provider configured later is covered without + * being named; the `provider` class (an operator-registered identity + * authority) and the bootstrap carve-out are unaffected. Under `open` with the + * deployment's verification declared off, the creation is admitted as before. + * * ## Pinned domain-matching rules (`email_domain`) * * An unpinned matcher is where this class of gate leaks, so the rules are @@ -494,6 +511,47 @@ export interface AudienceAdmissionInput { * creation, an `oidcProviders` entry included. */ ssoProvider?: { allowJit: boolean }; + /** The vendor's `source.method` for the creation (`oauth` for a social provider). */ + method?: unknown; + /** + * What the creation's identity provider said of the address, as the vendor + * hands it (`user.emailVerified`). Verified only when it is `true`. + */ + emailVerified?: unknown; + /** + * The deployment's declared `emailAndPassword.requireEmailVerification`, + * resolved here by {@link resolveEmailVerificationRequirement}, the resolver + * the better-auth wiring and the public config read. Absent resolves to the + * posture's default, so under `open` email verification is in force unless + * the deployment declared an explicit `false`. + */ + declaredEmailVerification?: boolean; +} + +/** + * A self-serve creation through a social provider: `oauth` whose providerId is + * not an operator-registered `oidcProviders` entry ({@link classifyCreationMethod} + * classes those `provider`). It is told by the creation class and method, not + * by a list of providers, so a social provider configured later is covered + * without being named. + */ +function isSocialProviderCreation(creationClass: AudienceCreationClass, method: unknown): boolean { + return creationClass === 'self-serve' && method === 'oauth'; +} + +/** + * Whether a valid posture's admission of a self-serve creation rests on its + * address: `email_domain` always, and `open` while email verification is in + * force. Under either, a self-serve creation through a social provider is + * admitted only when the provider verified the address + * ({@link decideAudienceAdmission}). Under `invite_only` the invitation proof + * already asks it of an OAuth creation ({@link invitationProofFor}). + */ +function admissionRestsOnAddress(audience: ResolvedAudience, declaredEmailVerification: boolean | undefined): boolean { + if (audience.invalid) return false; + if (audience.posture === 'email_domain') return true; + if (audience.posture === 'open') return resolveEmailVerificationRequirement('open', declaredEmailVerification); + return false; } /** @@ -569,10 +627,26 @@ const SSO_JIT_CLOSED_MESSAGE = '(audience posture invite_only). Ask an administrator for an invitation, or ask them to turn on ' + 'just-in-time provisioning (allowJit) for this provider.'; +/** The refusal message for a social-provider creation whose address the provider did not verify. */ +const socialAddressUnverifiedMessage = (posture: AudiencePosture): string => + 'This sign-in provider has not verified the email address, and this environment creates an account through ' + + `a social sign-in only for a verified address (audience posture ${posture}). ` + + 'Verify the address with the provider and sign in again.'; + /** * THE admission decision — pure, so the posture × method matrix is a table of * direct calls. Order: creation-class exemptions → bootstrap → vocabulary - * guard (fail closed) → posture semantics. + * guard (fail closed) → the social-provider address rule → posture semantics. + * + * The social-provider address rule: under a posture whose admission rests on + * the address ({@link admissionRestsOnAddress}: `email_domain` always, `open` + * while email verification is in force), a self-serve creation through a + * social provider is admitted only when the provider verified the address. + * Otherwise it is refused `SELF_REGISTRATION_CLOSED`, as `invite_only` refuses + * it, and nothing is written: no account row, no session, no membership. A + * pending invitation does not admit it either — the invitation is matched by + * that same address. The `operator` and `provider` classes, and the bootstrap + * carve-out, stay ahead of the rule. */ export function decideAudienceAdmission(input: AudienceAdmissionInput): AudienceAdmission { const { audience, creationClass, email, hasPendingInvitation, isBootstrap, ssoProvider } = input; @@ -601,6 +675,13 @@ export function decideAudienceAdmission(input: AudienceAdmissionInput): Audience 'This is a configuration error, not a policy refusal.', }; } + if ( + isSocialProviderCreation(creationClass, input.method) && + input.emailVerified !== true && + admissionRestsOnAddress(audience, input.declaredEmailVerification) + ) { + return { admit: false, code: SELF_REGISTRATION_CLOSED, message: socialAddressUnverifiedMessage(audience.posture) }; + } if (hasPendingInvitation) { // An explicit invitation is a stronger operator act than any posture — // it admits the invitee's own account creation under invite_only AND diff --git a/packages/plugins/plugin-auth/src/auth-manager-membership-admission.ts b/packages/plugins/plugin-auth/src/auth-manager-membership-admission.ts index 041b6ff566a..f6c405dd03a 100644 --- a/packages/plugins/plugin-auth/src/auth-manager-membership-admission.ts +++ b/packages/plugins/plugin-auth/src/auth-manager-membership-admission.ts @@ -276,12 +276,19 @@ export async function validateAudienceAdmission( } } } + // The method, the provider's word on the address and the deployment's + // declared email verification: a social-provider creation is admitted only + // with a provider-verified address under a posture whose admission rests on + // the address (`decideAudienceAdmission`). const verdict = decideAudienceAdmission({ audience, creationClass, email, hasPendingInvitation, isBootstrap, + method: data?.source?.method, + emailVerified: data?.user?.emailVerified, + declaredEmailVerification: this.config.emailAndPassword?.requireEmailVerification, ...(ssoProvider ? { ssoProvider } : {}), }); if (!verdict.admit) { diff --git a/packages/plugins/plugin-auth/src/invitation-acceptance-verified-address.test.ts b/packages/plugins/plugin-auth/src/invitation-acceptance-verified-address.test.ts index d77da48eb7c..e24ba968922 100644 --- a/packages/plugins/plugin-auth/src/invitation-acceptance-verified-address.test.ts +++ b/packages/plugins/plugin-auth/src/invitation-acceptance-verified-address.test.ts @@ -29,6 +29,7 @@ import { authIdentityObjects } from './manifest.js'; import { SIGN_UP_INVITATION_ID_FIELD } from './presented-invitation.js'; import { operatorProvisioningField } from './audience-gate-test-support'; import { ACCEPT_INVITATION_ONE_STEP_PATH } from './invitation-mailbox-proof.js'; +import { SELF_REGISTRATION_CLOSED } from './audience-posture.js'; import { memoizeScrypt } from './__tests__/scrypt-memo.testkit'; import { bindTestSecurityCatalog } from './__tests__/security-catalog.testkit.js'; import { relaxTenantColumns } from './pre-18-tenant-column.testkit.js'; @@ -230,9 +231,9 @@ async function deployment( config: Record = {}, { mail = 'live', into = PARTNER_ORG }: { mail?: MailState; into?: string } = {}, ) { - const engine = await bootEngine({ - selfRegistrationSet: (config as { audience?: { posture?: unknown } }).audience?.posture === 'email_domain', - }); + // Both self-registration postures grant the declared set to a sign-up they admit uninvited. + const posture = (config as { audience?: { posture?: unknown } }).audience?.posture; + const engine = await bootEngine({ selfRegistrationSet: posture === 'email_domain' || posture === 'open' }); const sent: SentMail[] = []; const manager = makeManager(engine, sent, config, mail); const first = await send(manager, 'POST', '/sign-up/email', { email: OWNER, password: PASSWORD, name: 'Owner' }); @@ -300,6 +301,35 @@ async function socialSession(d: Deployment, verified: boolean): Promise return cookie; } +/** A sign-in through the social provider, which asserts `email` as verified or not; the answer is returned as it came. */ +function socialSignIn(d: Deployment, email: string, verified: boolean): Promise { + providerProfile = { sub: `google-${email}`, email, email_verified: verified }; + return send(d.manager, 'POST', '/sign-in/social', { provider: 'google', idToken: { token: 'synthetic' } }); +} + +/** How many rows each identity object holds. */ +async function identityRowCounts(engine: ObjectQL): Promise> { + const counts: Record = {}; + for (const object of ['sys_user', 'sys_account', 'sys_session', 'sys_member']) counts[object] = (await rows(engine, object)).length; + return counts; +} + +/** + * A social sign-in whose provider did not verify `email` is refused at the + * admission gate, `403 SELF_REGISTRATION_CLOSED`, and writes nothing: no + * account row, no linked account, no session, no membership. + */ +async function expectSocialCreationRefused(d: Deployment, email: string) { + const before = await identityRowCounts(d.engine); + const res = await socialSignIn(d, email, false); + // One comparison, so a failure shows every leg at once. + expect( + { verdict: await verdict(res), signedIn: cookieFrom(res) !== '', rows: await identityRowCounts(d.engine) }, + await res.clone().text(), + ).toEqual({ verdict: { status: 403, code: SELF_REGISTRATION_CLOSED }, signedIn: false, rows: before }); + expect(await rows(d.engine, 'sys_user', { email })).toEqual([]); +} + /** The answer the one-step door gives a signed-in session (no proof). */ async function oneStepAnswer(d: Deployment, cookie: string): Promise { @@ -367,6 +397,14 @@ async function verifyByMail(d: Deployment, cookie: string) { } const OPEN = { audience: { posture: 'open', selfRegistrationPermissionSet: 'member_default' } }; +/** + * `open` with the deployment's email verification declared off. An address-based + * posture (`email_domain`, or `open` while email verification is in force) + * refuses a social creation whose provider did not verify the address, so this + * is the deployment on which such an account exists and the answer rules for it + * are driven. + */ +const OPEN_VERIFICATION_OFF = { ...OPEN, emailAndPassword: { requireEmailVerification: false } }; describe('accepting, declining and listing an invitation require a verified email address; reading it does not', () => { it('a password account that never verified its address is refused at accept, decline and the listing, and can read the invitation', async () => { @@ -390,7 +428,7 @@ describe('accepting, declining and listing an invitation require a verified emai }); it('an account whose social provider asserted the address unverified is refused at accept, decline and the listing', async () => { - const d = await deployment(OPEN); + const d = await deployment(OPEN_VERIFICATION_OFF); await expectAnswerRefusedReadOpen(d, await socialSession(d, false)); }); @@ -405,7 +443,7 @@ describe('accepting, declining and listing an invitation require a verified emai }); it('the one-step door accepts for a signed-in account only once its address is verified', async () => { - const d = await deployment(OPEN); + const d = await deployment(OPEN_VERIFICATION_OFF); const cookie = await socialSession(d, false); await expectAnswerRefusedReadOpen(d, cookie); @@ -449,7 +487,7 @@ describe('the rule holds whatever the state of the mail transport', () => { }); it(`${label}: an unverified social account is refused at accept, decline and the listing`, async () => { - const d = await deployment(OPEN, { mail }); + const d = await deployment(OPEN_VERIFICATION_OFF, { mail }); await expectAnswerRefusedReadOpen(d, await socialSession(d, false)); }); @@ -614,12 +652,17 @@ describe('under email_domain, a sign-up off the allowlist that an invitation adm expect((await d.allMemberships()).map((m) => [m.organization_id, m.role])).toEqual([[DEFAULT_ORG, 'admin']]); }); - it('an account a social provider made for that address, unverified, holds no membership and is refused at accept', async () => { - const d = await deployment(EMAIL_DOMAIN, { into: DEFAULT_ORG }); - const cookie = await socialSession(d, false); - expect(await d.allMemberships()).toEqual([]); - await expectAnswerRefusedReadOpen(d, cookie); - expect(await d.allMemberships()).toEqual([]); + it('a social provider that did not verify that address is refused at admission like any unverified social creation: no account, no session, no membership', async () => { + const d = await deployment(EMAIL_DOMAIN, { into: PARTNER_ORG }); + await expectSocialCreationRefused(d, INVITEE); + expect((await d.invitation())?.status).toBe('pending'); + + // The invitation still serves: the same person, once the provider verifies + // the address, is admitted and accepts the invited role. + const res = await socialSignIn(d, INVITEE, true); + expect(res.status, await res.clone().text()).toBe(200); + expect(cookieFrom(res), 'the verified social sign-in is signed in').not.toBe(''); + await expectAccepted(d, cookieFrom(res)); }); it('CONTROL: an address on the allowlist is bound to the default organization at creation, uninvited or invited', async () => { @@ -670,3 +713,50 @@ describe('under email_domain, a sign-up off the allowlist that an invitation adm }); }); +describe('under an address-based audience posture, a self-serve social creation is admitted only with a provider-verified address', () => { + /** {@link ON_LIST} is on this list; {@link OWNER} and {@link ANYONE} are off it. */ + const ALLOWLIST = { + audience: { posture: 'email_domain', allowedEmailDomains: ['corp.example'], selfRegistrationPermissionSet: SELF_REGISTRATION_SET }, + }; + const ON_LIST = 'colleague@corp.example'; + const ANYONE = 'someone@anywhere.example'; + + const membershipsOf = async (d: Deployment, email: string) => { + const [user] = await rows(d.engine, 'sys_user', { email }); + return user ? (await rows(d.engine, 'sys_member', { user_id: user.id })).map((m) => [m.organization_id, m.role]) : []; + }; + + it('email_domain: a social provider that did not verify an address on the allowlist is refused: no account, no session, no membership', async () => { + const d = await deployment(ALLOWLIST); + await expectSocialCreationRefused(d, ON_LIST); + }); + + it('open with email verification in force: a social provider that did not verify the address is refused: no account, no session, no membership', async () => { + const d = await deployment(OPEN); + await expectSocialCreationRefused(d, ANYONE); + }); + + for (const [label, config, email] of [ + ['email_domain, an address on the allowlist', ALLOWLIST, ON_LIST], + ['open with email verification in force', OPEN, ANYONE], + ] as const) { + it(`CONTROL: ${label}: a social provider that verified the address admits it, signs it in and binds it to the default organization`, async () => { + const d = await deployment(config); + const res = await socialSignIn(d, email, true); + expect(res.status, await res.clone().text()).toBe(200); + expect(cookieFrom(res), 'the verified social sign-in is signed in').not.toBe(''); + const [user] = await rows(d.engine, 'sys_user', { email }); + expect(Boolean(user?.email_verified)).toBe(true); + expect(await membershipsOf(d, email)).toEqual([[DEFAULT_ORG, 'member']]); + }); + } + + it('CONTROL: open with the deployment\'s email verification declared off: a social provider that did not verify the address admits it and signs it in', async () => { + const d = await deployment(OPEN_VERIFICATION_OFF); + const res = await socialSignIn(d, ANYONE, false); + expect(res.status, await res.clone().text()).toBe(200); + expect(cookieFrom(res), 'the sign-in is signed in').not.toBe(''); + const [user] = await rows(d.engine, 'sys_user', { email: ANYONE }); + expect(Boolean(user?.email_verified)).toBe(false); + }); +}); From bf6fa3de2066ea804f72007c9b9c441e56bd60cc Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Nov 2026 12:11:22 +0000 Subject: [PATCH 2/3] docs(plugin-auth): a self-serve social creation is admitted only with a provider-verified address under an address-based posture The authentication page states the rule beside the OAuth callback, and the tenancy page's membership reconciler notes that such a sign-in creates no account to bind. The changeset carries the declaration lines and the ADR-0087 disposition. Claude-Session: https://claude.ai/code/session_01ASNY8VyogmQQgdcx5jLwwc Co-authored-by: Claude --- ...reation-needs-provider-verified-address.md | 21 +++++++++++++++++++ content/docs/deployment/tenancy-modes.mdx | 6 +++++- content/docs/permissions/authentication.mdx | 13 ++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 .changeset/social-creation-needs-provider-verified-address.md diff --git a/.changeset/social-creation-needs-provider-verified-address.md b/.changeset/social-creation-needs-provider-verified-address.md new file mode 100644 index 00000000000..83b2ff7d80e --- /dev/null +++ b/.changeset/social-creation-needs-provider-verified-address.md @@ -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. + + + +**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. diff --git a/content/docs/deployment/tenancy-modes.mdx b/content/docs/deployment/tenancy-modes.mdx index 1c2140f0cee..8a8bacc5652 100644 --- a/content/docs/deployment/tenancy-modes.mdx +++ b/content/docs/deployment/tenancy-modes.mdx @@ -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 diff --git a/content/docs/permissions/authentication.mdx b/content/docs/permissions/authentication.mdx index 9413b44b9a9..3502063f2e0 100644 --- a/content/docs/permissions/authentication.mdx +++ b/content/docs/permissions/authentication.mdx @@ -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) From 45c45799967c56542bbc5f240d62e9ea3252d2bb Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 18 Nov 2026 14:32:30 +0000 Subject: [PATCH 3/3] docs(plugin-auth): self-hosting states that a social sign-in under an address-based posture creates an account only for a provider-verified address Under email_domain, and under open while email verification is in force, the self-hosting page's invitation paragraph and its email verification section now say that a new account through a social provider is created only when the provider reports the address verified, and is otherwise refused 403 SELF_REGISTRATION_CLOSED, whatever the allowlist or an invitation says. Claude-Session: https://claude.ai/code/session_01ASNY8VyogmQQgdcx5jLwwc Co-authored-by: Claude --- content/docs/deployment/self-hosting.mdx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/content/docs/deployment/self-hosting.mdx b/content/docs/deployment/self-hosting.mdx index f3126f7523d..d1905cbb2b8 100644 --- a/content/docs/deployment/self-hosting.mdx +++ b/content/docs/deployment/self-hosting.mdx @@ -767,7 +767,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, @@ -847,6 +852,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: