Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix: admit a cap-sized request on the LLM authorize route (#731)
Alfredo Lopez59ce5d3c29a7
diff --git a/control-api/package-lock.json b/control-api/package-lock.jsonindex f64de5231..716800e60 100644--- a/control-api/package-lock.json+++ b/control-api/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-api",- "version": "0.1.600",+ "version": "0.1.601","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-api",- "version": "0.1.600",+ "version": "0.1.601","dependencies": {"@clerum/display-field": "file:../packages/display-field","@clerum/grok-provider-attempt-contract": "file:../packages/grok-provider-attempt-contract",diff --git a/control-api/package.json b/control-api/package.jsonindex 20033d94b..a4c6f4544 100644--- a/control-api/package.json+++ b/control-api/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-api",- "version": "0.1.600",+ "version": "0.1.601","description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets","main": "dist/main.js","engines": {diff --git a/control-api/src/services/llmProviderAttemptAuthorizer.ts b/control-api/src/services/llmProviderAttemptAuthorizer.tsindex e428f1a88..287e71bc3 100644--- a/control-api/src/services/llmProviderAttemptAuthorizer.ts+++ b/control-api/src/services/llmProviderAttemptAuthorizer.ts@@ -150,6 +150,16 @@ export { computeCodexPolicyHash }// body root, and may itself nest maxNestingDepth containers.const MAX_AUTHORIZE_BODY_DEPTH = Math.max(LIMITS.maxNestingDepth, GROK_LIMITS.maxNestingDepth) + 6+/**+ * #731 — room for the authorize envelope around the contract-capped `request`:+ * ids, revisions, hashes and recipe names, a few hundred bytes in practice.+ * The whole-body check bounds serialization cost before parsing; the request+ * itself is held to maxRequestBodyBytes by the contract parser, so a request+ * at the cap is never refused for its envelope. The gateway's+ * client_max_body_size on this route is the cap plus this allowance.+ */+export const AUTHORIZE_ENVELOPE_ALLOWANCE_BYTES = 16 * 1024+/*** Reject an over-deep body before anything serializes it. Iterative, so an* attacker-controlled nesting depth cannot overflow the stack here; without it@@ -253,7 +263,10 @@ async function authorizeGrokProviderAttempt(}assertBodyNestingWithinLimit(body)const serialized = JSON.stringify(body)- if (Buffer.byteLength(serialized, 'utf8') > GROK_LIMITS.maxRequestBodyBytes) {+ if (+ Buffer.byteLength(serialized, 'utf8') >+ GROK_LIMITS.maxRequestBodyBytes + AUTHORIZE_ENVELOPE_ALLOWANCE_BYTES+ ) {throw new LlmProviderAttemptAuthorizeError('invalid_request', 'request body exceeds the limit')}const unknown = firstUnknownKey(body)@@ -612,7 +625,10 @@ export async function authorizeLlmProviderAttempt(}assertBodyNestingWithinLimit(body)const serialized = JSON.stringify(body)- if (Buffer.byteLength(serialized, 'utf8') > LIMITS.maxRequestBodyBytes) {+ if (+ Buffer.byteLength(serialized, 'utf8') >+ LIMITS.maxRequestBodyBytes + AUTHORIZE_ENVELOPE_ALLOWANCE_BYTES+ ) {throw new LlmProviderAttemptAuthorizeError('invalid_request', 'request body exceeds the limit')}const unknown = firstUnknownKey(body)diff --git a/deploy/base/control-plane/configmaps.yaml b/deploy/base/control-plane/configmaps.yamlindex 1323bf289..8d96f13e1 100644--- a/deploy/base/control-plane/configmaps.yaml+++ b/deploy/base/control-plane/configmaps.yaml@@ -802,6 +802,10 @@ data:limit_except POST {deny all;}+ # #731: the contract request cap (8 MiB) plus control-api's 16 KiB+ # authorize envelope allowance. Without it nginx's 1m default refuses+ # a contract-valid request before control-api sees it.+ client_max_body_size 8404992;proxy_pass http://control_api_upstream;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;