Apply nosniff headers to static error responses

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-10 01:18:03 +00:00
1 parent bb00a48f70
commit a0ef9976df
2 files changed
+8 -1

No files matched your search

+3
View File
@@ -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",
+5 -1
View File
@@ -566,7 +566,11 @@ function startStaticWebServer(distRoot: string, port: number) {
message: string,
extraHeaders: Record<string, string> = {},
) => {
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") {