Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ const nextConfig = {
// without needing the full node_modules tree (or a second `npm ci`) copied in.
output: "standalone",
turbopack: { root: __dirname },
poweredByHeader: false,
async headers() {
return [
{
source: "/(.*)",
headers: [
{ key: "Content-Security-Policy", value: "frame-ancestors 'self'" },
{ key: "X-Frame-Options", value: "SAMEORIGIN" },
],
},
];
},
};

module.exports = nextConfig;
20 changes: 20 additions & 0 deletions src/utils/__tests__/securityHeaders.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import type { NextConfig } from "next";

const nextConfig = require("../../../next.config.js") as NextConfig;

describe("clickjacking response headers", () => {
it("sends an enforceable framing policy on every route", async () => {
const rules = await nextConfig.headers?.();
const everyRoute = rules?.find((rule) => rule.source === "/(.*)");
const headers = Object.fromEntries(
(everyRoute?.headers ?? []).map(({ key, value }) => [key.toLowerCase(), value]),
);

expect(headers["content-security-policy"]).toContain("frame-ancestors 'self'");
expect(headers["x-frame-options"]).toBe("SAMEORIGIN");
});

it("omits the Next.js version disclosure header", () => {
expect(nextConfig.poweredByHeader).toBe(false);
});
});