From a776f672d8c3e307565b9430cd9270fd8068b11f Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 11:30:42 +0000 Subject: [PATCH 1/3] test(plugin-auth): pin the 404 a kernel without SSO answers on the discovery endpoints Claude-Session: https://claude.ai/code/session_01Q4EjjPP1zuWBNq3nBXVei9 Co-authored-by: Claude --- .../src/sso-discovery-connect-time.test.ts | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/packages/plugins/plugin-auth/src/sso-discovery-connect-time.test.ts b/packages/plugins/plugin-auth/src/sso-discovery-connect-time.test.ts index 021bb1e3ec4..a50249aef4a 100644 --- a/packages/plugins/plugin-auth/src/sso-discovery-connect-time.test.ts +++ b/packages/plugins/plugin-auth/src/sso-discovery-connect-time.test.ts @@ -660,6 +660,75 @@ describe('a request whose auth context adapter is not the observed view is refus }); }); +describe('the discovery scope follows the composition: a kernel that does not mount SSO answers the vendor\'s 404 and logs nothing', () => { + afterEach(() => { + vi.unstubAllEnvs(); + }); + + interface Kernel { + manager: AuthManager; + logger: { warn: ReturnType; error: ReturnType; info: ReturnType }; + } + + function kernel(plugins: Record): Kernel { + const logger = { warn: vi.fn(), error: vi.fn(), info: vi.fn() }; + const manager = new AuthManager({ + secret: SECRET, + baseUrl: BASE, + dataEngine: createMemoryEngine(), + trustedOrigins: [BASE], + plugins, + logger, + } as unknown as ConstructorParameters[0]); + return { manager, logger }; + } + + const doors: ReadonlyArray Request]> = [ + ['POST /sso/register', () => new Request(`${AUTH}/sso/register`, { + method: 'POST', + headers: { 'content-type': 'application/json', origin: BASE }, + body: JSON.stringify(registration('unmounted-register', 'https://idp.acme.example')), + })], + ['POST /sign-in/sso', () => new Request(`${AUTH}/sign-in/sso`, { + method: 'POST', + headers: { 'content-type': 'application/json', origin: BASE }, + body: JSON.stringify({ providerId: 'unmounted-oidc', callbackURL: `${BASE}/after` }), + })], + ['GET /sso/callback/:providerId', () => new Request(`${AUTH}/sso/callback/unmounted-oidc?code=idp-code&state=any-state`)], + ]; + + const compositions: ReadonlyArray]> = [ + ['plugins.sso false', { sso: false }], + ['plugins.sso unset and OS_SSO_ENABLED unset (the default)', {}], + ]; + + describe.each(compositions)('%s', (_name, plugins) => { + it.each(doors)('%s answers 404, and nothing is logged at error level', async (_door, request) => { + vi.stubEnv('OS_SSO_ENABLED', undefined); + const { manager, logger } = kernel(plugins); + const res = await manager.handleRequest(request()); + expect(res.status, await res.clone().text()).toBe(404); + expect(logger.error).not.toHaveBeenCalled(); + const lines = [...logger.warn.mock.calls, ...logger.info.mock.calls].map((call) => String(call[0])); + expect(lines.filter((line) => line.includes('SSO request refused'))).toEqual([]); + }); + }); + + it('CONTROL: a kernel that mounted SSO keeps the scope when OS_SSO_ENABLED is unset after the build: an unobserved context adapter is still answered 503', async () => { + vi.stubEnv('OS_SSO_ENABLED', 'true'); + const { manager, logger } = kernel({}); + const ctx = await ((await manager.getAuthInstance()) as any).$context; + // The configuration re-read at request time now says "no SSO"; the + // composition that answers the request still mounts it. + vi.stubEnv('OS_SSO_ENABLED', undefined); + ctx.adapter = { ...ctx.adapter }; + const res = await manager.handleRequest(doors[0]![1]()); + expect(res.status, await res.clone().text()).toBe(503); + expect(await res.json()).toMatchObject({ success: false, error: { code: 'SERVICE_UNAVAILABLE' } }); + expect(logger.error).toHaveBeenCalledTimes(1); + }); +}); + describe('the SSO discovery scope judges only the reads it names', () => { /** A guard that answers every read itself, recording it. */ function recordingGuard(): { guard: EgressGuard; sent: string[] } { From 3f7ec3b181e58ae60aff24804ec31947fd806c15 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 11:35:30 +0000 Subject: [PATCH 2/3] 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 --- .../src/auth-manager-request-routing.ts | 11 ++++++++--- packages/plugins/plugin-auth/src/auth-manager.ts | 4 +++- .../plugin-auth/src/sso-discovery-egress.ts | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/plugins/plugin-auth/src/auth-manager-request-routing.ts b/packages/plugins/plugin-auth/src/auth-manager-request-routing.ts index a944e060743..b04539afe0a 100644 --- a/packages/plugins/plugin-auth/src/auth-manager-request-routing.ts +++ b/packages/plugins/plugin-auth/src/auth-manager-request-routing.ts @@ -68,7 +68,7 @@ import { SESSION_ERASURE_PATHS } from './session-tombstone.js'; import { envelopeVendorAdminRefusal } from './vendor-admin-refusal-envelope.js'; import { OAUTH_REVOKE_PATH } from './mcp-token-revocation.js'; import { ssoCallbackOf } from './sso-oidc-refusal-cause.js'; -import { isSsoDiscoveryEgressPath } from './sso-discovery-egress.js'; +import { isSsoDiscoveryEgressPath, mountsSsoEndpoints } from './sso-discovery-egress.js'; import { samlSingleLogoutProviderId, SIGN_OUT_ENDPOINT_PATH } from './sso-sign-out-of-idp.js'; import type { ScimRequestScope } from './scim-connection-service.js'; @@ -233,8 +233,13 @@ export async function handleRequest(this: Pick => this.runSsoDiscoveryEgress(runVendorHandler) : runVendorHandler; diff --git a/packages/plugins/plugin-auth/src/auth-manager.ts b/packages/plugins/plugin-auth/src/auth-manager.ts index 12ce3198c2b..37821c9b955 100644 --- a/packages/plugins/plugin-auth/src/auth-manager.ts +++ b/packages/plugins/plugin-auth/src/auth-manager.ts @@ -4475,7 +4475,9 @@ export class AuthManager { * makes is sent as it was. A context whose adapter is not observed (a view * that does not hand its reads on through the observed one) is answered * `503 SERVICE_UNAVAILABLE` before the endpoint runs, so nothing is read or - * sent: its provider reads could not be judged. + * sent: its provider reads could not be judged. Reached only when the built + * instance mounts the vendor's `sso` plugin (`mountsSsoEndpoints`, judged in + * `handleRequest`): a kernel without SSO answers the vendor's own 404. */ private async runSsoDiscoveryEgress(run: () => Promise): Promise { const [{ runInSsoDiscoveryEgressScope, observesSsoProviderReads }, guard, auth] = await Promise.all([ diff --git a/packages/plugins/plugin-auth/src/sso-discovery-egress.ts b/packages/plugins/plugin-auth/src/sso-discovery-egress.ts index aedf6a26184..6132f3ae3b4 100644 --- a/packages/plugins/plugin-auth/src/sso-discovery-egress.ts +++ b/packages/plugins/plugin-auth/src/sso-discovery-egress.ts @@ -105,6 +105,20 @@ export function isSsoDiscoveryEgressPath(endpointPath: string | undefined): bool return endpointPath.startsWith('/sso/callback/'); } +/** + * Whether the built auth instance mounts the vendor's `sso` plugin, the one + * thing that serves the endpoints {@link isSsoDiscoveryEgressPath} names. Read + * off the composition that answers the request (its plugin list), never off + * the configuration re-read at request time, which can disagree with the lazy + * build. A plugin list that cannot be read answers `true`: a composition this + * cannot see into is judged as one that mounts SSO, so the scope opens. + */ +export function mountsSsoEndpoints(auth: unknown): boolean { + const plugins = (auth as { options?: { plugins?: unknown } } | null | undefined)?.options?.plugins; + if (!Array.isArray(plugins)) return true; + return plugins.some((plugin) => (plugin as { id?: unknown } | null)?.id === 'sso'); +} + /** * The guard SSO discovery sends through: the platform's outbound-request * guard with a policy that refuses every address that is not public and From 1f505ba720c776fa93ebf1a57a35e53bba3372cc Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 21 Nov 2026 11:48:29 +0000 Subject: [PATCH 3/3] chore(changeset): plugin-auth patch for the unmounted-SSO 404 Claude-Session: https://claude.ai/code/session_01Q4EjjPP1zuWBNq3nBXVei9 Co-authored-by: Claude --- .changeset/35939-sso-unmounted-404.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .changeset/35939-sso-unmounted-404.md diff --git a/.changeset/35939-sso-unmounted-404.md b/.changeset/35939-sso-unmounted-404.md new file mode 100644 index 00000000000..a157bfc31d8 --- /dev/null +++ b/.changeset/35939-sso-unmounted-404.md @@ -0,0 +1,12 @@ +--- +'@objectstack/plugin-auth': patch +--- + +fix(plugin-auth): a kernel without SSO answers 404 again on the SSO discovery endpoints, with no error log + +Clause-②: no +Metadata-protocol: none + +Since SSO discovery began connecting only to addresses that are public at connect time, a kernel that does not mount SSO (the default without `OS_SSO_ENABLED` or `plugins.sso`) answered `POST /sso/register`, `/sign-in/sso` and `/sso/callback/*` with `503 SERVICE_UNAVAILABLE` ("SSO is unavailable: this server cannot judge its reads of an identity provider") and logged one error line per request. The discovery scope opened on the path alone, while the adapter observer it requires is mounted only with SSO. + +The scope now opens only when the built auth instance mounts the vendor's `sso` plugin, read off the composed plugin list rather than the configuration re-read at request time. A kernel without SSO answers the vendor's own 404 on those paths and logs nothing. A kernel that mounts SSO is judged exactly as before: provider reads go through the connect-time guard, and a context whose adapter is not observed is still refused `503` before the endpoint runs. No configuration, export or response shape changes.