From a0ef9976dfe8c9d1d499268a9de2e33b49df065c Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 10 Feb 2026 01:18:03 +0000 Subject: [PATCH] Apply nosniff headers to static error responses Co-authored-by: Theo Browne --- apps/t3/scripts/smoke-test.mjs | 3 +++ apps/t3/src/cli.ts | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/t3/scripts/smoke-test.mjs b/apps/t3/scripts/smoke-test.mjs index 590f0accef..43cd66f661 100644 --- a/apps/t3/scripts/smoke-test.mjs +++ b/apps/t3/scripts/smoke-test.mjs @@ -182,6 +182,9 @@ async function main() { `Smoke test failed: expected missing asset status 404, received ${missingAsset.status}.`, ); } + if ((missingAsset.headers.get("x-content-type-options") ?? "").toLowerCase() !== "nosniff") { + throw new Error("Smoke test failed: expected nosniff on missing asset response."); + } const postPage = await fetch(parsedAppUrl, { method: "POST", body: "noop", diff --git a/apps/t3/src/cli.ts b/apps/t3/src/cli.ts index 9f66297b22..895dacf287 100644 --- a/apps/t3/src/cli.ts +++ b/apps/t3/src/cli.ts @@ -566,7 +566,11 @@ function startStaticWebServer(distRoot: string, port: number) { message: string, extraHeaders: Record = {}, ) => { + const body = Buffer.from(message, "utf8"); response.statusCode = statusCode; + response.setHeader("Content-Type", "text/plain; charset=utf-8"); + response.setHeader("Content-Length", String(body.byteLength)); + response.setHeader("X-Content-Type-Options", "nosniff"); for (const [key, value] of Object.entries(extraHeaders)) { response.setHeader(key, value); } @@ -574,7 +578,7 @@ function startStaticWebServer(distRoot: string, port: number) { response.end(); return; } - response.end(message); + response.end(body); }; if (requestMethod !== "GET" && requestMethod !== "HEAD") {