V03

Warning

Vocabulary

V03 — Markup put in as markup

An Unsafe.Html, and whether what it puts in went through sanitize; and a Frame(srcdoc:) drawing HTML from a value, which is sandboxed (sandbox="") unless it says what it may do.

What the compiler said

warning[V03]: `Unsafe.Html` puts markup in as markup --> src/App.wf:4:5 | 4 | Unsafe.Html(body) | ^^^^^^^^^^^ = help: Anything the project did not write itself belongs in `sanitize(…)` first = docs: https://webfluent.monzeromer.dev/errors/V03

The fix

Broken

wf

page P(path: "/", title: "T", description: "D") { state body = "<b>Hi</b>" Heading("Markup").h1 Unsafe.Html(body) }

Fixed

wf

page P(path: "/", title: "T", description: "D") { state body = "**Hi**" Heading("Markup").h1 Markdown(body) }

Most text wants no markup of its own: write it as Markdown, which Markdown(body) draws with any HTML in it shown as text. Markup that must stay markup and comes from outside the project goes through sanitize(…) first — Unsafe.Html(sanitize(body)) — which is the reviewed case, and the warning still names it.

A Frame(srcdoc:) drawing HTML from a value is named too: that HTML is a document of its own, scripts and all. Unless the call says what the frame may do, it may do nothing — the build gives it sandbox="" — and the warning says so. Writing sandbox: out is the reviewed case; allow-scripts with allow-same-origin undoes the sandbox, and is named again.

page P(path: "/", title: "T", description: "D") {
    state html = "<p>Hi</p>"
    Heading("Preview").h1
    Frame(srcdoc: html, title: "Preview")
}
warning[V03]: `Frame(srcdoc:)` draws HTML from a value as a document; it is sandboxed (`sandbox=""`), so nothing in it runs
 --> src/App.wf:4:5
  |
4 |     Frame(srcdoc: html, title: "Preview")
  |     ^^^^^
  = help: Say what it may do with `sandbox:` — `sandbox: ""` keeps it as it is now; `allow-scripts` and `allow-same-origin` together undo the sandbox
  = docs: https://webfluent.monzeromer.dev/errors/V03

Fix: Frame(srcdoc: html, title: "Preview", sandbox: "").

Each example is a whole program: it is all of src/App.wf in a project with no other .wf file (trying an example).

lints may lower it:

"lints": { "V03": "off" } // wf-allow(V03)