Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(control-api): pin defaultScopes over non-array and mixed scopes_supported (F2-M2)

Diego Zacarias61ffb901505a
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 67f816c02..836fcdb94 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.797",
+ "version": "0.1.798",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.797",
+ "version": "0.1.798",
"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.json
index afe0530d1..710ed78e6 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.797",
+ "version": "0.1.798",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/test/oauth.discovery.test.ts b/control-api/test/oauth.discovery.test.ts
index 18b8808d4..27b4f3298 100644
--- a/control-api/test/oauth.discovery.test.ts
+++ b/control-api/test/oauth.discovery.test.ts
@@ -5,8 +5,11 @@ import type {
PinnedTransportInput,
} from '../src/http/pinnedFetch.js'
import {
+ type AuthorizationServerMetadata,
type DiscoveryDeps,
+ type ProtectedResourceMetadata,
asMetadataUrls,
+ defaultScopes,
discoverRemoteOAuth,
parseResourceMetadataChallenge,
wellKnownPrmUrls,
@@ -821,3 +824,36 @@ describe('discoverRemoteOAuth — entra-v2 profile (PKCE, refresh, scope audienc
})
}
})
+
+describe('defaultScopes — untrusted scopes_supported', () => {
+ // The metadata is third-party JSON, so these shapes are what a hostile or broken server
+ // can send, typed loosely on purpose.
+ const prm = (scopes: unknown) =>
+ ({
+ resource: 'https://mcp.example.com/mcp',
+ scopes_supported: scopes,
+ }) as unknown as ProtectedResourceMetadata
+ const as = (scopes?: unknown) =>
+ ({
+ issuer: 'https://as.example.com',
+ authorization_endpoint: 'https://as.example.com/authorize',
+ token_endpoint: 'https://as.example.com/token',
+ ...(scopes === undefined ? {} : { scopes_supported: scopes }),
+ }) as unknown as AuthorizationServerMetadata
+
+ it('a non-array PRM value is ignored and the AS list is used', () => {
+ expect(defaultScopes(prm('a b'), as(['x']))).toEqual(['x'])
+ })
+
+ it('non-string entries are dropped', () => {
+ expect(defaultScopes(prm(['a', 1, null]), as(['x']))).toEqual(['a'])
+ })
+
+ it('an empty PRM list is an answer: it does not fall back to the AS', () => {
+ expect(defaultScopes(prm([]), as(['x']))).toEqual([])
+ })
+
+ it('neither side advertises scopes → []', () => {
+ expect(defaultScopes(prm(undefined), as())).toEqual([])
+ })
+})
diff --git a/control-api/test/routes.adminRemoteMcp.test.ts b/control-api/test/routes.adminRemoteMcp.test.ts
index 2b07d52f1..f5364f91d 100644
--- a/control-api/test/routes.adminRemoteMcp.test.ts
+++ b/control-api/test/routes.adminRemoteMcp.test.ts
@@ -2700,6 +2700,23 @@ describe('Microsoft Entra ID — authorizationServer override on /discover and i
])
})
+ it('/discover ignores a PRM scopes_supported that is a string, not a list', async () => {
+ const res = await request(
+ await entraApp(
+ workIqPilotWithPrm('entra-string-scopes', prm => {
+ prm.scopes_supported = 'fdcc1f02-fc51-4226-8753-f668596af7f7/WorkIQAgent.Ask'
+ }),
+ gatewayWithContext()
+ )
+ )
+ .post('/admin/mcp-servers/remote/discover')
+ .send({ baseUrl: ENTRA_WORKIQ_PILOT.mcpUrl, authorizationServer: TENANT_AUTHORITY })
+ expect(res.status).toBe(200)
+ // The real Entra tenant metadata advertises only sign-in scopes.
+ expect(res.body.detected.scopes).toEqual(['openid', 'profile', 'email', 'offline_access'])
+ expect(res.body.detected.scopeAudienceMissing).toBe(true)
+ })
+
it('/discover keeps an empty-string audience violation in the response', async () => {
const res = await request(
await entraApp(