Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
address review: reject second accepted file part to prevent /tmp leak
Adam Eivy865e561a789c
diff --git a/server/lib/multipart.js b/server/lib/multipart.jsindex dc690acc94..396eae760c 100644--- a/server/lib/multipart.js+++ b/server/lib/multipart.js@@ -151,6 +151,19 @@ function streamMultipart(req, boundary, fileFieldNames, maxSize, fileFilter, nexisMatchingFile = fileFieldNames.includes(currentName);const mimeMatch = headerStr.match(/Content-Type:\s*([^\r\n]+)/i);currentFileMimetype = mimeMatch ? mimeMatch[1].trim() : 'application/octet-stream';+ // Reject a second accepted file part rather than silently overwriting+ // fileResult and leaking the prior part's tmp file. This matters more+ // now that callers can pass multiple accepted field names (videoGen's+ // sourceImage|audioFile) — without this guard, a client posting both+ // could fill /tmp on repeated requests since the first temp file was+ // never unlinked. Limit is per-request (single accepted file in flight),+ // not per-fieldname.+ if (isMatchingFile && fileResult) {+ const err = new Error('Multiple file uploads not allowed — only one of the accepted file fields may be present per request');+ err.status = 400;+ err.code = 'TOO_MANY_FILES';+ return fail(err);+ }if (isMatchingFile) {const fileMeta = { fieldname: currentName, originalname: currentFilename, mimetype: currentFileMimetype };diff --git a/server/lib/multipart.test.js b/server/lib/multipart.test.jsindex 8efa1f2c2c..60002c6aac 100644--- a/server/lib/multipart.test.js+++ b/server/lib/multipart.test.js@@ -139,6 +139,26 @@ describe('uploadSingle multipart parser', () => {vi.doUnmock('fs');});+ it('rejects a second accepted file part (TOO_MANY_FILES) without leaking the first temp file', async () => {+ // With multi-fieldname uploads (e.g. videoGen's sourceImage|audioFile),+ // a malicious or buggy client could send both parts in one request. The+ // parser used to silently overwrite fileResult with the second file,+ // leaving the first temp file orphaned in /tmp. The TOO_MANY_FILES+ // guard rejects the request before the second part is opened, and+ // calls fail() so the first part's writeStream gets destroyed ++ // unlinked.+ const req = makeMultipartReq([+ { name: 'sourceImage', filename: 'a.png', contentType: 'image/png', body: Buffer.from([0x89, 0x50]) },+ { name: 'audioFile', filename: 'b.wav', contentType: 'audio/wav', body: Buffer.from([0xde, 0xad]) },+ ]);+ let captured = null;+ const mw = uploadSingle(['sourceImage', 'audioFile'], { limits: { fileSize: 1024 * 1024 } });+ await new Promise((resolve) => mw(req, {}, (err) => { captured = err; resolve(); }));+ expect(captured).toBeTruthy();+ expect(captured.code).toBe('TOO_MANY_FILES');+ expect(captured.status).toBe(400);+ });+it('rejects requests without the multipart Content-Type', async () => {const stream = Readable.from(['nope']);stream.headers = { 'content-type': 'application/json' };