Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: Compressed asset responses drop Content-Type, so nosniff renders HTML as plain text #11935

Closedstychu(GitHub profile, opens in a new tab) opened this issue 2 comments

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. Open a project containing any .html file.
  2. Open that file in the integrated browser so the server mints a signed /api/assets/... URL for it.
  3. Request that URL twice, varying only Accept-Encoding:
URL='http://127.0.0.1:<port>/api/assets/<signed>/<file>.html'
curl -sS -D - -o /dev/null -H 'Accept-Encoding: identity' "$URL"
curl -sS -D - -o /dev/null -H 'Accept-Encoding: gzip'     "$URL"

Opening the same URL in Chrome shows the same failure, since every browser sends Accept-Encoding.

Expected behavior

Both responses carry Content-Type: text/html; charset=utf-8, and the document renders as HTML.

Actual behavior

The compressed response omits Content-Type entirely. Because X-Content-Type-Options: nosniff is still sent, the browser is forbidden from sniffing the type it was not given, so Chrome renders the document as plain text, showing raw markup instead of the page.

Accept-Encodingcontent-type
identitytext/html; charset=utf-8
gzipabsent
brabsent
gzip, deflate, br, zstd (what Chrome sends)absent

Every other header survives compression: cache-control, the CSP, nosniff, last-modified, and the etag (correctly weakened). Only Content-Type is lost.

The two headers are each defensible alone and fatal together: dropping Content-Type would be survivable if sniffing were allowed, and nosniff is correct when a type is declared. Doing both guarantees the failure.

Root cause. The chain is:

  1. assetFileResponse calls HttpServerResponse.file(asset.path, { status, offset, bytesToRead, headers }) without a contentType, so the type exists only in the headers map.
  2. Node's fileResponse builds ServerResponse.raw(stream, { headers: { ..., "content-type": ... } }), leaving body.contentType undefined.
  3. Compression's Raw branch calls HttpBody.raw(..., { contentType: body.contentType }), which is undefined.
  4. setBody runs updateHeaders, which on an undefined body content type does Headers.remove(headers, "content-type"), deleting the header.
  5. Node's handleResponse writes only response.headers and never consults body.contentType, so nothing restores it.

The media path is unaffected: HttpServerResponse.stream back-fills through getContentType, which falls back to headers["content-type"] whenever headers is supplied. Only the file() path loses the type, and that is the path every HTML asset takes.

A regression test that fails on main and passes once the body carries the type:

const { dispose, handler } = HttpEffect.toWebHandlerLayer(
  assetFileResponse({ path: filePath }),
  fileResponseLayer,
  { middleware: HttpMiddleware.compression() },
);
const compressed = await handler(
  new Request("http://localhost/page.html", { headers: { "accept-encoding": "gzip" } }),
);
expect(compressed.headers.get("content-encoding")).toBe("gzip");
expect(compressed.headers.get("content-type")).toBe("text/html; charset=utf-8");

It currently fails with expected null to be 'text/html; charset=utf-8'. apps/server/src/http.test.ts has no Accept-Encoding coverage today, which is how this went unnoticed.

Impact

Major degradation or frequent failure

Version or commit

Desktop Nightly 0.0.41-nightly.20260913.1675; code references against main @ 3efdcc52

Environment

macOS (Apple Silicon), Chrome, and curl. Not platform-specific; reproduces wherever a client sends Accept-Encoding.

Logs or stack traces

# Accept-Encoding: gzip  -> no content-type
HTTP/1.1 200 OK
cache-control: private, max-age=3600
x-content-type-options: nosniff
content-security-policy: sandbox allow-scripts allow-forms allow-popups allow-modals
etag: W/"6b61-1a0a5c80565"
last-modified: Tue, 15 Sep 2026 15:55:44 GMT
content-encoding: gzip
vary: Accept-Encoding
access-control-allow-origin: *
Transfer-Encoding: chunked

# Accept-Encoding: identity  -> content-type present
HTTP/1.1 200 OK
cache-control: private, max-age=3600
x-content-type-options: nosniff
content-type: text/html; charset=utf-8
content-security-policy: sandbox allow-scripts allow-forms allow-popups allow-modals
etag: "6b61-1a0a5c80565"
last-modified: Tue, 15 Sep 2026 15:55:44 GMT
content-length: 27489
vary: Accept-Encoding
access-control-allow-origin: *

Workaround

Request the asset with Accept-Encoding: identity, which keeps the header. There is no way to do this from a normal browser, so there is no user-facing workaround.

Possibly related: #11191 (local HTML files opening to a blank viewer) was diagnosed as a renderer frame-src CSP problem. That fix is present in the build above and this still reproduces, so #11191 may be the same defect surfacing differently.

  1. Duplicate of #10935 — same compressed asset Content-Type drop under HttpMiddleware.compression() / HttpServerResponse.file, with nosniff forcing plain-text HTML. Tracking and workaround (no-transform Cache-Control) are already on that issue.

  2. juliusmarminge added labelsduplicate

  3. Closing as duplicate of #10935.

  4. juliusmarminge closed this

Sign in to join this conversation.