Skip to main content
MediumContentOWASP A05:2021CWE-1021

How to fix: srcdoc iframe without sandbox attribute

An <iframe srcdoc="..."> embeds inline HTML directly in the page without a sandbox attribute, giving that inline content full same-origin privileges.

Why it matters

Inline srcdoc markup runs in the parent page's own origin unless it is sandboxed. If any part of that markup is ever built from dynamic or user-influenced data, script inside it can read the page's cookies, storage, and DOM exactly as first-party code could.

Unlike a regular src= iframe loading a separate document, srcdoc content is embedded inline -- without sandbox, it runs with the same privileges as the parent page, which matters if the srcdoc value is ever built from dynamic or user-influenced data.

How to fix it

  1. 1Add sandbox="" to the srcdoc iframe. That is the maximally restrictive value and is enough for static inline markup.
  2. 2Only if the inline content genuinely needs it, add the single narrowest token back (e.g. sandbox="allow-scripts"). Never combine allow-scripts with allow-same-origin: together they let the framed content remove its own sandbox, which defeats the point.

Code examples

Add sandbox to srcdoc iframes

HTML
<iframe
  srcdoc="<p>Safe static content</p>"
  sandbox=""
  title="Safe frame"
></iframe>
<!-- sandbox="" is maximally restrictive
     Add permissions only as needed:
     sandbox="allow-scripts" for JS-only iframes -->

References

Detected automatically by VulnRadar. The check id is iframe-srcdoc-no-sandbox, stable across every scan so you can filter or diff on it.

See every content check

Questions

How severe is srcdoc iframe without sandbox attribute?
VulnRadar rates this medium severity in the content category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id iframe-srcdoc-no-sandbox, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does srcdoc iframe without sandbox attribute map to?
It maps to CWE-1021. In the OWASP Top 10 it falls under A05:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for srcdoc iframe without sandbox attribute

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

srcdoc iframe without sandbox attribute fix | VulnRadar