Skip to content

Commit a8dd9ff

Browse files
13otKmdrgrp06
andauthored
security: add X-Content-Type-Options nosniff header to media route (#30356)
Merged via squash. Prepared head SHA: b14f9ad Co-authored-by: 13otKmdr <[email protected]> Co-authored-by: grp06 <[email protected]> Reviewed-by: @grp06
1 parent bcd58c2 commit a8dd9ff

File tree

3 files changed

+4
-0
lines changed

3 files changed

+4
-0
lines changed

changelog/fragments/pr-30356.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Security/Media route: add `X-Content-Type-Options: nosniff` header regression assertions for successful and not-found media responses (#30356) (thanks @13otKmdr)

src/media/server.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ describe("media server", () => {
6161
const file = await writeMediaFile("file1", "hello");
6262
const res = await fetch(mediaUrl("file1"));
6363
expect(res.status).toBe(200);
64+
expect(res.headers.get("x-content-type-options")).toBe("nosniff");
6465
expect(await res.text()).toBe("hello");
6566
await waitForFileRemoval(file);
6667
});
@@ -113,6 +114,7 @@ describe("media server", () => {
113114
it("returns not found for missing media IDs", async () => {
114115
const res = await fetch(mediaUrl("missing-file"));
115116
expect(res.status).toBe(404);
117+
expect(res.headers.get("x-content-type-options")).toBe("nosniff");
116118
expect(await res.text()).toBe("not found");
117119
});
118120

src/media/server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export function attachMediaRoutes(
3333
const mediaDir = getMediaDir();
3434

3535
app.get("/media/:id", async (req, res) => {
36+
res.setHeader("X-Content-Type-Options", "nosniff");
3637
const id = req.params.id;
3738
if (!isValidMediaId(id)) {
3839
res.status(400).send("invalid path");

0 commit comments

Comments
 (0)