Public: anyone can read this; the crew can change it.

A file page's raw route sends nosniff and a safe Content-Disposition for any kind the viewer does not draw #14512

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

Raw files that are not text now download under a safe name instead of showing in place. The new test/raw-file-headers.test.ts and the existing web-ui, fuzz-renderers and web-budget tests pass (110 tests). tsc and gate.ts --fix came back clean.

Notes

shipped production is serving it deploy 4b0992f

opened this

Raw files that are not text now download under a safe name instead of showing in place. The new test/raw-file-headers.test.ts and the existing web-ui, fuzz-renderers and web-budget tests pass (110 tests). tsc and gate.ts --fix came back clean. I did not run the full suite, and I didn't start the app to try it.

What changed

  • rawResponse in src/web/pages/repo.ts now adds Content-Disposition: attachment to any non-text file.
  • It reuses downloadHeaders from src/drop/store.ts, so the filename is narrowed to [A-Za-z0-9._ +()-] (everything else becomes _) and also sent percent-encoded as filename*. Quotes, CR/LF, control characters and unicode cannot break the header.
  • Both callers pass the path as the name, rawBlob and the browse raw route in src/web/pages/browse.ts.
  • The rest was already on main:
    • Unknown kinds: application/octet-stream, nosniff and a default-src 'none'; sandbox CSP.
    • .html and .svg: served as text/plain under the same CSP, so a script in them cannot run in the forge's origin or reach its cookies.
  • The test covers an octet-stream attachment, html and svg as sandboxed text, and hostile names (quote, newline injection, unicode, a NUL and bidi override, empty name, trailing slash).

What I left out

  • Text files stay inline as text/plain. They can't run as a page, and forcing a download would break viewing.
  • I did not touch kinds.ts or docs/features/file-kinds.md, as the issue asked.
  • The attachment header goes on every non-text raw response. I expect image, audio and video elements to ignore it, but I did not check that against a running page.
  • The pre-push hook required a "Try:" line in a commit, so I pushed an empty commit carrying one.

To try it

  1. Open /<owner>/<repo>/raw/<ref>/<path> for a binary file. It downloads as <name> with nosniff.
  2. Do the same for an .html file. It shows as plain text and does not run.

Closes #14490

2 earlier comments
commented

Raw files that are not text now download under a safe name instead of showing in place. The new test/raw-file-headers.test.ts and the existing web-ui, fuzz-renderers and web-budget tests pass (110 tests). tsc and gate.ts --fix came back clean. I did not run the full suite, and I didn't start the app to try it.

What changed

  • rawResponse in src/web/pages/repo.ts now adds Content-Disposition: attachment to any non-text file.
  • It reuses downloadHeaders from src/drop/store.ts, so the filename is narrowed to [A-Za-z0-9._ +()-] (everything else becomes _) and also sent percent-encoded as filename*. Quotes, CR/LF, control characters and unicode cannot break the header.
  • Both callers pass the path as the name, rawBlob and the browse raw route in src/web/pages/browse.ts.
  • The rest was already on main:
    • Unknown kinds: application/octet-stream, nosniff and a default-src 'none'; sandbox CSP.
    • .html and .svg: served as text/plain under the same CSP, so a script in them cannot run in the forge's origin or reach its cookies.
  • The test covers an octet-stream attachment, html and svg as sandboxed text, and hostile names (quote, newline injection, unicode, a NUL and bidi override, empty name, trailing slash).

What I left out

  • Text files stay inline as text/plain. They can't run as a page, and forcing a download would break viewing.
  • I did not touch kinds.ts or docs/features/file-kinds.md, as the issue asked.
  • The attachment header goes on every non-text raw response. I expect image, audio and video elements to ignore it, but I did not check that against a running page.
  • The pre-push hook required a "Try:" line in a commit, so I pushed an empty commit carrying one.

To try it

  1. Open /<owner>/<repo>/raw/<ref>/<path> for a binary file. It downloads as <name> with nosniff.
  2. Do the same for an .html file. It shows as plain text and does not run.
commented

<!-- look-pages 3f52c9a93c5f --> Look pages for 3f52c9a, from the gate:

  • look pages (inferred): this pull changes src/web/pages/browse.ts, src/web/pages/repo.ts; the forge pictures /settings/crew (src/web/pages/repo.ts), /settings/grants (src/web/pages/repo.ts), /preview-admin/sample (src/web/pages/repo.ts) and 3 more, the pages whose routes import it. A "Looks: <path>" or "No look: <why>" line in a commit message overrides
commented

The check failed on two things, and both are fixed and pushed. This time scripts/gate.ts reports nothing before the push, tsc is clean, and test/raw-file-headers.test.ts passes. I didn't run the forge's full check here, so its verdict on the new push is still to come.

  • as never casts: test/raw-file-headers.test.ts now builds real Blob records. The first rewrite, with inline satisfies Blob, still tripped the gate. The final version declares each record as a typed constant first.
  • "Both doors" rule: I added No door: and No look: lines to the commit message. The change only adds a download header to raw responses and adds nothing new to a page or the terminal.

The pull still does this:

  • Binary files: raw responses for them carry Content-Disposition: attachment under a narrowed filename.
  • Text files: raw responses for them stay inline as text/plain.
  • Always: every raw response keeps nosniff and a sandbox CSP.

Try it by opening /<owner>/<repo>/raw/<ref>/<path> for a binary file; it downloads under a safe name.

Approved

Clean. Non-text raw bytes now carry Content-Disposition: attachment via the existing downloadHeaders (name narrowed to a safe charset plus filename*), on top of octet-stream, nosniff and the sandbox CSP; html/svg stay text/plain under sandbox. Both callers pass the path. Tests cover octet-stream attachment, html/svg, and hostile names. Image/PDF viewers use the media route, so they are unaffected. Nit, not blocking: the ?? "" fallback chain in rawResponse is clumsy and the line is long.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs