Skip to content

fix(security): Next 16.4.6, with the file preview's size cap counted while reading - #152

Merged
X-iZhang merged 1 commit into
mainfrom
chore/next-16.4.6
Nov 27, 2026
Merged

X-iZhang merged 1 commit into
mainfrom
chore/next-16.4.6

Conversation

@X-iZhang

@X-iZhang X-iZhang commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

What & why

npm audit --omit=dev on 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.

  • Dependency. next ^16.4.3 → ^16.4.6. The lockfile changes only next and @next/*. After the upgrade, npm audit --omit=dev reports 0. As far as I can tell, none of the advisories reached this app: it uses no use cache or Cache Components, has no Edge runtime routes and sets no cookies, and images are unoptimized. The settings and AutoSkills relays copy only content-type from the backend's answer. Scanners flag the version anyway.
  • The file preview's size cap no longer relies on Content-Length. Since 16.4.5, Next removes content-length, content-encoding and transfer-encoding from every route handler response (FORBIDDEN_HEADERS in next/dist/server/send-response.js). Its compression then gzips those responses when the browser accepts it. Here, the docked preview used content-length to 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. readText now 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: the MAX_STAMP comment 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

Must be tested against a real backend (EvoSci deploy, port 6174) — a green build is not enough.

  • npm run lint && npm run format:check && npm run build all green (also typecheck and 3367/3367 tests, on Node 20 as in CI and on Node 25)
  • Started the backend → configured the Deployment URL → chat works (an isolated EvoSci deploy on port 6290 with a local fake OpenAI-compatible model)
  • The feature(s) touched here were verified to work (file preview, chat, every view)
  • Significant changes re-tested against the production build (node dist/server.js in headless Chrome)

Test steps / screenshots

On production builds of main (16.4.3), this branch without the readText change (16.4.6), and this branch:

What 16.4.3 16.4.6, no change This branch
GET /api/workspace/file for a 3.4 MB text file content-length: 3440000 no length, gzip no length, gzip
Open that file by ?file=workspace:big.txt "too large to preview inline", 0 bytes read the whole file rendered (80,000 lines, 8.7 s) "too large to preview inline", the read stops at about 2 MiB
Open a 41-byte notes.md the same way shown shown shown
Chat, Skills, Experts, Memory, Scheduled, Settings, Workspace, AutoSkills drafts — no console errors no console errors

The 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:

  • A body served in 512 KiB chunks on demand. The test checks the "too large" notice, that reading stops by the sixth chunk, and that the request is aborted.
  • A body with a leading BOM and a two-byte character split across chunks decodes as 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

  • Self-tested, no obvious regressions
  • Requested at least one teammate for peer review

Merging ≠ shipping: releases are handled solely by the maintainer. A published release reaches users without a core release: EvoScientist v0.3.6+ picks up the newest version in its supported range (v0.3.6: >=0.3,<0.4; v0.3.7 and v0.3.8: >=0.3,<0.5; v0.4.0: >=0.4,<0.6; v0.4.1+: >=0.5,<0.6), and older versions run @latest.

Summary by CodeRabbit

  • Bug Fixes
    • Large text files without a declared size are now stopped at the inline preview limit, preventing the preview from continuing to read excessive content.
    • Text previews now correctly display characters when UTF-8 content arrives in separate chunks or begins with a byte-order mark.

…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.
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change limits streamed file previews to the inline byte-size cap, adds tests for oversized and split UTF-8 responses, updates the Next.js version range, and clarifies the AutoSkills digest comment.

Changes: Streamed file preview

Layer / File(s) Summary
Streamed preview size limit
src/app/components/WorkspaceFileView.tsx, src/app/components/WorkspaceFileView.test.tsx
readText counts streamed bytes and aborts when they exceed the inline size limit. Tests check the size-cap message, stream abort, refresh behavior, and BOM-prefixed UTF-8 split across chunks.

Next.js version range

Layer / File(s) Summary
Next.js dependency range
package.json
The Next.js dependency requirement changes from ^16.4.3 to ^16.4.6.

AutoSkills digest comment

Layer / File(s) Summary
Digest description
src/app/api/autoskills/route.ts
The comment describes the expected content digest as covering the draft’s files. The stated relay validation remains unchanged.

Estimated code review effort: 2 (Simple) | ~12 minutes

Change: Bug fix

Possibly related PRs

Suggested reviewers: din0s, jfilipiuk, nkantony777

Merge Risk: Minimal · up to c3be1 · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the two main changes: the Next upgrade to 16.4.6 (security fix) and the file preview's size cap now counted while reading. The changeset matches both. The title is a single line and sp…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the two main changes: the Next upgrade to 16.4.6 (security fix) and the file preview's size cap now counted while reading. The changeset matches both. The title is a single line and specific. It omits the ZIP download side effect, which is acceptable.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8d887026-9e9d-4830-9e4d-239ac3006777
Commits

Reviewing files that changed from the base of the PR and between 6e7e74d and c3be1bd.

Files ignored due to path filters: 1

  • package-lock.json is excluded by !**/package-lock.json
Files selected for processing: 4

  • package.json
  • src/app/api/autoskills/route.ts
  • src/app/components/WorkspaceFileView.test.tsx
  • src/app/components/WorkspaceFileView.tsx

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

@X-iZhang
X-iZhang merged commit 0ffa91d into main Nov 27, 2026
15 checks passed
@X-iZhang
X-iZhang deleted the chore/next-16.4.6 branch November 27, 2026 17:36
@X-iZhang X-iZhang mentioned this pull request Nov 27, 2026
2 of 3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant