Safeguard
Security Guides•

iframe sandbox attribute: which tokens to allow and which to avoid

An empty sandbox attribute blocks scripts, forms and popups. Add tokens one at a time, and avoid allow-scripts with allow-same-origin on same-origin content.

Safeguard Security Team
3 min read

The iframe sandbox attribute strips an embedded page of most powers. An empty value applies every restriction, and each token you add lifts one. Start empty, add only what the embed needs, and never combine allow-scripts with allow-same-origin for content from your own origin.

What an empty sandbox does

Per MDN, without allow-same-origin the content gets a special origin that fails the same-origin policy, so storage, cookies and some APIs are blocked. Without allow-scripts, scripts do not run. Forms render but do not submit. Popups silently fail. Navigating the top window is blocked.

Common tokens

TokenLifts
allow-scriptsScript execution
allow-same-originThe special origin, restoring the real one
allow-formsForm submission
allow-popupswindow.open and target blank
allow-downloadsDownloads
allow-modalsalert, confirm, prompt, print
allow-top-navigationNavigating the top window
allow-top-navigation-by-user-activationSame, after a user gesture
allow-popups-to-escape-sandboxNew windows leave the sandbox

The combination to avoid

If the embedded document is same-origin with your page, allow-scripts plus allow-same-origin lets it remove its own sandbox attribute. MDN says this is strongly discouraged, since it is then no safer than no sandbox.

<iframe sandbox="allow-scripts" src="https://widget.example.net/embed"></iframe>

This form runs scripts but keeps the content on a unique origin. For user-generated HTML, serve it from a separate origin and keep it sandboxed.

Pair it with other controls

A rollout approach

List every iframe in your templates. For each, write down what it must do, set sandbox empty, and add tokens until the feature works. Record the reason for each token in code review. Repeat when a vendor changes its embed.

Safeguard note

Embedded vendors are dependencies too. Safeguard's SBOM and dependency scanning and the free scan at gold.safeguard.sh/scan cover the packages you ship, while this checklist covers the frames.

Quick check

Does sandbox stop clickjacking?

No. It restricts the embedded page. Preventing your page from being framed is a job for frame-ancestors.

Why does my embed show a blank or broken page?

A missing token is the usual cause, often allow-scripts or allow-forms. Add one at a time and retest.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.