Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-api): reject bearerInBody at remote install admission (R1-M3)
Diego Zacarias21e57c4db73f
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex c72a36360..5369c8ec4 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.656",+ "version": "0.1.657","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.656",+ "version": "0.1.657","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 f9b771b36..765d5728c 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.656",+ "version": "0.1.657","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/src/routes/admin/remoteMcp.ts b/control-api/src/routes/admin/remoteMcp.tsindex bd1903930..ca834b7e1 100644--- a/control-api/src/routes/admin/remoteMcp.ts+++ b/control-api/src/routes/admin/remoteMcp.ts@@ -403,6 +403,25 @@ export function createAdminRemoteMcpRouter(}const discovery = outcome.result+ // Reject `bearerInBody` at admission instead of persisting a CR the runtime+ // cannot honor. mcp-host always sends the token in the Authorization header+ // (body injection is deferred, see `mcp/client.ts`), so a resource that only+ // accepts the token in the body (`bearer_methods_supported:["body"]` without+ // `"header"`, e.g. SEMrush) would install "green" and then fail every tool+ // call with no signal. Fail closed here until body injection exists.+ if (discovery.quirks.bearerInBody) {+ log.warn(+ { event: 'remote_oauth_bearer_in_body_unsupported', serverName: body.serverName },+ 'remote install rejected: resource requires bearer token in body, unsupported by the runtime'+ )+ res.status(400).json({+ error: 'bearer_in_body_unsupported',+ message:+ 'this resource requires the bearer token in the request body, which is not yet supported',+ })+ return+ }+// The requested mode must match what server-side discovery actually resolved// (D-4: discovery is authoritative). CIMD ⇒ AS must offer CIMD; DCR ⇒ AS must// offer a registration endpoint (registrationMode 'dcr').diff --git a/control-api/test/routes.adminRemoteMcp.test.ts b/control-api/test/routes.adminRemoteMcp.test.tsindex eb5eb4210..98ec188ea 100644--- a/control-api/test/routes.adminRemoteMcp.test.ts+++ b/control-api/test/routes.adminRemoteMcp.test.ts@@ -23,6 +23,7 @@ import {DCR_PUBLIC_WITH_ECHOED_SECRET_REGISTRATION_RESPONSE,DCR_VERCEL_DOWNGRADE_REGISTRATION_JSON,DCR_VERCEL_DOWNGRADE_REGISTRATION_RESPONSE,+ NOTION_PRM_JSON,PILOTS,VERCEL_PILOT,dcrPilot,@@ -105,6 +106,10 @@ function gatewayWithContext(contextName = 'ctx-a'): MockGateway {// Real DiscoveryResult, derived from the real Notion probe fixtures (T1).let notionResult: DiscoveryResult+// A DiscoveryResult whose resource requires the token in the BODY, derived from the+// real producer (T1) by documented substitution of the Notion PRM's+// `bearer_methods_supported` to `["body"]` — the only field changed.+let bodyBearerResult: DiscoveryResultbeforeAll(async () => {const actual = await vi.importActual<typeof import('../src/oauth/discovery.js')>(@@ -124,6 +129,27 @@ beforeAll(async () => {if (!vercelOutcome.ok)throw new Error(`vercel fixture discovery failed: ${vercelOutcome.error.kind}`)vercelResult = vercelOutcome.result++ // Documented substitution (like the DCR fixtures): the real Notion pilot with the+ // PRM's `bearer_methods_supported` set to body-only. The real producer then derives+ // `quirks.bearerInBody === true` — no hand-authored DiscoveryResult (T1).+ const bodyBearerPilot = {+ ...PILOTS.notion,+ prm: {+ ...PILOTS.notion.prm,+ json: NOTION_PRM_JSON.replace(+ '"bearer_methods_supported":["header"]',+ '"bearer_methods_supported":["body"]'+ ),+ },+ }+ const bodyBearerOutcome = await actual.discoverRemoteOAuth(bodyBearerPilot.mcpUrl, {+ transport: makeDiscoveryTransport(bodyBearerPilot),+ resolveDns: async () => ['93.184.216.34'],+ })+ if (!bodyBearerOutcome.ok)+ throw new Error(`body-bearer fixture discovery failed: ${bodyBearerOutcome.error.kind}`)+ bodyBearerResult = bodyBearerOutcome.result})beforeEach(() => {@@ -277,6 +303,29 @@ describe('POST /admin/mcp-servers/remote (install saga)', () => {expect(ctx.spec.mcpServers).toContain('notion-remote')})+ it('body-bearer resource: rejects at admission and creates no CR (the runtime cannot honor bearerInBody)', async () => {+ // Self-check the T1 fixture: the real producer must have derived the body-bearer+ // quirk, or this test would pass vacuously against any server.+ expect(bodyBearerResult.quirks.bearerInBody).toBe(true)+ mockDiscovery(bodyBearerResult)+ const gw = gatewayWithContext('ctx-a')+ const res = await request(makeApp(gw)).post('/admin/mcp-servers/remote').send({+ serverName: 'notion-remote',+ contextRef: 'ctx-a',+ baseUrl: 'https://mcp.notion.com/mcp',+ mode: 'cimd',+ })+ expect(res.status).toBe(400)+ expect(res.body.error).toBe('bearer_in_body_unsupported')++ // No CR persisted, and the Context is not mutated: the install failed closed.+ await expect(gw.getResource('mcpservers', 'notion-remote', NS)).rejects.toBeDefined()+ const ctx = (await gw.getResource('contexts', 'ctx-a', NS)) as {+ spec: { mcpServers?: string[] }+ }+ expect(ctx.spec.mcpServers ?? []).not.toContain('notion-remote')+ })+it('pre-registered confidential: creates the client Secret + references it in spec.oauth', async () => {mockDiscovery(notionResult)const gw = gatewayWithContext('ctx-a')