mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-19 06:37:28 +00:00
security: add X-Content-Type-Options nosniff header to media route (#30356)
Merged via squash.
Prepared head SHA: b14f9ad7ca
Co-authored-by: 13otKmdr <154699144+13otKmdr@users.noreply.github.com>
Co-authored-by: grp06 <1573959+grp06@users.noreply.github.com>
Reviewed-by: @grp06
This commit is contained in:
@@ -61,6 +61,7 @@ describe("media server", () => {
|
||||
const file = await writeMediaFile("file1", "hello");
|
||||
const res = await fetch(mediaUrl("file1"));
|
||||
expect(res.status).toBe(200);
|
||||
expect(res.headers.get("x-content-type-options")).toBe("nosniff");
|
||||
expect(await res.text()).toBe("hello");
|
||||
await waitForFileRemoval(file);
|
||||
});
|
||||
@@ -113,6 +114,7 @@ describe("media server", () => {
|
||||
it("returns not found for missing media IDs", async () => {
|
||||
const res = await fetch(mediaUrl("missing-file"));
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.headers.get("x-content-type-options")).toBe("nosniff");
|
||||
expect(await res.text()).toBe("not found");
|
||||
});
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ export function attachMediaRoutes(
|
||||
const mediaDir = getMediaDir();
|
||||
|
||||
app.get("/media/:id", async (req, res) => {
|
||||
res.setHeader("X-Content-Type-Options", "nosniff");
|
||||
const id = req.params.id;
|
||||
if (!isValidMediaId(id)) {
|
||||
res.status(400).send("invalid path");
|
||||
|
||||
Reference in New Issue
Block a user