Skip to content

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

TypeScript

fix(control-api): prove the shared disconnect DELETE is context-narrow (R1-M2)

Diego Zacarias5086c6a87578
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index b912e773f..6af284eaa 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.509",
+ "version": "0.1.510",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.509",
+ "version": "0.1.510",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/image-policy": "file:../packages/image-policy",
diff --git a/control-api/package.json b/control-api/package.json
index 3b32a33e1..60fc209af 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.509",
+ "version": "0.1.510",
"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.mcpDisconnect.realPostgres.integration.test.ts b/control-api/test/oauth.mcpDisconnect.realPostgres.integration.test.ts
index 5aa5cfb1a..308b8454e 100644
--- a/control-api/test/oauth.mcpDisconnect.realPostgres.integration.test.ts
+++ b/control-api/test/oauth.mcpDisconnect.realPostgres.integration.test.ts
@@ -122,23 +122,29 @@ describeRealPostgres('mcp-server grant disconnect composition (real Postgres)',
).toBe(true)
})
- it('context flavor: deletes the single shared grant for the whole Context', async () => {
+ it('context flavor: deletes ONLY the target Context grant (a sibling shared grant survives)', async () => {
const resolved = resolvedFor('context', 'ctx-A')
- // First member bootstraps the shared identity (real producer).
- const { inserted } = await bootstrapSharedOAuthGrant(db, KEY, {
- ownerKind: 'mcpserver',
- recipeNamespace: NS,
- recipeName: 'teamdrive',
- contextId: 'ctx-A',
- oauthClientId: 'google-drive',
- bootstrappedByUserId: 'user-a',
- provider: 'google',
- accessToken: 'shared-at',
- refreshToken: 'shared-rt',
- })
- expect(inserted).toBe(true)
+ // Two DIFFERENT Contexts each bootstrap a shared identity on the SAME server
+ // (real producer). ctx-B is the sibling that must survive — the mirror of
+ // the user-flavor case's user-b, so a shared DELETE that lost its
+ // `context_id` predicate (blast-radius bug) would be caught here.
+ for (const contextId of ['ctx-A', 'ctx-B']) {
+ const { inserted } = await bootstrapSharedOAuthGrant(db, KEY, {
+ ownerKind: 'mcpserver',
+ recipeNamespace: NS,
+ recipeName: 'teamdrive',
+ contextId,
+ oauthClientId: 'google-drive',
+ bootstrappedByUserId: 'user-a',
+ provider: 'google',
+ accessToken: `shared-at-${contextId}`,
+ refreshToken: `shared-rt-${contextId}`,
+ })
+ expect(inserted).toBe(true)
+ }
- // A DIFFERENT member revokes: the key is decoupled from the caller's userId.
+ // A DIFFERENT member revokes ctx-A: the key is decoupled from the caller's
+ // userId but MUST stay scoped to ctx-A's Context.
const key = buildMcpServerGrantKey(resolved, {
mcpServersNamespace: NS,
mcpServerName: 'teamdrive',
@@ -147,6 +153,7 @@ describeRealPostgres('mcp-server grant disconnect composition (real Postgres)',
expect(key).not.toBeNull()
await deleteOAuthGrant(db, key!)
+ // ctx-A's shared grant is gone …
expect(
await oauthGrantExists(db, {
grantKind: 'shared',
@@ -157,6 +164,18 @@ describeRealPostgres('mcp-server grant disconnect composition (real Postgres)',
oauthClientId: 'google-drive',
})
).toBe(false)
+ // … but the sibling ctx-B shared grant on the SAME server SURVIVES. Drop the
+ // `context_id` predicate from the shared DELETE and this flips to false.
+ expect(
+ await oauthGrantExists(db, {
+ grantKind: 'shared',
+ ownerKind: 'mcpserver',
+ recipeNamespace: NS,
+ recipeName: 'teamdrive',
+ contextId: 'ctx-B',
+ oauthClientId: 'google-drive',
+ })
+ ).toBe(true)
})
it('context flavor without contextRef: key is null (fail-closed, never a blind delete)', () => {