Skip to content

Commit 3f7ec3b

Browse files
committed
fix(plugin-auth): open the SSO discovery scope only where the built instance mounts SSO
A kernel without SSO answered 503 SERVICE_UNAVAILABLE and logged an error on /sso/register, /sign-in/sso and /sso/callback/* because the scope opened on the path alone while its adapter observer mounts only with SSO. The scope now opens when the path names a discovery endpoint AND the built auth instance mounts the vendor's sso plugin, so an unmounted kernel answers the vendor's 404 again and a mounted one is judged exactly as before. Claude-Session: https://claude.ai/code/session_01Q4EjjPP1zuWBNq3nBXVei9 Co-authored-by: Claude <noreply@anthropic.com>
1 parent a776f67 commit 3f7ec3b

3 files changed

Lines changed: 25 additions & 4 deletions

File tree

‎packages/plugins/plugin-auth/src/auth-manager-request-routing.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ import { SESSION_ERASURE_PATHS } from './session-tombstone.js';
6868
import { envelopeVendorAdminRefusal } from './vendor-admin-refusal-envelope.js';
6969
import { OAUTH_REVOKE_PATH } from './mcp-token-revocation.js';
7070
import { ssoCallbackOf } from './sso-oidc-refusal-cause.js';
71-
import { isSsoDiscoveryEgressPath } from './sso-discovery-egress.js';
71+
import { isSsoDiscoveryEgressPath, mountsSsoEndpoints } from './sso-discovery-egress.js';
7272
import { samlSingleLogoutProviderId, SIGN_OUT_ENDPOINT_PATH } from './sso-sign-out-of-idp.js';
7373
import type { ScimRequestScope } from './scim-connection-service.js';
7474

@@ -233,8 +233,13 @@ export async function handleRequest(this: Pick<RequestRoutingHost, 'config' | 'b
233233
// scope entered inside a hook never reaches. Only reads at origins the
234234
// request's provider configuration names are judged (the global before-hook
235235
// names a registration's, the observed adapter a stored provider's as the
236-
// vendor reads it); every other read is sent as it was.
237-
const runHandler = isSsoDiscoveryEgressPath(this.betterAuthEndpointPath(request))
236+
// vendor reads it); every other read is sent as it was. The scope opens only
237+
// where the built instance mounts the vendor's `sso` plugin
238+
// (`mountsSsoEndpoints`): a kernel without SSO serves none of these paths,
239+
// so the vendor answers its own 404 and no provider read can happen, while
240+
// a kernel that mounts it is judged exactly as before — an unobserved
241+
// adapter there is still refused 503.
242+
const runHandler = isSsoDiscoveryEgressPath(this.betterAuthEndpointPath(request)) && mountsSsoEndpoints(auth)
238243
? (): Promise<Response> => this.runSsoDiscoveryEgress(runVendorHandler)
239244
: runVendorHandler;
240245

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4475,7 +4475,9 @@ export class AuthManager {
44754475
* makes is sent as it was. A context whose adapter is not observed (a view
44764476
* that does not hand its reads on through the observed one) is answered
44774477
* `503 SERVICE_UNAVAILABLE` before the endpoint runs, so nothing is read or
4478-
* sent: its provider reads could not be judged.
4478+
* sent: its provider reads could not be judged. Reached only when the built
4479+
* instance mounts the vendor's `sso` plugin (`mountsSsoEndpoints`, judged in
4480+
* `handleRequest`): a kernel without SSO answers the vendor's own 404.
44794481
*/
44804482
private async runSsoDiscoveryEgress(run: () => Promise<Response>): Promise<Response> {
44814483
const [{ runInSsoDiscoveryEgressScope, observesSsoProviderReads }, guard, auth] = await Promise.all([

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@ export function isSsoDiscoveryEgressPath(endpointPath: string | undefined): bool
105105
return endpointPath.startsWith('/sso/callback/');
106106
}
107107

108+
/**
109+
* Whether the built auth instance mounts the vendor's `sso` plugin, the one
110+
* thing that serves the endpoints {@link isSsoDiscoveryEgressPath} names. Read
111+
* off the composition that answers the request (its plugin list), never off
112+
* the configuration re-read at request time, which can disagree with the lazy
113+
* build. A plugin list that cannot be read answers `true`: a composition this
114+
* cannot see into is judged as one that mounts SSO, so the scope opens.
115+
*/
116+
export function mountsSsoEndpoints(auth: unknown): boolean {
117+
const plugins = (auth as { options?: { plugins?: unknown } } | null | undefined)?.options?.plugins;
118+
if (!Array.isArray(plugins)) return true;
119+
return plugins.some((plugin) => (plugin as { id?: unknown } | null)?.id === 'sso');
120+
}
121+
108122
/**
109123
* The guard SSO discovery sends through: the platform's outbound-request
110124
* guard with a policy that refuses every address that is not public and

0 commit comments

Comments
 (0)