Skip to content

Commit ba221aa

Browse files
committed
fix(plugin-auth): the register door asks the public-host rule before the sign-out switch's check
A registration whose discovery host does not resolve to public addresses is refused on issuer or oidcConfig.discoveryEndpoint whatever signOutOfIdp says, and the sign-out check reads the discovery document only after the rule has admitted its host. The SSO guide and the module notes say what is checked. Claude-Session: https://claude.ai/code/session_016WV4czt69hUUaG5XcgFNYL Co-authored-by: Claude <noreply@anthropic.com>
1 parent 32d1f05 commit ba221aa

4 files changed

Lines changed: 53 additions & 17 deletions

File tree

‎content/docs/permissions/sso.mdx‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -178,16 +178,19 @@ identity provider on an internal or private network is refused **400
178178
`VALIDATION_FAILED`** on `signOutOfIdp` until the provider's origin is listed in
179179
`OS_TRUSTED_ORIGINS`.
180180

181-
**SSO discovery fetches only hosts that resolve to public addresses.** Before a
182-
registration reads its discovery document, the server resolves that document's
183-
host (the `discoveryEndpoint` the registration names, else the issuer's) and
184-
every address it resolves to must be public. A host that resolves to a private,
185-
loopback, link-local or otherwise non-public address is refused **400
186-
`VALIDATION_FAILED`** on `issuer` or `oidcConfig.discoveryEndpoint`, and
187-
nothing is read from it; the Register SSO Provider bridge answers the same
188-
refusal as `SSO_REGISTER_FAILED`. Trust an origin gains because a registration
189-
names it never stands in for this check. An identity provider on an internal
190-
network registers once its origin is listed in `OS_TRUSTED_ORIGINS`.
181+
**A registration checks that its discovery host resolves to public addresses
182+
before reading it.** Before a registration reads its discovery document, the
183+
server resolves that document's host (the `discoveryEndpoint` the registration
184+
names, else the issuer's) and every address it resolves to must be public. A
185+
host that resolves to a private, loopback, link-local or otherwise non-public
186+
address is refused **400 `VALIDATION_FAILED`** on `issuer` or
187+
`oidcConfig.discoveryEndpoint`, and nothing is read from it; the Register SSO
188+
Provider bridge answers the same refusal as `SSO_REGISTER_FAILED`. The check
189+
comes before the **Sign Out of the Company Sign-In Too** check above, so a
190+
registration that also turns that switch on is refused on the same member.
191+
Trust an origin gains because a registration names it never stands in for this
192+
check. An identity provider on an internal network registers once its origin
193+
is listed in `OS_TRUSTED_ORIGINS`.
191194

192195
Google is one such provider: its discovery document names the token endpoint,
193196
the key set and the userinfo endpoint each on a host of its own, so a Google

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,14 +609,15 @@ export async function globalBeforeHook(
609609
// [#32085] One email domain, one provider: a domain another
610610
// provider already serves is refused 409, naming that provider.
611611
await this.assertSsoProviderDomainFree(ctx);
612-
// Ruling record 6866334319: the sign-out switch, as on update-provider.
613-
await this.assertSsoSignOutOfIdpSupported(ctx);
614612
// SSO discovery fetches only hosts that resolve to public addresses:
615613
// the host this registration's discovery reads is resolved before the
616614
// vendor's endpoint runs, and every address must be public, unless the
617615
// deployment's configured trusted origins (read here, before any
618616
// body-named origin joins them) list it
619-
// (`refuseSsoDiscoveryHostNotPublic`).
617+
// (`refuseSsoDiscoveryHostNotPublic`). Asked before the sign-out
618+
// switch below, whose check reads the same discovery document: a host
619+
// that is not public is refused on the member that names it, whatever
620+
// the switch says, and nothing is read from it.
620621
const notPublic = await refuseSsoDiscoveryHostNotPublic({
621622
body: ctx?.body,
622623
isConfiguredTrusted: (url) =>
@@ -630,6 +631,8 @@ export async function globalBeforeHook(
630631
field: notPublic.field,
631632
});
632633
}
634+
// Ruling record 6866334319: the sign-out switch, as on update-provider.
635+
await this.assertSsoSignOutOfIdpSupported(ctx);
633636
bodyOrigins = await this.ssoDiscoveryTrustedOrigins(ctx?.body);
634637
}
635638
// The origins the body names (its issuer and any explicit `oidcConfig`

‎packages/plugins/plugin-auth/src/sso-discovery-companion-origins.test.ts‎

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,12 +566,12 @@ describe('an origin a register or update body names is trusted for that provider
566566
expect(JSON.stringify(storedRows(rp))).toBe(before);
567567
});
568568

569-
it('the sign-out capability check trusts a body-named origin for the logout endpoint only: on register, its discovery read keeps the configured trust', async () => {
569+
it('on register with the switch on, an issuer whose host resolves to a private address is refused on issuer, before the sign-out check reads it', async () => {
570570
restore = stubIdp({ [OTHER_ISSUER]: withLogout(OTHER_ISSUER, `${OTHER_ISSUER}/logout`) }, new URL(OTHER_ISSUER).hostname);
571571
const rp = await makeCheckedRp();
572572
const res = await postAs(rp, '/sso/register', { ...registration('other-oidc', OTHER_ISSUER), signOutOfIdp: true }, BASE);
573573
expect(res.status, await res.clone().text()).toBe(400);
574-
expect(await res.json()).toMatchObject({ code: 'VALIDATION_FAILED', field: 'signOutOfIdp' });
574+
expect(await res.json()).toMatchObject({ code: 'VALIDATION_FAILED', field: 'issuer' });
575575
expect(storedRows(rp)).toEqual([]);
576576
});
577577

@@ -653,6 +653,20 @@ describe('SSO discovery reads only hosts that resolve to public addresses', () =
653653
},
654654
);
655655

656+
it('with the sign-out switch on, the registration is refused on issuer by this rule, and nothing is read from that host', async () => {
657+
const io = idp(
658+
{ [RESOLVED_ISSUER]: { ...discoveryDocument(RESOLVED_ISSUER, `${RESOLVED_ISSUER}/userinfo`), end_session_endpoint: `${RESOLVED_ISSUER}/logout` } },
659+
{ [RESOLVED_HOST]: ['10.0.0.5'] },
660+
);
661+
const rp = await makeRp();
662+
const res = await register(rp, { ...registration('resolved-oidc', RESOLVED_ISSUER), signOutOfIdp: true });
663+
expect(res.status, await res.clone().text()).toBe(400);
664+
expect(await res.json()).toMatchObject({ code: 'VALIDATION_FAILED', field: 'issuer' });
665+
expect(io.asked).toContain(RESOLVED_HOST);
666+
expect(readFrom(io.fetched, RESOLVED_HOST)).toEqual([]);
667+
expect(storedRows(rp)).toEqual([]);
668+
});
669+
656670
it('a discovery host with one public and one private address is refused: every address must be public', async () => {
657671
const io = idp(
658672
{ [RESOLVED_ISSUER]: discoveryDocument(RESOLVED_ISSUER, `${RESOLVED_ISSUER}/userinfo`) },
@@ -726,6 +740,18 @@ describe('SSO discovery reads only hosts that resolve to public addresses', () =
726740
expect(readFrom(io.fetched, RESOLVED_HOST)).toEqual([]);
727741
expect(storedRows(rp)).toEqual([]);
728742
});
743+
744+
it('CONTROL: a registration by a signed-in user who is not a platform admin resolves no name and is answered 403', async () => {
745+
const io = idp({ [RESOLVED_ISSUER]: discoveryDocument(RESOLVED_ISSUER, `${RESOLVED_ISSUER}/userinfo`) }, { [RESOLVED_HOST]: ['10.0.0.5'] });
746+
const rp = await makeRp();
747+
vi.spyOn(rp.manager as any, 'isPlatformAdminUserId').mockResolvedValue(false);
748+
const res = await register(rp, registration('resolved-oidc', RESOLVED_ISSUER));
749+
expect(res.status, await res.clone().text()).toBe(403);
750+
expect(await res.json()).toMatchObject({ code: 'SSO_REGISTER_FORBIDDEN' });
751+
expect(io.asked).toEqual([]);
752+
expect(readFrom(io.fetched, RESOLVED_HOST)).toEqual([]);
753+
expect(storedRows(rp)).toEqual([]);
754+
});
729755
});
730756

731757
describe('the host a registration\'s discovery reads is the one host resolved', () => {

‎packages/plugins/plugin-auth/src/sso-discovery-companion-origins.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,12 @@ export type SsoDiscoveryReadMember = 'issuer' | 'oidcConfig.discoveryEndpoint';
170170
* the explicit `oidcConfig.discoveryEndpoint`, else at the issuer's well-known
171171
* URL (`computeDiscoveryUrl`, the vendor's own). `undefined` when the
172172
* registration reads none: no `oidcConfig` (a SAML registration), or
173-
* `oidcConfig.skipDiscovery`. That read is the one server-side read the
174-
* register endpoint makes (`@better-auth/sso` 1.7.12 `discoverOIDCConfig`).
173+
* `oidcConfig.skipDiscovery`. The vendor's register endpoint makes no other
174+
* server-side read (`@better-auth/sso` 1.7.12 `discoverOIDCConfig`). With
175+
* `signOutOfIdp` on, the register door's sign-out check
176+
* (`assertSsoSignOutOfIdpSupported`) reads the same document first, under the
177+
* configured trust only, and only after {@link refuseSsoDiscoveryHostNotPublic}
178+
* has admitted its host.
175179
*/
176180
export function ssoRegisterDiscoveryRead(
177181
body: unknown,

0 commit comments

Comments
 (0)