Disable Sanitization
By default, the aura:unescapedHTML component sanitizes HTML content when Lightning Web Security is enabled in your org. This sanitization allows safe HTML tags and removes other dangerous elements and attributes.
When you disable sanitization in your org, aura:unescapedHTML renders all HTML content without modification, including tags that sanitization normally removes for security reasons.
Disabling sanitization can expose your org to cross-site scripting (XSS) vulnerabilities if you render untrusted content. Only disable sanitization if you have a specific requirement and understand the security implications.
To disable sanitization when you use aura:unescapedHTML:
- From Setup, enter
Sessionin the Quick Find box, and then select Session Settings. - In the Lightning Web Security section, select the Disable sanitization in aura:unescapedHtml component option.
- Save your changes.
When sanitization is enabled (default), aura:unescapedHTML removes unsafe elements and attributes.
When you disable sanitization, certain attack vectors become possible and can potentially expose your org to XSS vulnerabilities. Content Security Policy (CSP) provides some protection but it isn’t sufficient to prevent all XSS attacks.
- Scripts that run directly in
scripttags - Scripts that are embedded in iframe
srcdocattributes - Base64-encoded scripts in
iframedata URIs - Blob URLs that contain runnable JavaScript
- Image error handlers that run when images fail to load
- SVG
onloadevents that fire when SVG elements render - Input
onfocusevents that fire automatically withautofocus - Mouse events that trigger when users hover over elements
- Details elements with
toggleevents that fire when disclosure widgets are opened - Video and audio error handlers that run when media fails to load
- Marquee
onstartevents that fire when animations begin
- Anchor tags that use the
javascript:protocol inhrefattributes - Iframes that use the
javascript:protocol insrcattributes - Object elements that use the
javascript:protocol indata-*attributes - Meta elements with the
http-equivtag set torefreshand redirect tojavascript:URLs
- Iframe
onloadevents that run in the parent context when frames load - Nested iframes that attempt to bypass simple content filters
- Iframe target injection where named iframes are targets
- SVG elements with event handlers that are embedded inside iframes
- Style tags that attempt to run JavaScript through URL expressions
- Hidden iframes that use CSS to conceal malicious content from users
- HTML entity encoding that obfuscates
javascript:protocols and bypasses detection - Polyglot or malformed tags that browsers attempt to fix during parsing
- XML or XSLT content that embeds scripts via stylesheets
- PostMessage injection that uses cross-frame communication to run code
These attack vectors are blocked when sanitization is enabled. Disabling sanitization makes your application vulnerable to XSS attacks if your component renders untrusted content.
Consider disabling sanitization only when:
- You want to render complex HTML that includes interactive elements or embedded scripts
- The HTML content comes from trusted sources that you fully control
- You have implemented security measures to validate and sanitize content before rendering
- Your use case requires functionality that’s blocked by sanitization
See Also