From daf94f721466d15116edb270d0bd955ee2549fcf Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 10:24:18 -0600 Subject: [PATCH] fix(clef-proxy): reject array bodies in the systemone guard (#2938) --- bin/clef-proxy.mjs | 2 +- bin/clef-proxy.test.mjs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/bin/clef-proxy.mjs b/bin/clef-proxy.mjs index 991df9e61f..5dca4125f4 100755 --- a/bin/clef-proxy.mjs +++ b/bin/clef-proxy.mjs @@ -232,7 +232,7 @@ const server = http.createServer(async (req, res) => { res.end(JSON.stringify({ error: `Invalid JSON body: ${err.message}` })); return; } - if (!body || typeof body !== 'object') { + if (!body || typeof body !== 'object' || Array.isArray(body)) { res.writeHead(400, { 'Content-Type': 'application/json' }); res.end(JSON.stringify({ error: 'Invalid JSON body: expected an object' })); return; diff --git a/bin/clef-proxy.test.mjs b/bin/clef-proxy.test.mjs index fe7214c6d3..3147ddf995 100644 --- a/bin/clef-proxy.test.mjs +++ b/bin/clef-proxy.test.mjs @@ -159,6 +159,25 @@ test('clef-proxy upstream guard (#690/#692)', async (t) => { assert.match(stubPaths.at(-1), /\/workers-ai\/run\//); }); + await t.test('array body is a 400 and never reaches the stub upstream (#2938)', async () => { + stubBehavior = (req, res) => { + res.writeHead(200, { 'Content-Type': 'application/json' }); + res.end(JSON.stringify({ success: true, result: { answers: { q1: 'answer one' } } })); + }; + const hitsBefore = stubPaths.length; + for (const raw of ['[]', '[1,2]']) { + const res = await fetch(`${base}/v1/systemone`, { + method: 'POST', + headers: { 'Content-Type': 'application/json', Authorization: 'Bearer test' }, + body: raw + }); + assert.equal(res.status, 400); + const data = await res.json(); + assert.equal(data.error, 'Invalid JSON body: expected an object'); + } + assert.equal(stubPaths.length, hitsBefore); + }); + await t.test('upstream that never sends headers returns a 504', async () => { stubBehavior = () => {}; const res = await ask();