Skip to content

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

TypeScript

test(rpc-proxy,mcp-host): pin the canonical-alphabet and padding rules of the file credit

Alfredo Lopezb86ecfe1b1c7
diff --git a/external-rest-api/src/releaseManifest.ts b/external-rest-api/src/releaseManifest.ts
index 18182251e..e3307d2e2 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.112',
+ rpcProxyVersion: '0.1.113',
desktopVersion: '0.10.0',
minimumDesktopVersion: '0.1.252',
}
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index e27c32cf6..660e6c099 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.479",
+ "version": "0.1.480",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.479",
+ "version": "0.1.480",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@anthropic-ai/sdk": "^0.32.0",
diff --git a/mcp-host/package.json b/mcp-host/package.json
index 566043608..8efd07c91 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.479",
+ "version": "0.1.480",
"description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude",
"main": "dist/main.js",
"engines": {
diff --git a/mcp-host/src/__tests__/bodylimits.test.ts b/mcp-host/src/__tests__/bodylimits.test.ts
index 07d64cc6d..85e53df4b 100644
--- a/mcp-host/src/__tests__/bodylimits.test.ts
+++ b/mcp-host/src/__tests__/bodylimits.test.ts
@@ -93,6 +93,23 @@ function withNonCanonicalTailBits(base64: string): string {
return base64.slice(0, lastIndex) + mutated + base64.slice(lastIndex + 1)
}
+/**
+ * Replace the final padded sextet with `sextet`. With '/' (63) every unused
+ * low bit is set, so the payload decodes to the same length but is not the
+ * canonical encoding of its bytes.
+ */
+function withFinalSextet(base64: string, sextet: string): string {
+ const padding = base64.endsWith('==') ? 2 : base64.endsWith('=') ? 1 : 0
+ if (padding === 0) throw new Error('fixture expects a padded base64 payload')
+ const lastIndex = base64.length - 1 - padding
+ return base64.slice(0, lastIndex) + sextet + base64.slice(lastIndex + 1)
+}
+
+/** The same bytes in the URL-safe alphabet (RFC 4648 §5): '-' for '+', '_' for '/'. */
+function toUrlSafeBase64(base64: string): string {
+ return base64.replace(/\+/g, '-').replace(/\//g, '_')
+}
+
function imageAttachment(
id: string,
sizeBytes: number,
@@ -439,6 +456,27 @@ describe('mcp-host runtime message body budget', () => {
expect(captured).toHaveLength(0)
})
+ it('does not credit an 11MiB file whose base64 uses the URL-safe alphabet', async () => {
+ const bytes = Buffer.alloc(FILE_MAX_BYTES, 0x61)
+ // 0xfbefbe encodes as '++++' and 0xffffff as '////'.
+ bytes.set([0xfb, 0xef, 0xbe, 0xff, 0xff, 0xff], 0)
+ const standard = { ...textFile('f1', FILE_MAX_BYTES), dataBase64: bytes.toString('base64') }
+ const urlSafe = { ...standard, dataBase64: toUrlSafeBase64(standard.dataBase64) }
+ expect(standard.dataBase64.startsWith('++++////')).toBe(true)
+ expect(urlSafe.dataBase64.startsWith('----____')).toBe(true)
+ // Sanity: Node's permissive decoder reads both alphabets to the same bytes,
+ // so only the alphabet rule can refuse the credit.
+ expect(Buffer.from(urlSafe.dataBase64, 'base64').equals(bytes)).toBe(true)
+ captured = []
+ expect((await postMessage(messageWithShare([standard], KIB))).status).toBe(200)
+ expect(captured).toHaveLength(1)
+ captured = []
+ // Uncredited, the ~14.7MiB of base64 is charged to the 6MiB share.
+ const response = await postMessage(messageWithShare([urlSafe], KIB))
+ expect(response.status).toBe(413)
+ expect(captured).toHaveLength(0)
+ })
+
it.each([
{ label: 'no digest', mutate: ({ digest: _d, ...rest }: Record<string, unknown>) => rest },
{
@@ -602,6 +640,26 @@ describe('mcp-host runtime message body budget', () => {
expect(captured).toHaveLength(0)
})
+ it("does not credit base64 whose final padded sextet is '/'", async () => {
+ const canonical = pngBase64(5 * MIB)
+ const slashTail = withFinalSextet(canonical, '/')
+ expect(slashTail).not.toBe(canonical)
+ // Sanity: permissive decoding still yields the same length, so the only
+ // thing that can reject this payload is the canonical-encoding rule.
+ expect(Buffer.from(slashTail, 'base64').length).toBe(Buffer.from(canonical, 'base64').length)
+ const withImage = (dataBase64: string) =>
+ messagePayload([
+ { id: 'a1', kind: 'image', mimeType: 'image/png', encoding: 'base64', dataBase64 },
+ ])
+ captured = []
+ expect((await postMessage(withImage(canonical))).status).toBe(200)
+ expect(captured).toHaveLength(1)
+ captured = []
+ const response = await postMessage(withImage(slashTail))
+ expect(response.status).toBe(413)
+ expect(captured).toHaveLength(0)
+ })
+
it('keeps the 10mb parser on every other POST route', async () => {
const over = await fetch(`${baseUrl}/v1/runtime/model`, {
method: 'POST',
diff --git a/mcp-host/src/core/orchestration/__tests__/toolUseLoop.spillover.test.ts b/mcp-host/src/core/orchestration/__tests__/toolUseLoop.spillover.test.ts
index ce37ed697..a1c176d3a 100644
--- a/mcp-host/src/core/orchestration/__tests__/toolUseLoop.spillover.test.ts
+++ b/mcp-host/src/core/orchestration/__tests__/toolUseLoop.spillover.test.ts
@@ -219,7 +219,7 @@ describe('executeSingleTool — T1.5 spillover wiring', () => {
expect(result.spillover_ref).toBeUndefined()
})
- it('never spills the output of clerum__spillover_read (no recursion)', async () => {
+ it('the storage name guard never spills clerum__spillover_read output, even from a tool without spilloverExempt', async () => {
const big = 'X'.repeat(512)
const result = await executeSingleTool(
{ id: 'call-1', name: 'clerum__spillover_read', arguments: {} },
diff --git a/rpc-proxy/package-lock.json b/rpc-proxy/package-lock.json
index 6e2967f85..c4fee10b4 100644
--- a/rpc-proxy/package-lock.json
+++ b/rpc-proxy/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-rpc-proxy",
- "version": "0.1.112",
+ "version": "0.1.113",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-rpc-proxy",
- "version": "0.1.112",
+ "version": "0.1.113",
"dependencies": {
"cors": "^2.8.5",
"express": "^4.21.2",
diff --git a/rpc-proxy/package.json b/rpc-proxy/package.json
index ed2a02696..b0d3ec855 100644
--- a/rpc-proxy/package.json
+++ b/rpc-proxy/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-rpc-proxy",
- "version": "0.1.112",
+ "version": "0.1.113",
"description": "External-facing RPC proxy for tenant-scoped MCP access",
"main": "dist/main.js",
"engines": {
diff --git a/rpc-proxy/src/__tests__/bodylimits.test.ts b/rpc-proxy/src/__tests__/bodylimits.test.ts
index 9efbd8843..20cd5ee4b 100644
--- a/rpc-proxy/src/__tests__/bodylimits.test.ts
+++ b/rpc-proxy/src/__tests__/bodylimits.test.ts
@@ -129,6 +129,23 @@ function withNonCanonicalTailBits(base64: string): string {
return base64.slice(0, lastIndex) + mutated + base64.slice(lastIndex + 1)
}
+/**
+ * Replace the final padded sextet with `sextet`. With '/' (63) every unused
+ * low bit is set, so the payload decodes to the same length but is not the
+ * canonical encoding of its bytes.
+ */
+function withFinalSextet(base64: string, sextet: string): string {
+ const padding = base64.endsWith('==') ? 2 : base64.endsWith('=') ? 1 : 0
+ if (padding === 0) throw new Error('fixture expects a padded base64 payload')
+ const lastIndex = base64.length - 1 - padding
+ return base64.slice(0, lastIndex) + sextet + base64.slice(lastIndex + 1)
+}
+
+/** The same bytes in the URL-safe alphabet (RFC 4648 §5): '-' for '+', '_' for '/'. */
+function toUrlSafeBase64(base64: string): string {
+ return base64.replace(/\+/g, '-').replace(/\//g, '_')
+}
+
function imageAttachment(
id: string,
sizeBytes: number,
@@ -477,6 +494,26 @@ describe('rpc-proxy chat message body budget', () => {
expect(serviceMock.forwardHostMessageToHost).not.toHaveBeenCalled()
})
+ it('does not credit an 11MiB file whose base64 uses the URL-safe alphabet', async () => {
+ const bytes = Buffer.alloc(FILE_MAX_BYTES, 0x61)
+ // 0xfbefbe encodes as '++++' and 0xffffff as '////'.
+ bytes.set([0xfb, 0xef, 0xbe, 0xff, 0xff, 0xff], 0)
+ const standard = { ...textFile('f1', FILE_MAX_BYTES), dataBase64: bytes.toString('base64') }
+ const urlSafe = { ...standard, dataBase64: toUrlSafeBase64(standard.dataBase64) }
+ expect(standard.dataBase64.startsWith('++++////')).toBe(true)
+ expect(urlSafe.dataBase64.startsWith('----____')).toBe(true)
+ // Sanity: Node's permissive decoder reads both alphabets to the same bytes,
+ // so only the alphabet rule can refuse the credit.
+ expect(Buffer.from(urlSafe.dataBase64, 'base64').equals(bytes)).toBe(true)
+ expect((await postMessage(messageWithShare([standard], KIB))).status).toBe(200)
+ expect(serviceMock.forwardHostMessageToHost).toHaveBeenCalledTimes(1)
+ vi.clearAllMocks()
+ // Uncredited, the ~14.7MiB of base64 is charged to the 6MiB share.
+ const response = await postMessage(messageWithShare([urlSafe], KIB))
+ expect(response.status).toBe(413)
+ expect(serviceMock.forwardHostMessageToHost).not.toHaveBeenCalled()
+ })
+
it.each([
{ label: 'no digest', mutate: ({ digest: _d, ...rest }: Record<string, unknown>) => rest },
{
@@ -636,6 +673,27 @@ describe('rpc-proxy chat message body budget', () => {
expect(response.status).toBe(413)
})
+ it("does not credit base64 whose final padded sextet is '/'", async () => {
+ const canonical = pngBase64(5 * MIB)
+ const slashTail = withFinalSextet(canonical, '/')
+ expect(slashTail).not.toBe(canonical)
+ // Sanity: permissive decoding still yields the same length, so the only
+ // thing that can reject this payload is the canonical-encoding rule.
+ expect(Buffer.from(slashTail, 'base64').length).toBe(Buffer.from(canonical, 'base64').length)
+ const withImage = (dataBase64: string) => ({
+ content: 'x'.repeat(MIB),
+ attachments: [
+ { id: 'a1', kind: 'image', mimeType: 'image/png', encoding: 'base64', dataBase64 },
+ ],
+ })
+ expect((await postMessage(withImage(canonical))).status).toBe(200)
+ expect(serviceMock.forwardHostMessageToHost).toHaveBeenCalledTimes(1)
+ vi.clearAllMocks()
+ const response = await postMessage(withImage(slashTail))
+ expect(response.status).toBe(413)
+ expect(serviceMock.forwardHostMessageToHost).not.toHaveBeenCalled()
+ })
+
it('keeps the 10mb parser on authenticated non-chat JSON routes', async () => {
const response = await post('/api/v1/rpc/demo', JSON.stringify({ a: 'x'.repeat(11 * MIB) }))
expect(response.status).toBe(413)