Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

sandbox

Locks down an iframe: scripts, forms, popups, top-level navigation and the frame's real origin are all withheld until you add tokens to grant them back.

Overview

The sandbox attribute on <iframe> applies a set of restrictions to the framed document. With no value, everything is restricted: no scripts, no form submission, no popups, no modal dialogs, no navigating the top-level page, no downloads, and the document gets a unique opaque origin, so it is cross-origin with every other page, including the one it came from. Each token you add grants one capability back.

Applies to: <iframe>

The demo puts the same inline document in three frames. With no tokens its script never runs. With allow-scripts it runs in an opaque origin (null) and cannot touch the page. With allow-scripts allow-same-origin it runs with this page's origin and can read and change this page.

Values

The value is an unordered, space-separated set of tokens. An empty value (sandbox or sandbox="") applies every restriction. Unknown tokens are ignored. The attribute is not inherited, but a sandboxed document's own frames and popups are sandboxed at least as strictly.

TokenGrants
allow-scriptsRunning scripts (not popups: those need allow-popups).
allow-same-originKeep the document's real origin instead of an opaque one, so cookies, storage and same-origin APIs work. It never makes third-party content same-origin with your page.
allow-formsSubmitting forms.
allow-modalsalert(), confirm(), prompt() and print().
allow-popupsOpening new windows (window.open(), target="_blank"). The popup inherits the sandbox.
allow-popups-to-escape-sandboxPopups open without the sandbox (needed for "open this post on the site" links).
allow-top-navigation-by-user-activationNavigating the top-level page, but only from a click or other user gesture.
allow-top-navigationNavigating the top-level page at any time, with or without a gesture.
allow-top-navigation-to-custom-protocolsNavigating to non-HTTP schemes such as mailto:. Not implemented in Chromium.
allow-downloadsStarting downloads.
allow-pointer-lockThe Pointer Lock API.
allow-orientation-lockLocking screen orientation.
allow-presentationThe Presentation API.
allow-storage-access-by-user-activationRequesting unpartitioned cookie access through the Storage Access API. Not yet in the HTML standard.

A sandboxed frame can always navigate itself; the sandbox restricts navigating other frames and the top-level page.

Examples

Untrusted third-party widget

Start from an empty sandbox and add only what the embed needs. A third-party URL is a different origin, so allow-same-origin just lets it keep its own cookies; it still cannot reach your page.

Checkout that may redirect the page

Payment flows sometimes need to send the whole page to a 3-D Secure or confirmation step. Grant top-level navigation only from a user gesture, so the frame cannot redirect your page on its own (a common phishing trick).

Inline HTML with srcdoc

For HTML you hold as a string (previews, emails, user posts) use srcdoc with an empty sandbox. Without a sandbox, srcdoc content runs with your origin.

The escape: same-origin content with scripts

This is the configuration the demo's third frame shows. The content is same-origin with the page (a path on your own site, a srcdoc document or about:blank), and the sandbox lets it keep that origin and run scripts. It can reach into the parent, including frameElement, and remove its own sandbox attribute.

For cross-origin content (a different host) the same two tokens are fine: the browser's same-origin policy still separates the frame from your page. Browsers warn in the console whenever both tokens appear, whatever the origin.

In Vanilla Breeze

  • <social-embed> renders every post (Bluesky, Mastodon, X, Instagram) as a sandboxed, lazily loaded iframe with referrerpolicy="strict-origin". Built-in providers use allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox, which is safe because the frames are on the provider's origin; Mastodon drops allow-popups-to-escape-sandbox. See src/web-components/social-embed/shared.js (createEmbedFrame, POST_SANDBOX).
  • VB's HTML sanitiser (src/lib/sanitize-html.js), used for untrusted markdown and comments, removes <iframe> elements and the srcdoc attribute entirely rather than trying to sandbox them.
  • Styling: iframe.bordered, iframe.rounded and iframe[data-ratio="16:9"] come from src/native-elements/iframe/styles.css; the attribute itself has no styling hook.
  • Doc-site demos in <browser-window> are not sandboxed: they are same-origin VB pages.

Accessibility

  • Give every iframe a title that names its content; screen readers announce it on entry.
  • Sandboxing does not change focus order: keyboard users tab into and out of the frame as usual. Test that the embedded content itself is keyboard-usable, because blocked scripts can leave half-working controls.
  • When a feature is blocked (forms, popups), the user gets no feedback inside the frame. If an embed depends on one, grant it or link to the content directly.

Security

  • Never combine allow-scripts and allow-same-origin for same-origin content you do not control, including srcdoc and about:blank. The sandbox becomes advisory.
  • Prefer allow-top-navigation-by-user-activation over allow-top-navigation.
  • allow-popups-to-escape-sandbox means links in the frame open unrestricted pages. Use it only for trusted providers.
  • Changes to the sandbox attribute apply on the frame's next navigation, not to the document already loaded.
  • Sandbox limits what the frame can do; Content Security Policy limits what it can load. Pages you serve yourself can also be sandboxed with the Content-Security-Policy: sandbox header.

Browser support

The attribute and the core tokens are supported everywhere. As of November 2026 (MDN browser-compat-data): allow-downloads Chrome 83, Firefox 82, Safari 17; allow-top-navigation-to-custom-protocols Firefox 101 and Safari 16, not Chromium; allow-storage-access-by-user-activation Chrome 113, Firefox 65, Safari 11.1.

Gotchas

  • Blocked actions are quiet in the page but logged in the console. Chromium logs, for example, "Blocked form submission … because the form's frame is sandboxed and the 'allow-forms' permission is not set." Check DevTools when an embed seems broken.
  • Opaque origin side effects. Without allow-same-origin, localStorage and cookie access throw or are empty, origin is "null", and CORS requests carry Origin: null.
  • Popups inherit the sandbox unless you add allow-popups-to-escape-sandbox, which can break sites opened from the frame.
  • allow-scripts is all or nothing. Use CSP inside the framed document for finer control.

Related

  • srcdoc — inline HTML in a frame; needs sandbox when the HTML is untrusted.
  • allow — Permissions Policy: camera, fullscreen, payment and other powerful APIs.
  • referrerpolicy — how much of your URL the frame's request reveals.
  • target — _top and _parent navigation, which the sandbox restricts.
  • nonce — Content Security Policy for your own scripts.
  • <iframe> — the element and VB's iframe styles.
  • <social-embed> and <youtube-player> — embeds that set these attributes for you.

Which to choose

  • A social post or video — use <social-embed> or <youtube-player>; they choose the sandbox and permissions.
  • A third-party page — sandbox with the fewest tokens it needs, plus allow for any powerful API.
  • HTML you hold as a string — srcdoc with an empty sandbox (add allow-scripts only, never with allow-same-origin).
  • User HTML shown inline in your page — no iframe: sanitise it (VB's markdown and comment components do).
↑