Skip to content

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

TypeScript

test(llm-proxy): bound the execution ticket at the envelope allowance

Alfredo Lopez20ed66902b5a
diff --git a/codex-llm-proxy/test/server.security.test.ts b/codex-llm-proxy/test/server.security.test.ts
index 929be782c..44221d8e9 100644
--- a/codex-llm-proxy/test/server.security.test.ts
+++ b/codex-llm-proxy/test/server.security.test.ts
@@ -28,6 +28,7 @@ import {
RequestLimitError,
STREAM_LIMITS,
streamGate,
+ visualStreamGate,
} from '../src/requestLimits.js'
import { createProxyApps } from '../src/server.js'
import { UPSTREAM_CONTEXT_OVERFLOW_FRAMES } from './fixtures/upstreamContextOverflow.js'
@@ -235,6 +236,40 @@ describe('codex-llm-proxy security surface', () => {
expect(admin.status).toBe(413)
})
+ // r10 Y1: the ticket is a signed JWT of a few hundred bytes. The non-image
+ // ceiling alone lets an ~8 MiB ticket reach jwt.verify, so the schema bounds
+ // it at the envelope allowance.
+ it('T-Y1-codex bounds the execution ticket at the envelope allowance before verifying it', async () => {
+ const { runtimeApp } = createProxyApps(config({ maxBodyBytes: DEFAULT_MAX_BODY_BYTES }))
+ const send = (executionTicket: string, body: Record<string, unknown> = {}) =>
+ request(runtimeApp)
+ .post('/internal/runtime/v1/codex/completions')
+ .set('Authorization', `Bearer ${platformToken()}`)
+ .send({ executionTicket, requestHash: 'a'.repeat(64), request: body })
+
+ // Witness: a ticket exactly at the bound reaches the verifier.
+ const atBound = await send('x'.repeat(ENVELOPE_ALLOWANCE_BYTES))
+ expect(atBound.status).toBe(403)
+ expect(atBound.body.error).toBe('ticket_invalid')
+
+ const overBound = await send('x'.repeat(ENVELOPE_ALLOWANCE_BYTES + 1))
+ expect(overBound.status).toBe(400)
+ expect(overBound.body.error).toBe('invalid_request')
+
+ // A V2 body pushed past the ordinary cap by its ticket and one small image
+ // takes the visual gate, is refused at the schema, and frees its slot.
+ const acquire = vi.spyOn(visualStreamGate, 'acquire')
+ const visual = await send('x'.repeat(8_000_000), {
+ schemaVersion: 'codex-completion-request.v2',
+ messages: [{ role: 'user', contentParts: [{ type: 'image', data: 'A'.repeat(1024 * 1024) }] }],
+ })
+ expect(visual.status).toBe(400)
+ expect(visual.body.error).toBe('invalid_request')
+ expect(acquire).toHaveBeenCalledTimes(1)
+ expect(visualStreamGate.snapshot()).toEqual({ running: 0, queued: 0 })
+ acquire.mockRestore()
+ }, 30_000)
+
it('does not let a V2 declaration raise the non-image budget to 24 MiB', async () => {
const { runtimeApp } = createProxyApps(config({ maxBodyBytes: DEFAULT_MAX_BODY_BYTES }))
// One byte of text past the non-image ceiling plus its envelope allowance,
diff --git a/grok-llm-proxy/test/server.security.test.ts b/grok-llm-proxy/test/server.security.test.ts
index 6005294ed..44f1ae4f9 100644
--- a/grok-llm-proxy/test/server.security.test.ts
+++ b/grok-llm-proxy/test/server.security.test.ts
@@ -242,6 +242,40 @@ describe('grok-llm-proxy security surface', () => {
expect(visualStreamGate.snapshot()).toEqual({ running: 0, queued: 0 })
}, 30_000)
+ // r10 Y1: the ticket is a signed JWT of a few hundred bytes. The non-image
+ // ceiling alone lets an ~8 MiB ticket reach jwt.verify, so the schema bounds
+ // it at the envelope allowance.
+ it('T-Y1-grok bounds the execution ticket at the envelope allowance before verifying it', async () => {
+ const { runtimeApp } = createProxyApps(config({ maxBodyBytes: DEFAULT_MAX_BODY_BYTES }))
+ const send = (executionTicket: string, body: Record<string, unknown> = {}) =>
+ request(runtimeApp)
+ .post('/internal/runtime/v1/grok/completions')
+ .set('Authorization', `Bearer ${platformToken()}`)
+ .send({ executionTicket, requestHash: 'a'.repeat(64), request: body })
+
+ // Witness: a ticket exactly at the bound reaches the verifier.
+ const atBound = await send('x'.repeat(ENVELOPE_ALLOWANCE_BYTES))
+ expect(atBound.status).toBe(403)
+ expect(atBound.body.error).toBe('ticket_invalid')
+
+ const overBound = await send('x'.repeat(ENVELOPE_ALLOWANCE_BYTES + 1))
+ expect(overBound.status).toBe(400)
+ expect(overBound.body.error).toBe('invalid_request')
+
+ // A V2 body pushed past the ordinary cap by its ticket and one small image
+ // takes the visual gate, is refused at the schema, and frees its slot.
+ const acquire = vi.spyOn(visualStreamGate, 'acquire')
+ const visual = await send('x'.repeat(8_000_000), {
+ schemaVersion: 'grok-completion-request.v2',
+ messages: [{ role: 'user', contentParts: [{ type: 'image', data: 'A'.repeat(1024 * 1024) }] }],
+ })
+ expect(visual.status).toBe(400)
+ expect(visual.body.error).toBe('invalid_request')
+ expect(acquire).toHaveBeenCalledTimes(1)
+ expect(visualStreamGate.snapshot()).toEqual({ running: 0, queued: 0 })
+ acquire.mockRestore()
+ }, 30_000)
+
it('refuses a declared length past the visual ceiling with 413 before reading it', async () => {
const { runtimeApp } = createProxyApps(config({ maxBodyBytes: DEFAULT_MAX_BODY_BYTES }))
const pad = 'A'.repeat(LIMITS.maxVisualRequestBodyBytes)