feat(pages): Custom HTML block in a sealed frame, and Hide page header #55

Merged
ngqile merged 9 commits from add-custom-html-block into main 2026-12-02 10:22:26 +00:00
Owner

OpenSpec change add-custom-html-block (design and change approved 2026-12-02).

What

  • New landing-page block Custom HTML. Staff paste AI-generated HTML, up to 200,000 characters. Scripts are allowed in this block only.
  • The block is shown in an <iframe sandbox="allow-scripts allow-popups allow-popups-to-escape-sandbox">. The iframe loads from the block's own address:
    • published pages: /p/<company>/<slug>/frame/<n>;
    • staff preview: /pages/<id>/preview/frame/<n>.
  • The frame response carries Content-Security-Policy: sandbox …; frame-ancestors 'self'. Opened directly, it still runs with an opaque origin: no same-origin, no form submission, no top-level navigation.
  • A small script reports the frame's height. The frame grows to fit, between 100 and 20,000 px. It accepts reports only from its own window. A guard stops the loop that full-viewport-height sections would cause.
  • New page option Hide page header: hides the company header and the visible title. The title stays for screen readers.
  • Editor:
    • "Add Custom HTML" with a monospace box;
    • a character counter;
    • a note that forms inside pasted HTML don't send;
    • the Hide page header switch.
  • New cms_page.hide_header column. /api/pages saves now get the 10 MB body limit.

Review notes

  • Security fix found in the live check: next.config's baseline Content-Security-Policy replaced the frame route's own header, so the sandbox was missing. A later headers() rule for the two frame paths restores it. next.config.frame.test.ts covers this. In the browser, the frame response now carries the sandbox policy.
  • Existing guard test extended: noHtmlInjection.sweep.test.ts required sandbox="" on every iframe.
    • HtmlFrame.tsx is now allow-listed, for the named FRAME_SANDBOX constant only.
    • A new assertion checks that FRAME_SANDBOX never grants same-origin, forms, top navigation or modals.
    • All existing assertions are unchanged.
  • The session cookie is httpOnly with SameSite=Lax, and the middleware refuses cross-site writes. A pasted script cannot act as a signed-in staff member.

SQL (in the change folder)

  • sql/01-hide-header.sql (DDL)
  • sql/02-html-block-labels.sql (labels)
  • sql/99-rollback.sql

docs/deployment.md lists the files. It also notes that a proxy must not replace the frame's CSP.

Verification

  • services-counter: 340 tests green.
  • mobile-api: 985 tests green.
  • Portal: 1860 vitest tests pass (exit 0). tsc is clean. Lint shows 0 errors; the 4 warnings were already there.
  • Playwright on the local stack, at 1280 and 360 px:
    • The INS proof-of-concept HTML is pasted into the INS page, with Hide page header on and the sign-up form below. It looks like the proof of concept, and the frame sizes to 4204 px at 1280 and 6696 px at 360.
    • The frame response headers show the sandbox CSP and no-referrer.
    • While the page is a draft, visitors get 404 for the page and the frame. The staff preview shows the frame, with no-store. A signed-out request for the preview frame redirects to the login page.
    • A paste of 200,002 characters is refused at its field ("Too long.").

🤖 Generated with Claude Code

https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs

OpenSpec change `add-custom-html-block` (design and change approved 2026-12-02). ## What - New landing-page block **Custom HTML**. Staff paste AI-generated HTML, up to 200,000 characters. Scripts are allowed in this block only. - The block is shown in an `<iframe sandbox="allow-scripts allow-popups allow-popups-to-escape-sandbox">`. The iframe loads from the block's own address: - published pages: `/p/<company>/<slug>/frame/<n>`; - staff preview: `/pages/<id>/preview/frame/<n>`. - The frame response carries `Content-Security-Policy: sandbox …; frame-ancestors 'self'`. Opened directly, it still runs with an opaque origin: no same-origin, no form submission, no top-level navigation. - A small script reports the frame's height. The frame grows to fit, between 100 and 20,000 px. It accepts reports only from its own window. A guard stops the loop that full-viewport-height sections would cause. - New page option **Hide page header**: hides the company header and the visible title. The title stays for screen readers. - Editor: - "Add Custom HTML" with a monospace box; - a character counter; - a note that forms inside pasted HTML don't send; - the Hide page header switch. - New `cms_page.hide_header` column. `/api/pages` saves now get the 10 MB body limit. ## Review notes - **Security fix found in the live check:** `next.config`'s baseline `Content-Security-Policy` replaced the frame route's own header, so the sandbox was missing. A later `headers()` rule for the two frame paths restores it. `next.config.frame.test.ts` covers this. In the browser, the frame response now carries the sandbox policy. - **Existing guard test extended:** `noHtmlInjection.sweep.test.ts` required `sandbox=""` on every iframe. - `HtmlFrame.tsx` is now allow-listed, for the named `FRAME_SANDBOX` constant only. - A new assertion checks that `FRAME_SANDBOX` never grants same-origin, forms, top navigation or modals. - All existing assertions are unchanged. - The session cookie is httpOnly with SameSite=Lax, and the middleware refuses cross-site writes. A pasted script cannot act as a signed-in staff member. ## SQL (in the change folder) - `sql/01-hide-header.sql` (DDL) - `sql/02-html-block-labels.sql` (labels) - `sql/99-rollback.sql` `docs/deployment.md` lists the files. It also notes that a proxy must not replace the frame's CSP. ## Verification - **services-counter:** 340 tests green. - **mobile-api:** 985 tests green. - **Portal:** 1860 vitest tests pass (exit 0). `tsc` is clean. Lint shows 0 errors; the 4 warnings were already there. - **Playwright** on the local stack, at 1280 and 360 px: - The INS proof-of-concept HTML is pasted into the INS page, with Hide page header on and the sign-up form below. It looks like the proof of concept, and the frame sizes to 4204 px at 1280 and 6696 px at 360. - The frame response headers show the sandbox CSP and `no-referrer`. - While the page is a draft, visitors get 404 for the page and the frame. The staff preview shows the frame, with `no-store`. A signed-out request for the preview frame redirects to the login page. - A paste of 200,002 characters is refused at its field ("Too long."). 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
ngqile added 9 commits 2026-12-02 10:22:23 +00:00
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
The counter accepts an HTML block (required, at most 200,000 characters, no
script check because it only runs sealed) and stores a hide-header flag on the
page. mobile-api passes the flag through on save and in the public page.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
The iframe guard allow-lists HtmlFrame.tsx for the named FRAME_SANDBOX
only, and asserts it never grants same-origin, forms, top navigation
or modals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
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
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
ngqile merged commit dd6cbfe71c into main 2026-12-02 10:22:26 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: ngqile/co-lite#55