Security and limits
Why a Sneferu theme cannot run code: the element and attribute allow-lists, URL rules, escaping, render budgets and include cycles.
On this page
A theme is untrusted input that runs on every store that installs it. Sneferu is built so that a theme cannot run code, read data it was not given, or make one page slow for everyone. The compiler enforces the rules below, and the runtime checks the compiled artifact again before rendering it (SN9xxx), so a hand-edited artifact cannot bypass them.
Elements
Plain HTML elements are checked against an allow-list. Anything not on it is SN2001, including custom elements.
| Group | Allowed |
|---|---|
| Sectioning and grouping | address article aside blockquote dd details div dl dt figcaption figure footer h1 h2 h3 h4 h5 h6 header hgroup hr li main menu nav ol p pre search section summary ul |
| Text | a abbr b bdi bdo br cite code data del dfn em i ins kbd mark meter progress q rp rt ruby s samp small span strong sub sup time u var wbr |
| Media | audio img picture source track video |
| Tables | caption col colgroup table tbody td tfoot th thead tr |
| SVG (presentation only) | svg g path circle ellipse line polyline polygon rect text tspan defs lineargradient radialgradient stop clippath mask pattern symbol use title desc image |
Never allowed: script, style, iframe, object, embed, base, link,
meta, form, animate, set, animatemotion, animatetransform,
foreignobject, plaintext, xmp, noembed, noscript, frameset, frame,
template, slot, portal.
Form controls (button, input, select, textarea) are not on the list.
Form controls exist only through hk-search-form (see
Icons and search), which renders a fixed
GET form to the store's search page.
What a theme cannot do (yet)
| Not available | Instead |
|---|---|
JavaScript: no <script>, no on* handlers | Interactive parts come from platform tags. .js files are accepted in assets/ but nothing can load them in this release |
| Forms and inputs | hk-search-form for a search box, hk-button for links that look like buttons, and the cart tags (hk-variant-picker, hk-add-to-cart, hk-cart-items, hk-cart-summary, hk-cart-drawer, see Cart and controllers). Checkout is the store's own page, or hk-inline-checkout (a frame of it) |
Inline <style> or <link rel="stylesheet"> | assets/*.css |
Dynamic style="…{{ }}…" (SN2009) | classes, data-* + CSS, tokens, tag props |
{% if %} inside an attribute value (SN2020) | class="btn btn-{{ x }}" with a select setting, or {% if %} around two versions of the element |
Embeds (iframe, object, embed) | none. The only frame a theme can place is hk-inline-checkout's, of the store's own checkout |
| Reading arbitrary data | only the scope in chapter 4 |
Attributes
Rejected (SN2002):
- every attribute starting with
on(onclick,onload,onerror, …); srcdoc,formaction,attributename,xml:base;- any name outside
[a-z_:][a-z0-9_:.-]*.
Also rejected: style containing {{ }} (SN2009), and a {% %} directive inside any attribute value (SN2020).
URLs
URL attributes are href, every *:href (xlink:href), src, action,
poster, srcset and formaction.
| Allowed | Rejected |
|---|---|
https://… | http://… |
mailto:… | javascript:, vbscript:, data: and every other scheme |
tel:… | protocol-relative //host/… |
relative: /products, #reviews, ?page=2, sale | anything containing \ or control characters |
- A static unsafe URL is a compile error (SN2010).
- A dynamic URL (
href="{{ section.settings.link }}") is checked when the page renders; an unsafe value becomes#. - Images in
hk-imageand product cards must behttps://or start with/; anything else renders no image.
<a href="https://wa.me/201001234567">WhatsApp</a> <!-- ok -->
<a href="tel:01001234567">Call us</a> <!-- ok -->
<a href="http://example.com">…</a> <!-- SN2010 -->Escaping
All {{ }} output is escaped for its position (text, attribute, URL), and
dynamic class/id values are reduced to safe tokens. Merchant settings and
product data can never inject markup; HTML from data is output only through
hk-rich-text (see Rich text) and hk-custom-html (see Custom HTML and CSS). Comments <!-- --> in templates are
dropped at compile time.
Rich text
<hk-rich-text html="{{ … }}" /> is the only way HTML from data (a product
description, a rich_text setting) reaches the page. It goes through the rich
text sanitiser, which treats the HTML as hostile and rebuilds it rather than
filtering it: nothing from the input is copied to the page except text, which is
decoded once and escaped again.
| Kept | Everything else |
|---|---|
p br strong b em i u s ul ol li h2 h3 h4 blockquote a span | other tags are dropped and their text kept (<h1>Title</h1> becomes Title) |
href on a, when it is a safe URL: only https:, mailto:, tel: and site-relative links are kept; the link gets rel="nofollow noopener ugc" | every other attribute: on*, style, class, id, src, target, … |
http: links lose their href (the link text stays); so does any unsafe href (javascript:, //host, also when written with entities like javascript:) |
- The content of
script,style,template,iframe,object,svg,math,noscript,textarea,title(andxmp,noembed,noframes,plaintext) is dropped entirely, text included. - Comments,
<!DOCTYPE>and<![CDATA[…]]>are dropped. - Entities are decoded once and the text escaped again, so
<script>shows as the text<script>and never becomes a tag. - Unclosed tags are closed, stray closing tags ignored, nesting is capped at 64, and the output is at most 100,000 characters.
- An empty result renders nothing.
The output is stable: sanitising it again gives the same HTML.
Custom HTML and CSS
<hk-custom-html html="{{ … }}" css="{{ … }}" /> is the merchant's own markup and style block. The platform adds
a Custom HTML section (custom-html) to every theme's editor, without the theme being edited or re-published,
on index, product, collection, search, page and 404 (not cart, and never in a group). A theme may
also place the tag itself. Themes never ship JavaScript, and this block does not change that: no script, no event
handlers, no form controls.
Both props are sanitised on the server. Like rich text, the HTML is rebuilt: nothing from the input is copied except text (decoded once, escaped again) and attribute values that passed their own check.
| Kept | Everything else |
|---|---|
p div span a img br hr ul ol li h1-h6 table thead tbody tfoot tr td th caption strong em b i u s small sub sup mark blockquote figure figcaption code pre cite section article header footer nav aside | other tags are dropped and their text kept |
class id dir lang title aria-label aria-hidden role | every other attribute: on*, style, srcset, name, data-*, aria-* other than the two listed |
href on a when safe (https:, mailto:, tel:, site-relative, #fragment); links always get rel="nofollow noopener"; target only when _blank | javascript:, data:, //host, http: (also written with entities, tabs or control characters) |
src on img when https: or site-relative; alt, width, height (1-4000); loading="lazy" is forced | an img with any other src is removed |
colspan, rowspan (1-100) on td and th | |
<iframe> only for https://www.youtube.com/embed/ID, https://www.youtube-nocookie.com/embed/ID and https://player.vimeo.com/video/ID (optional plain query string). It is rebuilt with a fixed sandbox="allow-scripts allow-same-origin allow-presentation", referrerpolicy="strict-origin-when-cross-origin", loading="lazy" and allow="fullscreen; picture-in-picture" | any other iframe, with its content |
script style link meta base form input button select textarea object embed svg math template noscriptandtitle xmp noembed noframes plaintextare dropped (the content of the raw-text ones too). There is no inlinestyleattribute: put styles in thecssprop.idvalues are prefixed with the block's id (id="faq"becomesid="n7-faq") so they cannot shadow page globals or clash with another block;href="#faq"and#faqin the CSS are rewritten the same way.- The HTML is capped at 30,000 characters in the editor, nesting at 64, and the output at 50,000 characters. Sanitising the output again gives the same HTML.
- The hosts above must be allowed by the storefront's
frame-src; embeds are blocked by the browser otherwise.
The CSS
Every selector is rooted at the block (.sn-<id>), so a rule cannot style the rest of the page:
.card{…} becomes .sn-n7 .card{…}, and html, body, :root and :scope mean the block itself. The result is
emitted through the same per-page stylesheet as every other tag (ctx.css), so no <style> element or
style attribute is added to the block's markup and no CSP change is needed beyond what every other tag already relies on. After the merchant's rules, the engine adds
position:relative; isolation:isolate; contain:layout paint with !important, which makes the block the
containing block for position:absolute descendants and clips anything that would paint outside it.
| Kept | Dropped |
|---|---|
class, id, type, *, attribute selectors, combinators > + ~, :hover :focus :focus-visible :focus-within :active :first-child :last-child :nth-child() …, :not() :is() :where() (one level), ::before ::after ::marker ::placeholder ::selection ::first-line ::first-letter | the whole rule when any selector is invalid: :has(), :host, namespaces, escapes, braces, @ |
@media (width, height, prefers-color-scheme, prefers-reduced-motion, hover, orientation, two levels deep) | @import @charset @namespace @font-face @page @property @layer @supports @container and any other at-rule, with the block |
@keyframes, renamed to <id>-<name>; animation and animation-name are rewritten to match | nested rules |
An allow-list of presentational properties (layout, box model, grid, flex, typography, colour, background, border, shadow, transform, transition, animation, filter, clip-path, content as a string, custom properties --x) | mask, mask-image, list-style-image, behavior, -moz-binding, -o-link and every property not on the list |
Values built from numbers, keywords, hex colours, quoted strings and the functions calc min max clamp var env rgb[a] hsl[a] hwb lab lch oklab oklch color-mix, gradients, transforms, cubic-bezier steps minmax repeat, filter functions, shapes | url(), image-set(), expression(), attr(), javascript:, backslash escapes, <, >, @, unknown functions: the declaration is dropped |
position: static / relative / absolute | position: fixed / sticky |
z-index between -10 and 10, or auto | larger values |
!important is removed from the merchant's declarations, so they cannot outrank the page. The CSS is capped at
10,000 characters in the editor, 150 rules, 60 declarations per rule, 12 selectors per rule and 300 characters per
value. A rule that is not closed is dropped with everything after it. If the sanitised result still contained
anything dangerous (it should not), nothing is emitted.
Render budgets
Every page render is metered. The limits are fixed by the platform:
| Budget | Limit |
|---|---|
Rendered nodes per page (text, markup, tags, if, for, render, …) | 20,000 |
| Loop iterations per page, all loops | 2,000 |
| Output size per page | 1,500,000 characters |
Loop limit: | 1-250, default 50 (SN2007 outside) |
| Snippet and block include depth | 8 (SN4002) |
| Element and directive nesting | 64 (SN1108 at compile time, SN4003 at render) |
What happens when a budget runs out:
- Each section renders against what is left of the page budget. If a section
runs out, that section is replaced by
<!-- section <id> unavailable -->, SN4001 is reported once, and the layout and the sections before it are kept. - Sections after the point where the page budget is spent are also replaced.
- Include depth and nesting beyond the limit drop the deeper part (SN4002, SN4003, each reported once per page).
To stay well inside the budget: give every loop an explicit, small limit:,
avoid loops inside loops, and use hk-product-grid (one tag) rather than
rebuilding a grid from many small tags.
Include cycles
A snippet may not render itself, directly or through others:
snippets/a.snf: {% render 'b' %}
snippets/b.snf: {% render 'a' %}is a compile error: SN3027 snippet include cycle: a → b → a. Rendering a
snippet that does not exist is SN2008.
Diagnostics
Every problem has a stable code; the series tells you the stage:
| Series | Stage |
|---|---|
| SN1xxx | parsing |
| SN2xxx | template rules (elements, attributes, tags, URLs) |
| SN3xxx | files, manifest, compile |
| SN4xxx | rendering (the page still renders; the bad part is dropped) |
| SN9xxx | artifact integrity (rebuild) |
The full list with fixes: diagnostics.md.
