Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-api): keep the generic lane's operator base as origin+path (F1-M2)
Diego Zacariasbcadf82502b3
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex f80598026..bca53fc35 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.791",+ "version": "0.1.792","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.791",+ "version": "0.1.792","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 c42d871fd..2a702e5bc 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.791",+ "version": "0.1.792","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 605a74e20..3bb2d1d62 100644--- a/control-api/src/oauth/discovery.ts+++ b/control-api/src/oauth/discovery.ts@@ -917,8 +917,17 @@ export async function discoverAuthorizationServerMetadata(let prm: ProtectedResourceMetadata | undefinedlet resource: string | undefined- // Issuer-first (DA-2): the typed URL is most likely an AS issuer.- const issuerFirst = await resolveAsMetadataFromBase(base, deps)+ // Issuer-first (DA-2): the typed URL is most likely an AS issuer. Only its origin+ // and path locate the well-known documents, so the operator's query, fragment or+ // userinfo are dropped before the comparison; the issuer the AS declares must still+ // be bare. The PRM fallback below keeps `authorization_servers[0]` strict: that one+ // is a third party's claim of the identifier, not a locator typed by the operator.+ const operatorBase = new URL(base.href)+ operatorBase.search = ''+ operatorBase.hash = ''+ operatorBase.username = ''+ operatorBase.password = ''+ const issuerFirst = await resolveAsMetadataFromBase(operatorBase, deps)if (issuerFirst.ok) {as = issuerFirst.as} else {diff --git a/control-api/test/oauth.discovery.generic.test.ts b/control-api/test/oauth.discovery.generic.test.tsindex 5841ad3a4..cd3cff213 100644--- a/control-api/test/oauth.discovery.generic.test.ts+++ b/control-api/test/oauth.discovery.generic.test.ts@@ -146,3 +146,89 @@ describe('discoverAuthorizationServerMetadata — kernel §4 (inv.6)', () => {expect(outcome.error.kind).toBe('kernel_rejected')})})++describe('discoverAuthorizationServerMetadata — issuer identity (RFC 8414 §3.3 / §2)', () => {+ const notionWellKnown = 'https://mcp.notion.com/.well-known/oauth-authorization-server'++ // The operator's typed URL only locates the well-known documents (built from its+ // origin and path); its query, fragment or userinfo are not part of the issuer the+ // AS must declare.+ for (const typed of [+ 'https://mcp.notion.com?tenant=x',+ 'https://mcp.notion.com?',+ 'https://mcp.notion.com#',+ 'https://u:[email protected]',+ ]) {+ it(`accepts the bare issuer when the operator types ${typed}`, async () => {+ const outcome = await discoverAuthorizationServerMetadata(+ typed,+ deps(asOnlyTransport(notionWellKnown, NOTION_AS_JSON))+ )+ expect(outcome.ok).toBe(true)+ if (outcome.ok) expect(outcome.result.issuer).toBe('https://mcp.notion.com')+ })+ }++ // The PRM fallback follows `authorization_servers[0]`, a third party's claim of the+ // AS identifier: it stays strict, so a decorated one never matches a bare issuer.+ const prmFallback = (advertised: string) => {+ const asJson = JSON.stringify({+ ...JSON.parse(NOTION_AS_JSON),+ issuer: 'https://as.example.com',+ })+ const pilot = {+ ...PILOTS.notion,+ prm: {+ ...PILOTS.notion.prm,+ json: JSON.stringify({+ ...JSON.parse(PILOTS.notion.prm.json),+ authorization_servers: [advertised],+ }),+ },+ as: { url: 'https://as.example.com/.well-known/oauth-authorization-server', json: asJson },+ asExtra: [+ {+ url: 'https://as.example.com/.well-known/openid-configuration',+ status: 200,+ json: asJson,+ },+ ],+ }+ // The typed MCP URL has a path, so issuer-first finds no AS and the PRM decides.+ return discoverAuthorizationServerMetadata(pilot.mcpUrl, deps(makeDiscoveryTransport(pilot)))+ }++ it('control: the PRM fallback accepts a bare authorization_servers[0]', async () => {+ const outcome = await prmFallback('https://as.example.com')+ expect(outcome.ok).toBe(true)+ if (outcome.ok) expect(outcome.result.issuer).toBe('https://as.example.com')+ })++ for (const advertised of ['https://as.example.com?', 'https://u:[email protected]']) {+ it(`rejects a PRM authorization_servers[0] of ${advertised}`, async () => {+ const outcome = await prmFallback(advertised)+ expect(outcome.ok).toBe(false)+ if (!outcome.ok) expect(outcome.error.kind).toBe('issuer_mismatch')+ })+ }++ for (const issuer of [+ 'https://mcp.notion.com?',+ 'https://mcp.notion.com#f',+ 'https://u:[email protected]',+ ]) {+ it(`rejects an AS whose issuer is ${issuer}`, async () => {+ const asJson = JSON.stringify({ ...JSON.parse(NOTION_AS_JSON), issuer })+ const transport: PinnedTransport = async ({ url }) =>+ url === notionWellKnown || url === 'https://mcp.notion.com/.well-known/openid-configuration'+ ? { status: 200, headers: { 'content-type': 'application/json' }, bodyText: asJson }+ : { status: 404, headers: {}, bodyText: 'not found' }+ const outcome = await discoverAuthorizationServerMetadata(+ 'https://mcp.notion.com',+ deps(transport)+ )+ expect(outcome.ok).toBe(false)+ if (!outcome.ok) expect(outcome.error.kind).toBe('issuer_mismatch')+ })+ }+})