Repository navigation
fix(security): Next 16.4.6, with the file preview's size cap counted while reading - #152
Conversation
…while reading Next 16.4.5 fixes seven moderate advisories and drops Content-Length from route handler responses. The docked preview used that header to refuse text files over 2 MiB opened without a known size (chat links, ?file= addresses), so it read and rendered them whole. readText now counts bytes while reading and stops at the cap; the header stays a shortcut where present. Also corrects the MAX_STAMP comment: the digest covers the draft's files.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
What & why
npm audit --omit=devon main reports seven moderate advisories in Next 16.4.3 (fixed in 16.4.5). This PR moves to Next 16.4.6 and fixes the one change in this app that the upgrade causes.nextand@next/*. After the upgrade,npm audit --omit=devreports 0. As far as I can tell, none of the advisories reached this app: it uses nouse cacheor Cache Components, has no Edge runtime routes and sets no cookies, and images are unoptimized. The settings and AutoSkills relays copy onlycontent-typefrom the backend's answer. Scanners flag the version anyway.Content-Length. Since 16.4.5, Next removescontent-length,content-encodingandtransfer-encodingfrom every route handler response (FORBIDDEN_HEADERSinnext/dist/server/send-response.js). Its compression then gzips those responses when the browser accepts it. Here, the docked preview usedcontent-lengthto refuse text files over 2 MiB before reading them. This is the path for files opened without a known size, from a chat link or a?file=address. With 16.4.6 alone, a 3.4 MB text file was read and rendered whole: 80,000 lines, 8.7 s, without the "too large to preview inline" notice.readTextnow counts bytes while it reads and stops at the cap. The header still works as a shortcut where it is present.src/app/api/autoskills/route.ts: theMAX_STAMPcomment now says the digest covers the draft's files.A side effect with no code change: the "Download all" zip no longer carries a
Content-Length, so the browser shows the download without a total size. Uploads are not affected (request headers are untouched).Backend. No new requirement.
Manual testing
npm run lint && npm run format:check && npm run buildall green (alsotypecheckand 3367/3367 tests, on Node 20 as in CI and on Node 25)EvoSci deployon port 6290 with a local fake OpenAI-compatible model)node dist/server.jsin headless Chrome)Test steps / screenshots
On production builds of main (16.4.3), this branch without the
readTextchange (16.4.6), and this branch:GET /api/workspace/filefor a 3.4 MB text filecontent-length: 3440000?file=workspace:big.txtnotes.mdthe same wayThe first message of a new chat, sent while the skill names are still loading (the check from the 16.4 upgrade, fresh tab each round): one run request, none aborted, one run on the backend and the answer shown, 12 of 12 rounds on 16.4.6 and 6 of 6 on this branch.
Tests (
WorkspaceFileView.test.tsx), both on bodies without a length:Response.text()would.Each of these mutants fails one of the tests: checking each chunk instead of the running total, checking only after the whole body is read, dropping the abort, keeping the BOM, decoding each chunk on its own, and going back to
res.text().Checklist
Summary by CodeRabbit