fix(pages): keep the frame's sandbox policy past the config headers
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
This commit is contained in:
1 parent
f13b2a592a
commit
36dbb4c949
6 files changed
+49
-8
No files matched your search
@@ -30,7 +30,7 @@ Design: `design.md` and `docs/superpowers/specs/2026-12-02-custom-html-block-des
|
|||||||
## 3. Release
|
## 3. Release
|
||||||
|
|
||||||
- [x] 3.1 `docs/deployment.md`: the SQL rows and the frame routes. A Traefik or proxy layer must not add a CSP that overrides the frame's own policy.
|
- [x] 3.1 `docs/deployment.md`: the SQL rows and the frame routes. A Traefik or proxy layer must not add a CSP that overrides the frame's own policy.
|
||||||
- [ ] 3.2 Live Playwright check on the local stack, at 1280 and 360 px:
|
- [x] 3.2 Live Playwright check on the local stack, at 1280 and 360 px:
|
||||||
- paste the INS proof-of-concept HTML into the INS page, with "hide page header" on and the sign-up form below it;
|
- paste the INS proof-of-concept HTML into the INS page, with "hide page header" on and the sign-up form below it;
|
||||||
- it looks like the PoC signed out;
|
- it looks like the PoC signed out;
|
||||||
- opening the frame address directly shows no Co-Lite cookies to the frame's script;
|
- opening the frame address directly shows no Co-Lite cookies to the frame's script;
|
||||||
|
|||||||
@@ -40,4 +40,11 @@ describe("LandingPage: Custom HTML", () => {
|
|||||||
expect(document.querySelector("header")).toBeNull();
|
expect(document.querySelector("header")).toBeNull();
|
||||||
expect(screen.getByRole("heading", { level: 1, name: "Hotel day" })).toHaveClass("sr-only");
|
expect(screen.getByRole("heading", { level: 1, name: "Hotel day" })).toHaveClass("sr-only");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("starts a header-less page flush at the top: the hidden title takes no part in block spacing", () => {
|
||||||
|
render(<LandingPage company={company} page={page([HTML], true)} />);
|
||||||
|
const title = screen.getByRole("heading", { level: 1, name: "Hotel day" });
|
||||||
|
expect(title.parentElement!.className).not.toMatch(/space-y/);
|
||||||
|
expect(frame().parentElement!.className).toMatch(/space-y/);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
@@ -119,11 +119,13 @@ export function LandingPage({ company, page, banner, preview, frameBase }: {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</header>}
|
</header>}
|
||||||
<main className={page.hideHeader ? "space-y-10 pb-8" : "space-y-10 py-8"}>
|
<main className={page.hideHeader ? "pb-8" : "py-8"}>
|
||||||
<h1 className={page.hideHeader ? "sr-only" : `${WIDTH} text-3xl font-semibold sm:text-4xl`}>{page.title}</h1>
|
<h1 className={page.hideHeader ? "sr-only" : `${WIDTH} mb-10 text-3xl font-semibold sm:text-4xl`}>{page.title}</h1>
|
||||||
{page.blocks.map((block, i) => block.type === "HTML"
|
<div className="space-y-10">
|
||||||
? <HtmlFrame key={i} src={`${frames}/${i}`} title={page.title} />
|
{page.blocks.map((block, i) => block.type === "HTML"
|
||||||
: <div key={i} className={WIDTH}><Block block={block} index={i} company={company.code} slug={page.slug} preview={preview} /></div>)}
|
? <HtmlFrame key={i} src={`${frames}/${i}`} title={page.title} />
|
||||||
|
: <div key={i} className={WIDTH}><Block block={block} index={i} company={company.code} slug={page.slug} preview={preview} /></div>)}
|
||||||
|
</div>
|
||||||
</main>
|
</main>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
// shown in an <iframe sandbox> with the same grants. No same-origin, forms, top navigation or modals.
|
// shown in an <iframe sandbox> with the same grants. No same-origin, forms, top navigation or modals.
|
||||||
|
|
||||||
export const FRAME_SANDBOX = "allow-scripts allow-popups allow-popups-to-escape-sandbox";
|
export const FRAME_SANDBOX = "allow-scripts allow-popups allow-popups-to-escape-sandbox";
|
||||||
|
/** The frame document's own policy. next.config sends it too: config headers replace a route's header of the same name. */
|
||||||
|
export const FRAME_CSP = `sandbox ${FRAME_SANDBOX}; frame-ancestors 'self'`;
|
||||||
export const FRAME_MESSAGE = "colite-frame-height";
|
export const FRAME_MESSAGE = "colite-frame-height";
|
||||||
export const START_HEIGHT = 600;
|
export const START_HEIGHT = 600;
|
||||||
const MIN_HEIGHT = 100;
|
const MIN_HEIGHT = 100;
|
||||||
@@ -23,7 +25,7 @@ export function frameResponse(html: string, { preview }: { preview: boolean }):
|
|||||||
return new Response(frameDocument(html), {
|
return new Response(frameDocument(html), {
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "text/html; charset=utf-8",
|
"Content-Type": "text/html; charset=utf-8",
|
||||||
"Content-Security-Policy": `sandbox ${FRAME_SANDBOX}; frame-ancestors 'self'`,
|
"Content-Security-Policy": FRAME_CSP,
|
||||||
"X-Content-Type-Options": "nosniff",
|
"X-Content-Type-Options": "nosniff",
|
||||||
"Referrer-Policy": "no-referrer",
|
"Referrer-Policy": "no-referrer",
|
||||||
"Cache-Control": preview ? "no-store" : "public, max-age=60",
|
"Cache-Control": preview ? "no-store" : "public, max-age=60",
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
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'/);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { NextConfig } from "next";
|
import type { NextConfig } from "next";
|
||||||
import { SECURITY_HEADERS } from "./app/lib/securityHeaders";
|
import { SECURITY_HEADERS } from "./app/lib/securityHeaders";
|
||||||
|
import { FRAME_CSP } from "./app/lib/frameHtml";
|
||||||
|
|
||||||
// 2026-10-07: CI run 5545 (#731 CMS forms) failed in Docker build (a runner storage fault while run
|
// 2026-10-07: CI run 5545 (#731 CMS forms) failed in Docker build (a runner storage fault while run
|
||||||
// 5544 built at the same time), so nothing from #731 rolled out. Only a push that changes this
|
// 5544 built at the same time), so nothing from #731 rolled out. Only a push that changes this
|
||||||
@@ -9,7 +10,15 @@ const nextConfig: NextConfig = {
|
|||||||
// harden-portal-requests (F30): no X-Powered-By, baseline security headers everywhere.
|
// harden-portal-requests (F30): no X-Powered-By, baseline security headers everywhere.
|
||||||
poweredByHeader: false,
|
poweredByHeader: false,
|
||||||
async headers() {
|
async headers() {
|
||||||
return [{ source: "/:path*", headers: [...SECURITY_HEADERS] }];
|
// add-custom-html-block: these headers replace a route's own, so the Custom HTML frame paths get their sandbox
|
||||||
|
// policy back from a later rule (the last rule setting a key wins). Without it, a frame address opened directly
|
||||||
|
// would run pasted scripts as this origin.
|
||||||
|
const frame = [{ key: "Content-Security-Policy", value: FRAME_CSP }, { key: "Referrer-Policy", value: "no-referrer" }];
|
||||||
|
return [
|
||||||
|
{ source: "/:path*", headers: [...SECURITY_HEADERS] },
|
||||||
|
{ source: "/p/:company/:slug/frame/:block", headers: frame },
|
||||||
|
{ source: "/pages/:id/preview/frame/:block", headers: frame },
|
||||||
|
];
|
||||||
},
|
},
|
||||||
reactStrictMode: true,
|
reactStrictMode: true,
|
||||||
// Stop `next dev` writing AGENTS.md/CLAUDE.md into the repo; agent instructions live in the root CLAUDE.md.
|
// Stop `next dev` writing AGENTS.md/CLAUDE.md into the repo; agent instructions live in the root CLAUDE.md.
|
||||||
|
|||||||
Reference in new issue
Block a user