pub enum Sandbox {
AllowForms,
AllowModals,
AllowOrientationLock,
AllowPointerLock,
AllowPopups,
AllowPopupsToEscapeSandbox,
AllowPresentation,
AllowSameOrigin,
AllowScripts,
AllowTopNavigation,
AllowTopNavigationByUserActivation,
}Expand description
The sandbox attribute values for <iframe> elements.
§Purpose
Enables extra restrictions on iframe content for security, allowing fine-grained control over what capabilities the embedded content has access to.
§Usage Context
- Used with:
<iframe>elements - Security: Applies strict sandbox by default; flags allow specific capabilities
- Multiple values: Space-separated list of allowed capabilities
- Default: Empty sandbox (most restrictive)
§Valid Values
AllowForms: Allow form submissionAllowModals: Allow opening modal windows (alert, confirm, print)AllowOrientationLock: Allow screen orientation lockAllowPointerLock: Allow Pointer Lock APIAllowPopups: Allow popups (window.open, target=“_blank”)AllowPopupsToEscapeSandbox: Allow popups without sandbox restrictionsAllowPresentation: Allow Presentation APIAllowSameOrigin: Treat content as same-origin (use with caution)AllowScripts: Allow JavaScript executionAllowTopNavigation: Allow navigating top-level browsing contextAllowTopNavigationByUserActivation: Allow top navigation only from user gesture
§Example
use ironhtml_attributes::{AttributeValue, Sandbox};
let sandbox = Sandbox::AllowScripts;
assert_eq!(sandbox.to_attr_value(), "allow-scripts");<iframe src="untrusted.html" sandbox></iframe>
<iframe src="widget.html" sandbox="allow-scripts allow-same-origin"></iframe>
<iframe src="game.html" sandbox="allow-scripts allow-pointer-lock"></iframe>§WHATWG Specification
Variants§
AllowForms
Allow form submission from the sandboxed content.
AllowModals
Allow the sandboxed content to open modal windows (alert, confirm, print, etc.).
AllowOrientationLock
Allow the sandboxed content to lock the screen orientation.
AllowPointerLock
Allow the sandboxed content to use the Pointer Lock API.
AllowPopups
Allow the sandboxed content to open popup windows.
AllowPopupsToEscapeSandbox
Allow popups opened by the sandboxed content to not inherit the sandbox restrictions.
AllowPresentation
Allow the sandboxed content to use the Presentation API.
AllowSameOrigin
Allow the content to be treated as being from its normal origin.
WARNING: Dangerous when combined with allow-scripts.
AllowScripts
Allow the sandboxed content to run scripts (but not create popups).
Allow the sandboxed content to navigate the top-level browsing context (the full window).
Allow top-level navigation only when triggered by user activation
(safer than allow-top-navigation).