Safeguard
Developer Tools•

Which iframe sandbox tokens does a store widget need?

A sandboxed iframe starts with every restriction on. Learn which tokens a review, chat or payment widget needs and which combination undoes the sandbox.

Safeguard Security Team
4 min read

Start with an empty sandbox attribute, which applies every restriction, then add only the tokens the widget fails without. Most widgets need allow-scripts. Avoid combining allow-scripts with allow-same-origin on content from your own origin, because that pairing lets the framed page remove its own sandbox.

How the attribute works

MDN describes the sandbox attribute on an iframe as controlling the restrictions applied to embedded content. An empty value applies all restrictions. Space-separated tokens lift particular restrictions one at a time.

That makes it an allowlist: you grant what is needed. For a store, that is a useful default, because widgets such as reviews, chat, store locators or loyalty panels rarely need the full power of your page.

Tokens a widget might ask for

TokenWhat it allowsTypical need
allow-scriptsRun JavaScript inside the frameAlmost every widget
allow-formsSubmit formsSign-up or review forms
allow-popupsOpen new windows or tabsLinks that open elsewhere
allow-popups-to-escape-sandboxOpened windows are not sandboxedLinks to a partner site that must work normally
allow-same-originTreat the frame as its real originWidgets that need their own cookies or storage
allow-top-navigationLet the frame navigate your whole pageRarely, and ask why
allow-modalsShow alert and confirm dialogsRarely

MDN also notes a detail that surprises people: if a sandboxed frame opens a new page and the popup token is set without the escape token, the new page inherits the same restrictions, and a form submission there can silently fail.

The one combination to avoid

MDN states that when the embedded document has the same origin as the embedding page, using both allow-scripts and allow-same-origin is strongly discouraged. The framed page can then remove the sandbox attribute, making it no more secure than having no sandbox at all.

For a widget served from the vendor's own domain, the situation differs, since the frame is cross-origin to your page. Even so, grant allow-same-origin only when the widget breaks without it, and record why.

Steps to choose tokens

  1. Embed the widget with an empty sandbox attribute.
  2. Load the page and watch the browser console for blocked actions.
  3. Add one token at a time, reloading after each, until the widget works.
  4. Write down each token and the reason in your tag register.
  5. Recheck when the vendor ships a major change, since needs can grow.

What a sandbox does not do

A sandbox limits the framed page. It does not make the vendor trustworthy, and it does not help if the vendor's script is a plain script tag on your page rather than inside a frame. The OWASP cheat sheet suggests combining iframe sandboxing with a Content Security Policy for high risk applications, and notes the frame and the main page can talk through postMessage.

Payment widgets often have their own rules about how they must be embedded. Follow your payment provider's instructions and PCI guidance first, and use the sandbox for the other widgets.

Where Safeguard fits

If a widget arrives as an npm package rather than a frame, Safeguard's dependency scanning and policies apply to the package. Frames themselves are a page-level control. A free scan is at gold.safeguard.sh/scan.

Quick check

Does an empty sandbox attribute mean no sandbox?

No. An empty value applies all restrictions, which is the strictest setting.

Can a sandboxed widget read my checkout form?

Not through the page's DOM, since a frame is a separate document. Do not put the widget on the checkout page without a clear need.

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.