Skip to content

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

TypeScript

test(rpc-proxy): guard the host-access denial contract across services

Alfredo Lopezba864331db31
diff --git a/external-rest-api/src/releaseManifest.ts b/external-rest-api/src/releaseManifest.ts
index 0d9f7c23f..d34efae13 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.107',
+ rpcProxyVersion: '0.1.108',
desktopVersion: '0.10.0',
minimumDesktopVersion: '0.1.252',
}
diff --git a/rpc-proxy/package-lock.json b/rpc-proxy/package-lock.json
index a21e531c4..7971bd037 100644
--- a/rpc-proxy/package-lock.json
+++ b/rpc-proxy/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-rpc-proxy",
- "version": "0.1.107",
+ "version": "0.1.108",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-rpc-proxy",
- "version": "0.1.107",
+ "version": "0.1.108",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.21.2",
diff --git a/rpc-proxy/package.json b/rpc-proxy/package.json
index 1f61287b6..7b4fc06b2 100644
--- a/rpc-proxy/package.json
+++ b/rpc-proxy/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-rpc-proxy",
- "version": "0.1.107",
+ "version": "0.1.108",
"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.cross-service.test.ts b/rpc-proxy/src/__tests__/host-access-denial.cross-service.test.ts
new file mode 100644
index 000000000..095d0eac8
--- /dev/null
+++ b/rpc-proxy/src/__tests__/host-access-denial.cross-service.test.ts
@@ -0,0 +1,120 @@
+import { describe, expect, it } from 'vitest'
+import { readFileSync } from 'node:fs'
+import { hostAccessDenialCodeForReason } from '../services/hostAccessDenial.js'
+
+/**
+ * PR #849 R3-L9: cross-service guard for the Host-access denial contract.
+ *
+ * control-api names the denial reason (`RpcHostAccessDenialReason`) and sends it
+ * in a response header; rpc-proxy reads that header, maps the reason to a
+ * `HostAccessDenialCode`, and Desktop matches the code against its own
+ * constants. The three services share no module, so each hop is read here as
+ * source and compared. The rpc-proxy literals are also checked against the
+ * running mapping, so a parse that drifted from the code fails instead of
+ * comparing stale text.
+ */
+
+function read(relativeFromThisFile: string): string {
+ return readFileSync(new URL(relativeFromThisFile, import.meta.url), 'utf-8')
+}
+
+/** Fail-loud single-match extraction — a miss means the source moved. */
+function extractOne(source: string, pattern: RegExp, label: string): string {
+ const match = source.match(pattern)
+ if (!match || match[1] === undefined) {
+ throw new Error(`Could not extract ${label} with ${pattern} — re-derive the guard`)
+ }
+ return match[1]
+}
+
+/** Every single-quoted literal of a union or array body; empty is a failure. */
+function quotedLiterals(body: string, label: string): string[] {
+ const literals = [...body.matchAll(/'([^']+)'/g)].map(match => match[1]!)
+ if (literals.length === 0) throw new Error(`No literals found in ${label}`)
+ return literals
+}
+
+const controlApiAuthorizer = read(
+ '../../../control-api/src/services/access/rpcHostAccessAuthorizer.ts'
+)
+const controlApiRoute = read('../../../control-api/src/routes/rpc-access/users.ts')
+const rpcProxyRestService = read('../services/controlApiRestService.ts')
+const rpcProxyDenial = read('../services/hostAccessDenial.ts')
+const desktopUpstreamErrors = read('../../../desktop-app/src/upstreamErrors.ts')
+
+const controlApiReasons = quotedLiterals(
+ extractOne(
+ controlApiAuthorizer,
+ /export type RpcHostAccessDenialReason =([\s\S]*?)\n\n/,
+ 'control-api RpcHostAccessDenialReason'
+ ),
+ 'control-api RpcHostAccessDenialReason'
+)
+const revokedReasons = quotedLiterals(
+ extractOne(
+ rpcProxyDenial,
+ /const REVOKED_CONTROL_API_REASONS: ReadonlySet<string> = new Set\(\[([\s\S]*?)\]\)/,
+ 'rpc-proxy REVOKED_CONTROL_API_REASONS'
+ ),
+ 'rpc-proxy REVOKED_CONTROL_API_REASONS'
+)
+const rpcProxyCodes = quotedLiterals(
+ extractOne(
+ rpcProxyDenial,
+ /export type HostAccessDenialCode = ([^\n]+)/,
+ 'rpc-proxy HostAccessDenialCode'
+ ),
+ 'rpc-proxy HostAccessDenialCode'
+)
+const desktopRevokedCode = extractOne(
+ desktopUpstreamErrors,
+ /export const HOST_ACCESS_REVOKED_CODE = '([^']+)'/,
+ 'desktop HOST_ACCESS_REVOKED_CODE'
+)
+const desktopDeniedCode = extractOne(
+ desktopUpstreamErrors,
+ /export const HOST_ACCESS_DENIED_CODE = '([^']+)'/,
+ 'desktop HOST_ACCESS_DENIED_CODE'
+)
+
+describe('R3-L9 Host-access denial contract across control-api, rpc-proxy and Desktop', () => {
+ it('rpc-proxy reads the denial-reason header under the name control-api sends it', () => {
+ const sent = extractOne(
+ controlApiRoute,
+ /export const HOST_ACCESS_DENIAL_REASON_HEADER = '([^']+)'/,
+ 'control-api HOST_ACCESS_DENIAL_REASON_HEADER'
+ )
+ const received = extractOne(
+ rpcProxyRestService,
+ /const reason = response\.headers\.get\('([^']+)'\)/,
+ 'rpc-proxy denial-reason header read'
+ )
+
+ expect(received).toBe(sent)
+ })
+
+ it('every revoking reason in rpc-proxy is a reason control-api can send', () => {
+ // Witness: the parsed set is the running set.
+ for (const reason of revokedReasons) {
+ expect(hostAccessDenialCodeForReason(reason)).toBe('host_access_revoked')
+ }
+ for (const reason of revokedReasons) {
+ expect(controlApiReasons).toContain(reason)
+ }
+ // And every other control-api reason is a plain denial.
+ const deniedReasons = controlApiReasons.filter(r => !revokedReasons.includes(r))
+ expect(deniedReasons.length).toBeGreaterThan(0)
+ for (const reason of deniedReasons) {
+ expect(hostAccessDenialCodeForReason(reason)).toBe('host_access_denied')
+ }
+ })
+
+ it('Desktop matches exactly the codes rpc-proxy emits', () => {
+ expect([...rpcProxyCodes].sort()).toEqual([desktopDeniedCode, desktopRevokedCode].sort())
+ // The running mapping emits Desktop's literals for both outcomes.
+ for (const reason of revokedReasons) {
+ expect(hostAccessDenialCodeForReason(reason)).toBe(desktopRevokedCode)
+ }
+ expect(hostAccessDenialCodeForReason('a_reason_no_service_sends')).toBe(desktopDeniedCode)
+ })
+})