Skip to content

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

TypeScript

test(llm-proxy): refuse a body limit below the contract floor (#739)

Alfredo Lopez76ddcfdf2a73
diff --git a/codex-llm-proxy/test/server.security.test.ts b/codex-llm-proxy/test/server.security.test.ts
index 92a11102f..0ba3e27a5 100644
--- a/codex-llm-proxy/test/server.security.test.ts
+++ b/codex-llm-proxy/test/server.security.test.ts
@@ -553,6 +553,23 @@ describe('codex-llm-proxy startup config', () => {
expect(loadConfig(base).maxBodyBytes).toBe(LIMITS.maxRequestBodyBytes + 16 * 1024)
})
+ // R9-3 (L-3) — a lower override would answer 413 to requests the contract
+ // accepts, so it is refused at startup, as the visual override is.
+ it('T-R9-3 refuses a body limit below the contract request cap plus the envelope allowance', () => {
+ const floor = LIMITS.maxRequestBodyBytes + ENVELOPE_ALLOWANCE_BYTES
+ expect(() => loadConfig({ ...base, CODEX_LLM_PROXY_MAX_BODY_BYTES: String(floor - 1) })).toThrow(
+ 'CODEX_LLM_PROXY_MAX_BODY_BYTES must be at least the contract request cap plus the envelope allowance'
+ )
+ expect(() =>
+ loadConfig({ ...base, CODEX_LLM_PROXY_MAX_BODY_BYTES: String(LIMITS.maxRequestBodyBytes) })
+ ).toThrow(/CODEX_LLM_PROXY_MAX_BODY_BYTES must be at least/)
+ // Witness: the floor itself and any larger value load.
+ expect(loadConfig({ ...base, CODEX_LLM_PROXY_MAX_BODY_BYTES: String(floor) }).maxBodyBytes).toBe(floor)
+ expect(loadConfig({ ...base, CODEX_LLM_PROXY_MAX_BODY_BYTES: String(floor + 1) }).maxBodyBytes).toBe(
+ floor + 1
+ )
+ })
+
it('T-R2-6c does not refuse a request at the contract cap with a real ticket as payload_too_large', async () => {
const { runtimeApp } = createProxyApps(config({ maxBodyBytes: loadConfig(base).maxBodyBytes }))
const atCap = { pad: 'x'.repeat(LIMITS.maxRequestBodyBytes - '{"pad":""}'.length) }
diff --git a/grok-llm-proxy/test/server.security.test.ts b/grok-llm-proxy/test/server.security.test.ts
index a401c594a..50e37bc0b 100644
--- a/grok-llm-proxy/test/server.security.test.ts
+++ b/grok-llm-proxy/test/server.security.test.ts
@@ -19,6 +19,7 @@ import {
import { MAX_TOOL_CALL_ARGUMENT_CHARS } from '../src/grokTransport.js'
import { REDACT_PATHS, logger } from '../src/logger.js'
import { GROK_CATALOG_ORIGIN, GROK_COMPLETIONS_ORIGIN } from '../src/originPolicy.js'
+import { ENVELOPE_ALLOWANCE_BYTES } from '../src/requestLimits.js'
import { createProxyApps } from '../src/server.js'
const { privateKey, publicKey } = generateKeyPairSync('rsa', {
@@ -437,6 +438,23 @@ describe('grok-llm-proxy startup config', () => {
expect(loadConfig(base).maxBodyBytes).toBe(LIMITS.maxRequestBodyBytes + 16 * 1024)
})
+ // R9-3 (L-3) — a lower override would answer 413 to requests the contract
+ // accepts, so it is refused at startup.
+ it('T-R9-3-grok refuses a body limit below the contract request cap plus the envelope allowance', () => {
+ const floor = LIMITS.maxRequestBodyBytes + ENVELOPE_ALLOWANCE_BYTES
+ expect(() => loadConfig({ ...base, GROK_LLM_PROXY_MAX_BODY_BYTES: String(floor - 1) })).toThrow(
+ 'GROK_LLM_PROXY_MAX_BODY_BYTES must be at least the contract request cap plus the envelope allowance'
+ )
+ expect(() =>
+ loadConfig({ ...base, GROK_LLM_PROXY_MAX_BODY_BYTES: String(LIMITS.maxRequestBodyBytes) })
+ ).toThrow(/GROK_LLM_PROXY_MAX_BODY_BYTES must be at least/)
+ // Witness: the floor itself and any larger value load.
+ expect(loadConfig({ ...base, GROK_LLM_PROXY_MAX_BODY_BYTES: String(floor) }).maxBodyBytes).toBe(floor)
+ expect(loadConfig({ ...base, GROK_LLM_PROXY_MAX_BODY_BYTES: String(floor + 1) }).maxBodyBytes).toBe(
+ floor + 1
+ )
+ })
+
it('T-R2-6c-grok does not refuse a request at the contract cap with a real ticket as payload_too_large', async () => {
const { runtimeApp } = createProxyApps(config({ maxBodyBytes: loadConfig(base).maxBodyBytes }))
const atCap = { pad: 'x'.repeat(LIMITS.maxRequestBodyBytes - '{"pad":""}'.length) }