next.config's baseline Content-Security-Policy replaced the frame route's own header, so a frame address opened directly ran without the sandbox. A later headers rule for the two frame paths restores it. Also drop the gap above a header-less page. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
22 lines
1.2 KiB
TypeScript
22 lines
1.2 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import nextConfig from "./next.config";
|
|
import { FRAME_CSP } from "./app/lib/frameHtml";
|
|
|
|
// add-custom-html-block: config headers replace a route's own header of the same name, so the baseline
|
|
// Content-Security-Policy would strip the frame's sandbox. A later rule for the frame paths puts it back
|
|
// (Next.js: the last rule setting a key wins).
|
|
describe("Custom HTML frame headers", () => {
|
|
it("sends the sandbox policy on both frame paths, after the baseline rule", async () => {
|
|
const rules = await nextConfig.headers!();
|
|
const baseline = rules.findIndex((r) => r.source === "/:path*");
|
|
for (const source of ["/p/:company/:slug/frame/:block", "/pages/:id/preview/frame/:block"]) {
|
|
const at = rules.findIndex((r) => r.source === source);
|
|
expect(at, source).toBeGreaterThan(baseline);
|
|
const sent = Object.fromEntries(rules[at].headers.map((h) => [h.key, h.value]));
|
|
expect(sent["Content-Security-Policy"]).toBe(FRAME_CSP);
|
|
expect(sent["Referrer-Policy"]).toBe("no-referrer");
|
|
}
|
|
expect(FRAME_CSP).toMatch(/^sandbox allow-scripts allow-popups allow-popups-to-escape-sandbox; frame-ancestors 'self'/);
|
|
});
|
|
});
|