Files
co-lite/openspec/changes/add-custom-html-block/specs/landing-pages/spec.md
T

6.7 KiB

MODIFIED Requirements

Requirement: A Page Is An Ordered List Of Typed Blocks

A page SHALL belong to one company and have a slug, a title, an optional meta description, a status (Draft or Published), a "hide header" flag that defaults to off, and an ordered list of zero to 30 blocks. The block types SHALL be HERO, RICH_TEXT, IMAGE_TEXT, FAQ, FORM and HTML. Blocks SHALL be returned in the order they were saved, and a valid save SHALL replace all of a page's blocks.

Scenario: Blocks read back in order

  • WHEN staff save page hotel-technology with blocks HERO, RICH_TEXT, FORM
  • THEN reading the page returns those three blocks in that order with their fields

Scenario: A save replaces the blocks

  • GIVEN a page whose blocks are HERO and FAQ
  • WHEN it is saved with only a RICH_TEXT block
  • THEN the page has only that RICH_TEXT block

Scenario: An HTML block and the header flag read back

  • WHEN staff save a page with "hide header" on and blocks HTML, FORM
  • THEN reading the page returns "hide header" on and the HTML block with its HTML unchanged

Requirement: Block Fields Are Validated Server-Side

A page save SHALL be refused with the offending field path, writing nothing, when a block has an unknown type, a required field is blank, or a text exceeds its limit: heading 120, text and FAQ question 300, button label 40, FAQ answer 2000, rich-text HTML 100000 characters, and an HTML block's HTML 200000 characters. An HTML block's HTML SHALL NOT be blank. A FAQ SHALL have 1 to 30 items. imagePosition SHALL be LEFT or RIGHT.

Scenario: Too many blocks

  • WHEN a page is saved with 31 blocks
  • THEN the save is refused and nothing is written

Scenario: HTML block too long

  • WHEN a page is saved with an HTML block of 200001 characters
  • THEN the save is refused on field blocks[0].html and nothing is written

Requirement: Page Content Cannot Run Scripts

A button SHALL have both a label and a link or neither. The link SHALL be a same-site path starting with a single /, an https:// URL, a mailto: link or a tel: link. A save SHALL be refused when the HTML of a RICH_TEXT or IMAGE_TEXT block holds a script element, an on* attribute or a javascript: URL. The public page SHALL also sanitise that HTML against an allow-list before rendering it. HTML blocks are exempt, because they only ever run sealed.

  • WHEN a page is saved with a HERO button link javascript:alert(1)
  • THEN the save is refused on field blocks[0].buttonUrl

Scenario: Script in rich text

  • WHEN a page is saved with rich text holding <img src=x onerror=alert(1)>
  • THEN the save is refused on that block's HTML field

Scenario: Script in an HTML block

  • WHEN a page is saved with an HTML block holding <script>document.title = "x"</script>
  • THEN the save succeeds

ADDED Requirements

Requirement: Custom HTML Runs Sealed

The public page and the staff preview SHALL show each HTML block in a sandboxed frame loaded from its own address. Each frame response SHALL carry a Content-Security-Policy whose sandbox directive allows scripts and pop-ups only, so the HTML runs with an opaque origin even when the address is opened directly, and whose frame-ancestors directive allows only the Co-Lite site. The frame element SHALL NOT grant same-origin, form submission, top-level navigation or modal dialogs.

Scenario: Public frame is sealed

  • GIVEN INS page hotel-technology is published with an HTML block at index 0
  • WHEN a visitor's browser loads /p/INS/hotel-technology/frame/0
  • THEN the response is the block's HTML with a sandbox policy that allows scripts and pop-ups and not same-origin
  • AND its frame-ancestors allows only the Co-Lite site

Scenario: Pasted HTML cannot reach the visitor's session

  • GIVEN a published HTML block whose script reads document.cookie and calls /api/auth/session
  • WHEN the page is shown
  • THEN the script sees no Co-Lite cookies and its call carries no Co-Lite session

Requirement: Custom HTML Frame Addresses

The public frame address SHALL be /p/<company>/<slug>/frame/<block index> and SHALL answer only for an HTML block of a published page; every other request SHALL get the same not-found response. The preview frame address SHALL be /pages/<id>/preview/frame/<block index> and SHALL require a signed-in user with BO_PAGES who may see that page.

Scenario: No frame for a draft, a missing block or a non-HTML block

  • WHEN a visitor loads the frame address of a draft page, of block 7 of a page with 3 blocks, or of a FORM block
  • THEN each answers with the same not-found response

Scenario: Staff preview of a draft frame

  • GIVEN a draft page with an HTML block
  • WHEN a signed-in user with BO_PAGES of that page's company opens the preview
  • THEN the frame shows the draft HTML, sealed as on the public page
  • AND the same address without a session sends the browser to sign in

Requirement: Custom HTML Frame Height

The frame SHALL grow to fit its content, between 100 and 20000 pixels, using height reports sent by that frame only. Before the first report it SHALL be 600 pixels tall.

Scenario: A tall paste grows the frame

  • GIVEN a published HTML block whose content is 3000 pixels tall
  • WHEN a visitor opens the page
  • THEN the frame is 3000 pixels tall and shows no inner scroll bar

Scenario: Another frame cannot resize it

  • WHEN a different window posts a height report to the page
  • THEN the frame's height does not change

Requirement: The Custom HTML Block In The Editor

The editor SHALL offer "Add Custom HTML", which adds an HTML block with a monospace text box, a 200000-character counter and a note that forms inside the pasted HTML do not send and the sign-up form block collects leads. The editor SHALL also offer a "hide page header" switch for the page.

Scenario: Adding a Custom HTML block

  • WHEN staff add a Custom HTML block and paste HTML into it
  • THEN the block shows the pasted HTML, the character count and the note about forms

Scenario: Hiding the header

  • WHEN staff turn on "hide page header" and save
  • THEN reading the page returns "hide header" on

Requirement: Hide Page Header

When a page's "hide header" flag is on, its public page and its preview SHALL NOT show the company header or the page title, and SHALL still use the page title in the browser title and the page metadata.

Scenario: Header hidden

  • GIVEN INS page hotel-technology has "hide header" on
  • WHEN a visitor opens it
  • THEN no company logo bar or page title heading shows above the first block
  • AND the browser title is still the page title