Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-api): accept the Entra override only when the first AS is multi-tenant (BR1-L4)
Diego Zacariasbe2210a5e9ea
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex e15c3f454..c4b0d40b7 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.805",+ "version": "0.1.806","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.805",+ "version": "0.1.806","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",diff --git a/control-api/package.json b/control-api/package.jsonindex 94f96c827..8a49a47d1 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.805",+ "version": "0.1.806","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/src/oauth/discovery.ts b/control-api/src/oauth/discovery.tsindex 311458ca9..797d41f60 100644--- a/control-api/src/oauth/discovery.ts+++ b/control-api/src/oauth/discovery.ts@@ -692,18 +692,16 @@ async function resolvePrm(*/function authorizationServerOverrideRejection(override: string,- prm: ProtectedResourceMetadata+ advertisedAs: string): string | null {if (!isEntraTenantAuthority(override)) {return 'authorizationServer must be a Microsoft Entra ID tenant authority (https://login.microsoftonline.com/<tenant-id>/v2.0)'}- const advertised = Array.isArray(prm.authorization_servers) ? prm.authorization_servers : []- const advertisesEntraMultiTenant = advertised.some(entry => {- if (typeof entry !== 'string' || !URL.canParse(entry)) return false- return isEntraMultiTenantAuthority(new URL(entry))- })- if (!advertisesEntraMultiTenant) {- return 'the protected resource does not advertise the Microsoft Entra ID multi-tenant authority'+ // Only the first entry counts: discovery replaces `authorization_servers[0]` and only+ // that entry raises `tenant_required`, so an Entra multi-tenant authority listed later+ // must not license swapping out an unrelated first authorization server.+ if (!URL.canParse(advertisedAs) || !isEntraMultiTenantAuthority(new URL(advertisedAs))) {+ return "the protected resource's first authorization server is not the Microsoft Entra ID multi-tenant authority"}return null}@@ -752,7 +750,7 @@ export async function discoverRemoteOAuth(let asBase = advertisedAsif (opts.authorizationServer !== undefined) {- const rejection = authorizationServerOverrideRejection(opts.authorizationServer, prm)+ const rejection = authorizationServerOverrideRejection(opts.authorizationServer, advertisedAs)if (rejection !== null) {log.warn({ discovery: 'authorization_server_override_rejected' },diff --git a/control-api/test/oauth.discovery.test.ts b/control-api/test/oauth.discovery.test.tsindex 27b4f3298..17b91837c 100644--- a/control-api/test/oauth.discovery.test.ts+++ b/control-api/test/oauth.discovery.test.ts@@ -655,7 +655,26 @@ describe('discoverRemoteOAuth — Microsoft Entra tenant authority (tenant_requierror: {kind: 'authorization_server_override_rejected',detail:- 'the protected resource does not advertise the Microsoft Entra ID multi-tenant authority',+ "the protected resource's first authorization server is not the Microsoft Entra ID multi-tenant authority",+ },+ })+ expect(hostsOf(requestedUrls)).not.toContain('login.microsoftonline.com')+ })++ it('the multi-tenant authority listed after another authorization server does not license the override', async () => {+ const pilot = workIqPilotWithPrm('entra-organizations-second', prm => {+ prm.authorization_servers = ['https://other-as.example', ORGANIZATIONS]+ })+ const { transport, requestedUrls } = recordingTransport(makeDiscoveryTransport(pilot))+ const outcome = await discoverRemoteOAuth(pilot.mcpUrl, deps(transport), {+ authorizationServer: TENANT_AUTHORITY,+ })+ expect(outcome).toEqual({+ ok: false,+ error: {+ kind: 'authorization_server_override_rejected',+ detail:+ "the protected resource's first authorization server is not the Microsoft Entra ID multi-tenant authority",},})expect(hostsOf(requestedUrls)).not.toContain('login.microsoftonline.com')