Skip to content

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

TypeScript

fix(codex-proxy): resolve the attempt error status without the prototype chain

Alfredo Lopeza651b8512b01
diff --git a/codex-llm-proxy/src/server.ts b/codex-llm-proxy/src/server.ts
index 7e048f1f0..7b48aa2ac 100644
--- a/codex-llm-proxy/src/server.ts
+++ b/codex-llm-proxy/src/server.ts
@@ -386,6 +386,13 @@ const ATTEMPT_ERROR_STATUS: Record<string, number> = {
conflict: 503,
}
+// A control-api code is an unbounded string, so both readers of the table must
+// ignore inherited names: `ATTEMPT_ERROR_STATUS['constructor']` is a function,
+// not undefined, and `??` would pass it straight to `res.status()`.
+function attemptErrorStatus(code: string): number {
+ return Object.hasOwn(ATTEMPT_ERROR_STATUS, code) ? ATTEMPT_ERROR_STATUS[code]! : 503
+}
+
function failureLabel(code: string): string {
return Object.hasOwn(ATTEMPT_ERROR_STATUS, code) ? code : 'other'
}
@@ -394,7 +401,7 @@ function mapError(err: unknown): { status: number; code: string } {
if (err instanceof OriginDeniedError) return { status: 403, code: 'origin_denied' }
if (err instanceof RequestLimitError) return { status: 503, code: 'provider_unavailable' }
if (err instanceof CodexTransportError || err instanceof ControlApiClientError) {
- return { status: ATTEMPT_ERROR_STATUS[err.code] ?? 503, code: err.code }
+ return { status: attemptErrorStatus(err.code), code: err.code }
}
return { status: 503, code: 'provider_unavailable' }
}
diff --git a/codex-llm-proxy/test/server.security.test.ts b/codex-llm-proxy/test/server.security.test.ts
index 359d44535..9f0d1d663 100644
--- a/codex-llm-proxy/test/server.security.test.ts
+++ b/codex-llm-proxy/test/server.security.test.ts
@@ -702,4 +702,30 @@ describe('codex-llm-proxy attempt telemetry', () => {
expect(failureCount(metricsText, 'other')).toBe(1)
expect(metricsText).not.toContain(rawCode)
})
+
+ // `ATTEMPT_ERROR_STATUS` is an object literal, so an inherited name resolves
+ // to a function or an object instead of undefined. A plain index read would
+ // hand that value to `res.status()`, which throws ERR_HTTP_INVALID_STATUS_CODE
+ // inside the request IIFE's catch — an unhandled rejection that takes every
+ // other in-flight stream down with the process.
+ it.each(['constructor', '__proto__', 'toString', 'hasOwnProperty'])(
+ '(g) answers 503 for the inherited control-api code %j instead of crashing',
+ async code => {
+ const { res, lines, metricsText } = await run(
+ `att-proto-${code}`,
+ 0,
+ 0,
+ undefined,
+ code
+ )
+ expect(res.status).toBe(503)
+ expect(res.body).toEqual({ error: code })
+ // Witness: the attempt was reached and logged, so the status above is the
+ // mapped refusal and not a connection that never produced a response.
+ expect(lines).toHaveLength(1)
+ expect(lines[0]).toMatchObject({ outcome: 'failed', code, httpStatus: 503 })
+ expect(failureCount(metricsText, 'other')).toBe(1)
+ expect(failureCount(metricsText, code)).toBe(0)
+ }
+ )
})