Skip to content

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

TypeScript

fix(control-api): log every scope-audience rejection of a remote install (BR1-L6)

Diego Zacarias0809d66c52ce
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index 78224d160..1b388b9bd 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.807",
+ "version": "0.1.808",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.807",
+ "version": "0.1.808",
"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 5be4c67a6..2791fd276 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.807",
+ "version": "0.1.808",
"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.ts
index 28608abec..02cd0d951 100644
--- a/control-api/src/routes/admin/remoteMcp.ts
+++ b/control-api/src/routes/admin/remoteMcp.ts
@@ -765,7 +765,11 @@ export function createAdminRemoteMcpRouter(
const audienceViolation = profileScopeViolation(discovery.asProfile, body.baseUrl, scopes)
if (audienceViolation !== null) {
reqLog.warn(
- { event: 'remote_install_scope_audience_rejected', serverName: body.serverName },
+ {
+ event: 'remote_install_scope_audience_rejected',
+ serverName: body.serverName,
+ reason: 'mismatch',
+ },
'remote install rejected: scope outside the server audience'
)
res.status(400).json({
@@ -777,6 +781,14 @@ export function createAdminRemoteMcpRouter(
return
}
if (!profileHasResourceScope(discovery.asProfile, body.baseUrl, scopes)) {
+ reqLog.warn(
+ {
+ event: 'remote_install_scope_audience_rejected',
+ serverName: body.serverName,
+ reason: 'missing',
+ },
+ 'remote install rejected: no scope belongs to the server audience'
+ )
res.status(400).json({
error: 'scope_audience_missing',
message:
@@ -788,6 +800,15 @@ export function createAdminRemoteMcpRouter(
const unverifiedScopes = profileUnverifiedScopes(discovery.asProfile, body.baseUrl, scopes)
const unconfirmed = unverifiedScopes.filter(scope => !confirmed.has(scope))
if (unconfirmed.length > 0) {
+ reqLog.warn(
+ {
+ event: 'remote_install_scope_audience_rejected',
+ serverName: body.serverName,
+ reason: 'unverified',
+ scopes: unconfirmed,
+ },
+ 'remote install rejected: scopes not confirmed as belonging to the server'
+ )
res.status(400).json({
error: 'scope_audience_unverified',
scopes: unconfirmed,
diff --git a/control-api/test/routes.adminRemoteMcp.test.ts b/control-api/test/routes.adminRemoteMcp.test.ts
index ff230ba51..22c39fd6b 100644
--- a/control-api/test/routes.adminRemoteMcp.test.ts
+++ b/control-api/test/routes.adminRemoteMcp.test.ts
@@ -3068,11 +3068,48 @@ describe('Microsoft Entra ID — remote install with scopes, scope audience and
const reqLog = { info: vi.fn(), warn: vi.fn(), error: vi.fn() }
await entraInstall(ENTRA_GRAPH_SCOPE_PILOT, gw, { scopes: ['Mail.Read'] }, { reqLog })
expect(reqLog.warn).toHaveBeenCalledWith(
- { event: 'remote_install_scope_audience_rejected', serverName: 'workiq' },
+ { event: 'remote_install_scope_audience_rejected', serverName: 'workiq', reason: 'mismatch' },
'remote install rejected: scope outside the server audience'
)
})
+ it('a missing server audience is logged on the request logger', async () => {
+ const gw = gatewayWithContext()
+ const reqLog = { info: vi.fn(), warn: vi.fn(), error: vi.fn() }
+ const res = await entraInstall(
+ ENTRA_NO_SCOPES_PILOT,
+ gw,
+ { scopes: ['offline_access'] },
+ { reqLog }
+ )
+ expect(res.body.error).toBe('scope_audience_missing')
+ expect(reqLog.warn).toHaveBeenCalledWith(
+ { event: 'remote_install_scope_audience_rejected', serverName: 'workiq', reason: 'missing' },
+ 'remote install rejected: no scope belongs to the server audience'
+ )
+ })
+
+ it('unconfirmed unverified scopes are logged on the request logger with those scopes', async () => {
+ const gw = gatewayWithContext()
+ const reqLog = { info: vi.fn(), warn: vi.fn(), error: vi.fn() }
+ const res = await entraInstall(
+ ENTRA_UNKNOWN_GUID_PILOT,
+ gw,
+ { scopes: [UNKNOWN_GUID_SCOPE] },
+ { reqLog }
+ )
+ expect(res.body.error).toBe('scope_audience_unverified')
+ expect(reqLog.warn).toHaveBeenCalledWith(
+ {
+ event: 'remote_install_scope_audience_rejected',
+ serverName: 'workiq',
+ reason: 'unverified',
+ scopes: [UNKNOWN_GUID_SCOPE],
+ },
+ 'remote install rejected: scopes not confirmed as belonging to the server'
+ )
+ })
+
it('DCR with a scopes override: the registration request carries exactly those scopes', async () => {
const gw = gatewayWithContext()
const { db } = makeInMemoryDynamicClientsDb()