DangerousHtml
A block to render HTML with the ability to customize the DOMPurify's options.
The DangerousHtml block sanitizes HTML using DOMPurify's with the ability to customize the sanitization options. This comes with some security considerations, please consider DOMPurify's Security Goals and Threat Model for more details regarding the security impact of using the DangerousHtml block.
In short, it is strongly advised to never render any user input DangerousHtml content, only render hardcoded or trusted HTML content.
Block
Block Setup
id: block_id
type: DangerousHtml
properties:
html: <a href="https://lowdefy.com">Lowdefy Website</a>
Settings
Examples
Basic DangerousHtml
A simple white title box
id: basic_example
type: DangerousHtml
properties:
html: >
<div style="background: #123456; padding: 10px;"><h1 style="color: white;">A
simple white title box</h1></div>
DangerousHtml with iframes sanitized
The iframe was removed: - title: DangerousHtml with iframes enabled
id: sanitized_iframes_example
type: DangerousHtml
properties:
html: >
The iframe was removed: <iframe style="max-width: 512px;" width="100%"
src="https://www.youtube.com/embed/7N7GWdlQJlU" frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope;
picture-in-picture" allowfullscreen></iframe> - title: DangerousHtml
with iframes enabled
DangerousHtml with iframes not sanitized
The iframe was not removed:
id: iframes_example
type: DangerousHtml
properties:
DOMPurifyOptions:
ADD_TAGS:
- iframe
html: >
The iframe was not removed: <iframe style="max-width: 512px;" width="100%"
src="https://www.youtube.com/embed/7N7GWdlQJlU" frameborder="0"
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope;
picture-in-picture" allowfullscreen></iframe>
DangerousHtml basic sanitization
id: sanitized_example
type: DangerousHtml
properties:
html: >
<div style="color: red; border: 2px dashed blue; padding:
10px;"><script>alert("hello world")</script><img src=x onerror=alert("img")
/>A little bit of bad html sanitized.</div>
DangerousHtml JSON Schema Definition
type: object
properties:
properties:
additionalProperties: false
properties:
DOMPurifyOptions:
description: >-
Customize DOMPurify options. Options are only applied when the block is
mounted, thus any parsed settings is only applied at first render.
type: object
html:
description: Content to be rendered as Html.
type: string
style:
description: Css style object to apply to Html div.
type: object
type: object