Tracker env is read at request time and the CSP already allows the analytics host, so staging can set a rule admin, an ops bearer token, and the cookieless Umami site without rebuilding.
27 lines
1.2 KiB
TypeScript
27 lines
1.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import nextConfig from "../../next.config.mjs";
|
|
|
|
describe("security headers", () => {
|
|
it("drops X-Powered-By and sends a same-origin CSP", async () => {
|
|
expect(nextConfig.poweredByHeader).toBe(false);
|
|
const rows = await nextConfig.headers();
|
|
const globalHeaders = rows.find((row) => row.source === "/(.*)")?.headers;
|
|
expect(globalHeaders).toBeDefined();
|
|
const byKey = Object.fromEntries(
|
|
(globalHeaders ?? []).map((header) => [header.key, header.value]),
|
|
);
|
|
expect(byKey["Content-Security-Policy"]).toContain("default-src 'self'");
|
|
expect(byKey["Content-Security-Policy"]).toContain("script-src 'self'");
|
|
expect(byKey["Content-Security-Policy"]).toContain(
|
|
"https://analytics.communityrule.info",
|
|
);
|
|
expect(byKey["Content-Security-Policy"]).toContain("style-src 'self'");
|
|
expect(byKey["Content-Security-Policy"]).toContain("font-src 'self'");
|
|
expect(byKey["Content-Security-Policy"]).toContain("img-src 'self'");
|
|
expect(byKey["Permissions-Policy"]).toBe(
|
|
"camera=(), microphone=(), geolocation=()",
|
|
);
|
|
expect(byKey["Referrer-Policy"]).toBe("same-origin");
|
|
});
|
|
});
|