html_sanitize
Sanitize HTML by removing dangerous tags, attributes, and scripts using the ammonia crate.
Parameters
- inputstring*
- HTML string (supports
${ctx.key}) - source_keystring*
- Context key containing HTML string
- output_keystringdefault "sanitized_html"
- Key to store sanitized output
- allowed_tagsstring[]default ammonia defaults
- Custom set of allowed HTML tags
- strip_commentsbooldefault true
- Whether to strip HTML comments
- link_relstringdefault "noopener noreferrer"
relattribute for links
*One of input or source_key is required (not both).
Context Output
| Key | Type | Description |
|---|---|---|
{output_key} | string | Sanitized HTML string |
Examples
Basic sanitization
flow:step("sanitize", nodes.html_sanitize({
input = '<h1>Hello</h1><script>alert("xss")</script>',
}))
-- Output: { sanitized_html = "<h1>Hello</h1>" }
Custom allowed tags
flow:step("sanitize", nodes.html_sanitize({
input = '<p><b>bold</b> <custom>tag</custom></p>',
allowed_tags = { "p", "b", "custom" },
}))
From context
flow:step("sanitize", nodes.html_sanitize({
source_key = "raw_html",
output_key = "clean_html",
}))