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
- 1Add sandbox="" to the srcdoc iframe. That is the maximally restrictive value and is enough for static inline markup.
- 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
<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.
More content checks
- MediumPotential Open Redirect Parameters
- HighDirectory Listing Appears Enabled
- MediumSensitive File References Detected
- HighPotentially Outdated JavaScript Libraries
- Inforobots.txt Present - Review Manually
- InfoCMS / Technology Fingerprinting
- MediumPotentially Dangerous Inline JavaScript
- LowServer version disclosed in response header
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.