Skip to content

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

TypeScript

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

Alfredo Lopez996452900743
diff --git a/codex-llm-proxy/src/config.ts b/codex-llm-proxy/src/config.ts
index 69349ddc1..f64b31611 100644
--- a/codex-llm-proxy/src/config.ts
+++ b/codex-llm-proxy/src/config.ts
@@ -65,6 +65,12 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): CodexLlmProxyC
env.CODEX_LLM_PROXY_MAX_BODY_BYTES,
DEFAULT_MAX_BODY_BYTES
)
+ // R9-3: a lower limit would answer 413 to requests the contract accepts.
+ if (maxBodyBytes < DEFAULT_MAX_BODY_BYTES) {
+ throw new Error(
+ 'CODEX_LLM_PROXY_MAX_BODY_BYTES must be at least the contract request cap plus the envelope allowance'
+ )
+ }
const maxVisualBodyBytes = requiredPositiveInt(
'CODEX_LLM_PROXY_MAX_VISUAL_BODY_BYTES',
env.CODEX_LLM_PROXY_MAX_VISUAL_BODY_BYTES,
diff --git a/grok-llm-proxy/src/config.ts b/grok-llm-proxy/src/config.ts
index c266547c8..7b8760757 100644
--- a/grok-llm-proxy/src/config.ts
+++ b/grok-llm-proxy/src/config.ts
@@ -58,6 +58,17 @@ function requiredNonEmpty(name: string, raw: string | undefined): string {
}
export function loadConfig(env: NodeJS.ProcessEnv = process.env): GrokLlmProxyConfig {
+ const maxBodyBytes = requiredPositiveInt(
+ 'GROK_LLM_PROXY_MAX_BODY_BYTES',
+ env.GROK_LLM_PROXY_MAX_BODY_BYTES,
+ DEFAULT_MAX_BODY_BYTES
+ )
+ // R9-3: a lower limit would answer 413 to requests the contract accepts.
+ if (maxBodyBytes < DEFAULT_MAX_BODY_BYTES) {
+ throw new Error(
+ 'GROK_LLM_PROXY_MAX_BODY_BYTES must be at least the contract request cap plus the envelope allowance'
+ )
+ }
return {
runtimePort: requiredPositiveInt(
'GROK_LLM_PROXY_RUNTIME_PORT',
@@ -74,11 +85,7 @@ export function loadConfig(env: NodeJS.ProcessEnv = process.env): GrokLlmProxyCo
env.GROK_LLM_PROXY_PROBE_PORT,
9090
),
- maxBodyBytes: requiredPositiveInt(
- 'GROK_LLM_PROXY_MAX_BODY_BYTES',
- env.GROK_LLM_PROXY_MAX_BODY_BYTES,
- DEFAULT_MAX_BODY_BYTES
- ),
+ maxBodyBytes,
maxStreamDurationMs: requiredPositiveInt(
'GROK_LLM_PROXY_MAX_STREAM_DURATION_MS',
env.GROK_LLM_PROXY_MAX_STREAM_DURATION_MS,