Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(rpc-proxy): subject_mismatch is a denial, not a revocation
Alfredo Lopezcd8e11598e9e
diff --git a/external-rest-api/src/releaseManifest.ts b/external-rest-api/src/releaseManifest.tsindex 1784fe811..0d9f7c23f 100644--- a/external-rest-api/src/releaseManifest.ts+++ b/external-rest-api/src/releaseManifest.ts@@ -9,7 +9,7 @@ export type ReleaseManifest = {export const releaseManifest: ReleaseManifest = {releaseId: 'v0.10.0',externalRestApiVersion: '0.1.85',- rpcProxyVersion: '0.1.106',+ rpcProxyVersion: '0.1.107',desktopVersion: '0.10.0',minimumDesktopVersion: '0.1.252',}diff --git a/rpc-proxy/package-lock.json b/rpc-proxy/package-lock.jsonindex c379d0443..a21e531c4 100644--- a/rpc-proxy/package-lock.json+++ b/rpc-proxy/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-rpc-proxy",- "version": "0.1.106",+ "version": "0.1.107","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-rpc-proxy",- "version": "0.1.106",+ "version": "0.1.107","dependencies": {"cors": "^2.8.5","express": "^4.21.2",diff --git a/rpc-proxy/package.json b/rpc-proxy/package.jsonindex 011d3b2b5..1f61287b6 100644--- a/rpc-proxy/package.json+++ b/rpc-proxy/package.json@@ -1,6 +1,6 @@{"name": "clerum-rpc-proxy",- "version": "0.1.106",+ "version": "0.1.107","description": "External-facing RPC proxy for tenant-scoped MCP access","main": "dist/main.js","engines": {diff --git a/rpc-proxy/src/__tests__/host-access-denial-code.route.test.ts b/rpc-proxy/src/__tests__/host-access-denial-code.route.test.tsindex 053cd2b8f..6d4a64105 100644--- a/rpc-proxy/src/__tests__/host-access-denial-code.route.test.ts+++ b/rpc-proxy/src/__tests__/host-access-denial-code.route.test.ts@@ -6,6 +6,7 @@ import { createRpcRouter } from '../routes/rpc.js'import { createRpcHostActivityStreamRouter } from '../routes/rpcHostActivityStream.js'import { createRpcHostProgressStreamRouter } from '../routes/rpcHostProgressStream.js'import { createRpcHostStatusStreamRouter } from '../routes/rpcHostStatusStream.js'+import { hostAccessDenialCodeForReason } from '../services/hostAccessDenial.js'// PR #849 R1-M6 producer side (also R1-L7 on the rpc-proxy side).//@@ -205,13 +206,24 @@ describe('host authorization 403 carries a machine-readable code at every site',})})+describe('R3-L8 hostAccessDenialCodeForReason', () => {+ it('subject_mismatch is a denial; removed membership and grants are revocations', () => {+ // Positive controls: the revoked set is live.+ expect(hostAccessDenialCodeForReason('team_membership_missing')).toBe('host_access_revoked')+ expect(hostAccessDenialCodeForReason('directory_grant_missing')).toBe('host_access_revoked')+ expect(hostAccessDenialCodeForReason('subject_mismatch')).toBe('host_access_denied')+ })+})+describe('control-api 403 reason -> code mapping', () => {const status = DENYING_ROUTES.find(route => route.label === 'status')!it.each([['team_membership_missing', 'host_access_revoked'],['directory_grant_missing', 'host_access_revoked'],- ['subject_mismatch', 'host_access_revoked'],+ // R3-L8: the route's userId is the token's own sub, so a mismatch is a+ // request-shape error, not a removed grant.+ ['subject_mismatch', 'host_access_denied'],['host_disabled', 'host_access_denied'],['host_missing', 'host_access_denied'],['host_claim_missing', 'host_access_denied'],@@ -245,7 +257,9 @@ describe('control-api 403 reason -> code mapping', () => {})- it.each(['directory_grant_missing', 'team_membership_missing', 'subject_mismatch'])(+ // Only reasons that map to host_access_revoked as a header give this test+ // power: a denied-anyway reason would pass even if the body were read.+ it.each(['directory_grant_missing', 'team_membership_missing'])('a legacy body-only reason %s (no header) is ignored -> host_access_denied',async reason => {// Proves the 403 body is never read: the same reason that maps todiff --git a/rpc-proxy/src/services/hostAccessDenial.ts b/rpc-proxy/src/services/hostAccessDenial.tsindex d758ca5b7..8166349ea 100644--- a/rpc-proxy/src/services/hostAccessDenial.ts+++ b/rpc-proxy/src/services/hostAccessDenial.ts@@ -15,13 +15,16 @@ export type HostAccessDenial = { denied: true; code: HostAccessDenialCode }/*** control-api denial reasons (control-api `RpcHostAccessDenialReason`) that* prove the access was actually removed from the user. Every other reason- * (`host_disabled`, `host_missing`, `host_claim_missing`, an unknown or absent- * reason) is a denial that does not prove revocation.+ * (`host_disabled`, `host_missing`, `host_claim_missing`, `subject_mismatch`,+ * an unknown or absent reason) is a denial that does not prove revocation.+ * `subject_mismatch` in particular: rpc-proxy calls+ * `/rpc/access/users/:userId/...` with the token's own `sub` as `userId`+ * (control-api `routes/rpc-access/users.ts`), so a mismatch is a request-shape+ * error, never a grant that was removed.*/const REVOKED_CONTROL_API_REASONS: ReadonlySet<string> = new Set(['team_membership_missing','directory_grant_missing',- 'subject_mismatch',])export function hostAccessDenialCodeForReason(reason: unknown): HostAccessDenialCode {diff --git a/rpc-proxy/test/services.controlApiHostAccess.test.ts b/rpc-proxy/test/services.controlApiHostAccess.test.tsindex f6715a209..0d2e1ac09 100644--- a/rpc-proxy/test/services.controlApiHostAccess.test.ts+++ b/rpc-proxy/test/services.controlApiHostAccess.test.ts@@ -78,12 +78,13 @@ describe('control-api canonical host access client', () => {const FORBIDDEN_BODY = { error: 'Forbidden' }// R1-M6: the denial reason (read from the response header, never the body)- // decides whether Desktop may treat the loss as a revocation. Only the three- // reasons that prove removed access map to `host_access_revoked`.+ // decides whether Desktop may treat the loss as a revocation. Only the two+ // reasons that prove removed access map to `host_access_revoked`;+ // `subject_mismatch` is a request-shape error (R3-L8).it.each([['team_membership_missing', 'host_access_revoked'],['directory_grant_missing', 'host_access_revoked'],- ['subject_mismatch', 'host_access_revoked'],+ ['subject_mismatch', 'host_access_denied'],['host_disabled', 'host_access_denied'],['host_missing', 'host_access_denied'],['host_claim_missing', 'host_access_denied'],@@ -122,9 +123,14 @@ describe('control-api canonical host access client', () => {})it('a non-direct-run 403 with a non-JSON body still honours the header', async () => {+ // A revoking reason: a denied-anyway reason would pass even if the header+ // were ignored.const fetchImpl = vi.fn(async () =>- new Response('not json', { status: 403, headers: { [REASON_HEADER]: 'subject_mismatch' } })+ new Response('not json', {+ status: 403,+ headers: { [REASON_HEADER]: 'team_membership_missing' },+ }))await expect(