Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-api): reject a known Entra API GUID scope off its own host (BR1-M1)
Diego Zacariasf9a6d8e5f0b9
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex 036617853..6b5e83041 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.810",+ "version": "0.1.811","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.810",+ "version": "0.1.811","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 63b5beb3b..6f4277d55 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.810",+ "version": "0.1.811","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/asProfiles.ts b/control-api/src/oauth/asProfiles.tsindex 940bea040..466d076b4 100644--- a/control-api/src/oauth/asProfiles.ts+++ b/control-api/src/oauth/asProfiles.ts@@ -136,7 +136,12 @@ function classifyEntraScope(scope: string, host: string): { kind: ScopeClass; guconst guidForm = GUID_SCOPE_RE.exec(scope)if (guidForm) {const guid = guidForm[2]- return { kind: ENTRA_BLOCKED_RESOURCE_APPS.has(guid) ? 'blocked-guid' : 'guid', guid }+ if (ENTRA_BLOCKED_RESOURCE_APPS.has(guid)) return { kind: 'blocked-guid', guid }+ // A known API has one legitimate host, so on any other host its token is a leak, not+ // something the operator could confirm; this also catches a base URL edited after the+ // install, which the runtime re-check classifies with the same rule.+ const knownHost = ENTRA_KNOWN_RESOURCE_APPS.get(guid)+ return { kind: knownHost === undefined || knownHost === host ? 'guid' : 'foreign', guid }}// A literal prefix, never `new URL`: WHATWG parsing accepts userinfo and a port, so// `api://<graph-guid>@<host>/x` would otherwise report the MCP host.@@ -180,8 +185,9 @@ export function profileHasResourceScope(}/**- * Scopes in GUID form whose API cannot be tied to the MCP host: accepted only when- * the operator confirms each one. Empty without a profile. Order kept, no duplicates.+ * Scopes in GUID form whose API the platform does not know, so it cannot tie them to the+ * MCP host: accepted only when the operator confirms each one. A known API on another+ * host is a violation instead. Empty without a profile. Order kept, no duplicates.*/export function profileUnverifiedScopes(id: AsProfileId | undefined,@@ -192,7 +198,7 @@ export function profileUnverifiedScopes(const host = new URL(mcpBaseUrl).hostnameconst unverified = scopes.filter(scope => {const { kind, guid } = classifyEntraScope(scope, host)- return kind === 'guid' && ENTRA_KNOWN_RESOURCE_APPS.get(guid as string) !== host+ return kind === 'guid' && !ENTRA_KNOWN_RESOURCE_APPS.has(guid as string)})return [...new Set(unverified)]}diff --git a/control-api/src/oauth/mcpServerOAuthSpec.ts b/control-api/src/oauth/mcpServerOAuthSpec.tsindex 1c18b5287..0de071225 100644--- a/control-api/src/oauth/mcpServerOAuthSpec.ts+++ b/control-api/src/oauth/mcpServerOAuthSpec.ts@@ -305,8 +305,9 @@ function remoteOAuthSpecIncoherence(}// Without `resource` the scopes alone pick the token's audience, and the scopes or the// base URL can be edited after the install (API or kubectl). The hard audience rules- // are therefore re-checked against the base URL in force now. GUID scopes the platform- // cannot tie to the host pass: writing the CR is the operator's confirmation.+ // are therefore re-checked against the base URL in force now: a known API's GUID scope+ // off its own host is refused. GUID scopes of an API the platform does not know pass:+ // writing the CR is the operator's confirmation.if (oauth.asProfile === 'entra-v2') {const scopes = withProfileScopes(normalizeScopes(oauth.scopes) ?? [], 'entra-v2')if (diff --git a/control-api/test/oauth.asProfiles.test.ts b/control-api/test/oauth.asProfiles.test.tsindex 74139a72f..d945b2252 100644--- a/control-api/test/oauth.asProfiles.test.ts+++ b/control-api/test/oauth.asProfiles.test.ts@@ -289,6 +289,8 @@ describe('profileScopeViolation', () => {'https://workiq.svc.cloud.microsoft.evil.example/x','https://workiq.svc.cloud.microsoft','FDCC1F02-FC51-4226-8753-F668596AF7F7/WorkIQAgent.Ask',+ AGENT365_GUID_SCOPE,+ `api://${AGENT365_GUID_SCOPE}`,'',]for (const scope of rejected) {@@ -307,6 +309,20 @@ describe('profileScopeViolation', () => {}})+ it('a known GUID is accepted only on the host tied to it', () => {+ for (const [scope, ownBase] of [+ [WORKIQ_GUID_SCOPE, WORKIQ_URL],+ [AGENT365_GUID_SCOPE, AGENT365_URL],+ ]) {+ expect(profileScopeViolation('entra-v2', ownBase, [scope])).toBeNull()+ for (const base of [WORKIQ_URL, AGENT365_URL, 'https://evil.example/mcp']) {+ if (base === ownBase) continue+ expect(profileScopeViolation('entra-v2', base, [scope])).toBe(scope)+ expect(profileScopeViolation('entra-v2', base, [`api://${scope}`])).toBe(`api://${scope}`)+ }+ }+ })+it('returns the first rejected scope, in order', () => {expect(profileScopeViolation('entra-v2', WORKIQ_URL, [@@ -391,13 +407,12 @@ describe('profileUnverifiedScopes', () => {).toEqual([UNKNOWN_GUID_SCOPE, `api://${UNKNOWN_GUID_SCOPE}`])})- it('a known GUID on another host is unverified', () => {- expect(profileUnverifiedScopes('entra-v2', WORKIQ_URL, [AGENT365_GUID_SCOPE])).toEqual([- AGENT365_GUID_SCOPE,- ])- expect(profileUnverifiedScopes('entra-v2', AGENT365_URL, [WORKIQ_GUID_SCOPE])).toEqual([- WORKIQ_GUID_SCOPE,- ])+ it('a known GUID on another host is never unverified (it is rejected instead)', () => {+ expect(profileUnverifiedScopes('entra-v2', WORKIQ_URL, [AGENT365_GUID_SCOPE])).toEqual([])+ expect(profileUnverifiedScopes('entra-v2', AGENT365_URL, [WORKIQ_GUID_SCOPE])).toEqual([])+ expect(+ profileUnverifiedScopes('entra-v2', 'https://evil.example/mcp', [WORKIQ_GUID_SCOPE])+ ).toEqual([])})it('a blocked GUID is never unverified (it is rejected instead)', () => {@@ -458,6 +473,21 @@ describe('audience classification properties', () => {)})+ it('a known GUID is a violation exactly when the base URL is not on its host', () => {+ fc.assert(+ fc.property(+ hostArb,+ fc.constantFrom(...KNOWN_LITERAL),+ fc.constantFrom('', 'api://'),+ (host, [guid, knownHost], prefix) => {+ const scope = `${prefix}${guid}/Read`+ const violation = profileScopeViolation('entra-v2', `https://${host}/mcp`, [scope])+ expect(violation).toBe(host === knownHost ? null : scope)+ }+ )+ )+ })+it('every scope the profile accepts is an RFC 6749 scope-token', () => {fc.assert(fc.property(baseArb, scopeArb, (base, scope) => {diff --git a/control-api/test/oauth.discovery.test.ts b/control-api/test/oauth.discovery.test.tsindex 17b91837c..ff2f73d3f 100644--- a/control-api/test/oauth.discovery.test.ts+++ b/control-api/test/oauth.discovery.test.ts@@ -762,6 +762,16 @@ describe('discoverRemoteOAuth — entra-v2 profile (PKCE, refresh, scope audiencexpect(r.unverifiedScopes).toBeUndefined()})+ it('row 16: the Agent 365 GUID advertised by the Work IQ host → scopeAudienceViolation, never unverified', async () => {+ const agent365Scope = '05879165-0320-489e-b644-f72b33f3edf0/McpServers.Mail.All'+ const pilot = workIqPilotWithPrm('entra-agent365-guid-on-workiq', prm => {+ prm.scopes_supported = [agent365Scope]+ })+ const r = await discoverWithTenant(pilot)+ expect(r.scopeAudienceViolation).toBe(agent365Scope)+ expect(r.unverifiedScopes).toBeUndefined()+ })+it('row 17: no PRM scopes (sign-in scopes of the AS only) → scopeAudienceMissing', async () => {const r = await discoverWithTenant(ENTRA_NO_SCOPES_PILOT)expect(r.scopeAudienceMissing).toBe(true)diff --git a/control-api/test/oauth.remoteSpecCoherence.test.ts b/control-api/test/oauth.remoteSpecCoherence.test.tsindex 779e02ba7..e3494567a 100644--- a/control-api/test/oauth.remoteSpecCoherence.test.ts+++ b/control-api/test/oauth.remoteSpecCoherence.test.ts@@ -334,6 +334,15 @@ const INCOHERENT: ReadonlyArray<{reason: 'scope_audience_mismatch',consentOnly: false,},+ {+ // The Work IQ app GUID is tied to its own host, so an edited base URL cannot carry its+ // tokens elsewhere even though a GUID scope names no host.+ label: 'entra-v2 GUID-form scope of a known API after baseUrl moved to another host',+ oauth: () => ({ ...workIqGuid.spec.oauth }),+ remote: () => ({ ...workIqGuid.spec.remote, baseUrl: EVIL_BASE_URL }),+ reason: 'scope_audience_mismatch',+ consentOnly: false,+ },{label: 'entra-v2 without spec.remote',oauth: () => ({ ...workIqGuid.spec.oauth }),@@ -502,20 +511,6 @@ describe('entra-v2 runtime audience: what stays coherent', () => {expect(resolveServerOAuthSubject(cr, phase)?.decl.id).toBe(workIqGuid.spec.oauth.id)})- // A GUID-form scope is not tied to the base URL, so moving the base URL to another- // host goes unnoticed; this pins that limit rather than leaving it implicit.- it(`${phase}: the Work IQ GUID scope with baseUrl moved to another host stays coherent`, () => {- const cr = crFrom(- 'srv',- { ...workIqGuid.spec.oauth },- {- ...workIqGuid.spec.remote,- baseUrl: EVIL_BASE_URL,- }- )- expect(resolveServerOAuthSubject(cr, phase)?.decl.id).toBe(workIqGuid.spec.oauth.id)- })-it(`${phase}: without a profile the same scopes are coherent (I6)`, () => {const preRegistered = buildRemoteOAuthSpec(headerDiscovery, {clientMode: 'confidential',diff --git a/control-api/test/routes.adminRemoteMcp.test.ts b/control-api/test/routes.adminRemoteMcp.test.tsindex 22c39fd6b..15ee1b27b 100644--- a/control-api/test/routes.adminRemoteMcp.test.ts+++ b/control-api/test/routes.adminRemoteMcp.test.ts@@ -3054,12 +3054,15 @@ describe('Microsoft Entra ID — remote install with scopes, scope audience andawait expectNoWrites(gw)})- it('row 16: the Agent 365 GUID on the Work IQ host → 400 scope_audience_unverified', async () => {+ it('row 16: the Agent 365 GUID on the Work IQ host → 400 scope_audience_mismatch even when confirmed', async () => {const gw = gatewayWithContext()const agent365Scope = '05879165-0320-489e-b644-f72b33f3edf0/McpServers.Mail.All'- const res = await entraInstall(ENTRA_WORKIQ_PILOT, gw, { scopes: [agent365Scope] })+ const res = await entraInstall(ENTRA_WORKIQ_PILOT, gw, {+ scopes: [agent365Scope],+ confirmedUnverifiedScopes: [agent365Scope],+ })expect(res.status).toBe(400)- expect(res.body).toMatchObject({ error: 'scope_audience_unverified', scopes: [agent365Scope] })+ expect(res.body).toMatchObject({ error: 'scope_audience_mismatch', scope: agent365Scope })await expectNoWrites(gw)})diff --git a/docs/how-to/connect-oauth-connector.md b/docs/how-to/connect-oauth-connector.mdindex 4c30c68a9..093c522ee 100644--- a/docs/how-to/connect-oauth-connector.md+++ b/docs/how-to/connect-oauth-connector.md@@ -218,7 +218,8 @@ from you, and both are checked the same way.| `https://<server-host>/...` or `api://<server-host>/...`, where `<server-host>` is exactly the host of the server URL | Accepted. || GUID form (`<guid>/<permission>` or `api://<guid>/<permission>`, lower-case GUID) of a Microsoft MCP API on its own host: Work IQ `fdcc1f02-fc51-4226-8753-f668596af7f7` on `workiq.svc.cloud.microsoft`, Agent 365 Tools `05879165-0320-489e-b644-f72b33f3edf0` on `agent365.svc.cloud.microsoft` | Accepted. || GUID form of a blocked Microsoft API (list below) | Always rejected (`scope_audience_mismatch`), even if you confirm it. |-| Any other GUID form, including a known one on a different host | Accepted only after you confirm it (`scope_audience_unverified`). |+| GUID form of one of those two Microsoft MCP APIs on any other host | Always rejected (`scope_audience_mismatch`), even if you confirm it. |+| Any other GUID form (an API the platform does not know) | Accepted only after you confirm it (`scope_audience_unverified`). || Anything else: a bare permission such as `Mail.Read` (Entra reads it as Microsoft Graph), a URL on another host, or a URL with a user name or port | Rejected (`scope_audience_mismatch`). |**Blocked APIs.** Microsoft Graph, SharePoint Online, Exchange Online, Azure@@ -249,15 +250,18 @@ with the confirming admin and the scopes.unverified GUID scopes: whoever can write the resource can already change itsserver URL. It does not bypass the other rules. On every authorization,callback, token use, and refresh, control-api checks the scopes again against-the current `spec.remote.baseUrl`. A blocked API, a URL on another host, a-bare permission, or a missing server scope is refused with+the current `spec.remote.baseUrl`. A blocked API, a known Microsoft MCP API's+GUID off its own host, a URL on another host, a bare permission, or a missing+server scope is refused with`409 remote_oauth_spec_incoherent` (reason `scope_audience_mismatch`), andexisting grants stop being served until the resource is fixed.-> **Limit with GUID scopes.** A GUID scope is not tied to a host, so if only-> `spec.remote.baseUrl` changes, the platform cannot tell that the token now-> goes to a different server. Prefer the URL form (`api://<server-host>/...`)-> when the server accepts it.+> **Limit with unknown GUID scopes.** The GUID of an API the platform does not+> know is not tied to a host, so if only `spec.remote.baseUrl` changes, the+> platform cannot tell that the token now goes to a different server. Prefer the+> URL form (`api://<server-host>/...`) when the server accepts it. The Work IQ+> and Agent 365 Tools GUIDs are tied to their hosts, so that change is detected+> for them.Ask for scopes of one API only. Entra issues each token for a singleresource, so mixing scopes of different APIs, or `.default` with specific