Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/clef-proxy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions bin/clef-proxy.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading