qat

Security

What Qat guarantees about markup, URLs and the build, and where each guarantee is tested.

Data is data

Every binding puts a value in the page as a value:

  • {x} is a text node, in an element, a block ({if}, {for}, {switch}, {try}) or a list row.
  • Attributes and properties (title={x}, class={x}, class:on={x}, data-*, aria-*, value, bind:value, textContent) are set as attribute values or properties.
  • style={…} and style:prop={…} go through the CSSOM.

So markup in data never becomes elements or handlers. packages/compiler/test/corpus/security.test.ts runs a payload with a <script>, an <img onerror> and an attribute break-out through every one of them.

One way to insert HTML: innerHTML={…}

export default function Article({ html }) {
  return <div class="article-body" innerHTML={html} />
}

innerHTML inserts markup as it is, unescaped. It is the one way to put markup into an element, and with a value from data it is a QX-HTML warning, so every such place shows up in qatjs check. An iframe's srcdoc={…} makes a whole document from markup (its scripts run, on the page's origin unless the iframe has sandbox): from data, it is the same warning. Give it only markup you trust, or have sanitized (DOMPurify, or your server's sanitizer). qatjs migrate converts React's dangerouslySetInnerHTML={{ __html: x }} to it.

(The main spec named this raw(html). raw already means the value behind deep state, from @qatjs/core/deep, and one word has one meaning: D135.)

URLs from data cannot be script

A javascript: or vbscript: URL that reaches href, src, action, formaction, poster, cite, xlink:href or an <object>'s data from data becomes about:blank#blocked. That includes mixed case, leading spaces and control characters, and tabs or newlines inside the scheme. Other URLs pass unchanged (/path, https:, mailto:, tel:, #hash, data: images). A static URL in your own markup is yours.

The check is compiled into the module that binds the URL. The runtime carries none, so a hand-written attr(a, 'href', …) through the runtime API is not checked.

The build

  • No eval, no new Function, no inline event handlers. Styles go through the CSSOM, never an inline style attribute. So a strict Content-Security-Policy allows a Qat app as it is.
  • qatjs compress writes that policy, dist/csp.json: hashes of the inline scripts and styles, object-src 'none', no unsafe-*, and a nonce variant. It also adds SRI integrity to every script and stylesheet, and lists every bundled package in dist/audit.json. See compress.md.
  • The shop's browser suite runs the build under its own policy, with no violation, and checks that a tampered chunk does not run.
  • Only PUBLIC_ variables reach the browser. A private one in client code is a compile error (dev.md).