Skip to content

Commit a8b9da5

Browse files
author
Val
committed
daemon: tighten run-source validation; drop fork gate scripts (#7040 review)
- attachments entries must be objects; pluginId must be an installed plugin - specs for malformed source fields - remove bin/gate.sh + scripts/gate-tests.sh (fork-internal gate entrypoints, out of scope for this repo)
1 parent 582b4fc commit a8b9da5

4 files changed

Lines changed: 25 additions & 89 deletions

File tree

apps/daemon/src/routes/runs.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,10 +1246,15 @@ export function registerRunRoutes(app: Express, ctx: RegisterRunRoutesDeps) {
12461246
const hasPrompt =
12471247
(typeof requestBody.message === 'string' && requestBody.message.trim().length > 0)
12481248
|| (typeof requestBody.currentPrompt === 'string' && requestBody.currentPrompt.trim().length > 0);
1249-
const hasAttachments = Array.isArray(requestBody.attachments) && requestBody.attachments.length > 0;
1249+
const hasAttachments = Array.isArray(requestBody.attachments)
1250+
&& requestBody.attachments.length > 0
1251+
&& requestBody.attachments.every((entry) => entry !== null && typeof entry === 'object');
12501252
const hasPluginBriefSource =
1251-
(typeof requestBody.pluginId === 'string' && requestBody.pluginId.length > 0)
1252-
|| (typeof requestBody.appliedPluginSnapshotId === 'string' && requestBody.appliedPluginSnapshotId.length > 0);
1253+
(typeof requestBody.pluginId === 'string'
1254+
&& requestBody.pluginId.length > 0
1255+
&& Boolean(getInstalledPlugin(db, requestBody.pluginId)))
1256+
|| (typeof requestBody.appliedPluginSnapshotId === 'string'
1257+
&& requestBody.appliedPluginSnapshotId.length > 0);
12531258
if (!hasPrompt && !hasAttachments && !hasPluginBriefSource) {
12541259
return sendApiError(
12551260
res,

apps/daemon/tests/run-create-validation.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,23 @@ describe('run creation input validation (#7040)', () => {
3838
expect(resp.status).toBe(400);
3939
});
4040

41+
it('rejects malformed source fields', async () => {
42+
const cases = [
43+
{ message: {} },
44+
{ message: 42 },
45+
{ attachments: [null, 42] },
46+
{ pluginId: 'definitely-not-installed' },
47+
];
48+
for (const body of cases) {
49+
const resp = await fetch(baseUrl + '/api/runs', {
50+
method: 'POST',
51+
headers: { 'Content-Type': 'application/json' },
52+
body: JSON.stringify(body),
53+
});
54+
expect(resp.status, JSON.stringify(body)).toBe(400);
55+
}
56+
});
57+
4158
it('still accepts a normal prompt', async () => {
4259
const resp = await fetch(baseUrl + '/api/runs', {
4360
method: 'POST',

bin/gate.sh

Lines changed: 0 additions & 40 deletions
This file was deleted.

scripts/gate-tests.sh

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)