When adding the style tag to the whitelist, content inside the tag is incorrectly unescaped, and closing tags injected as content are interpreted as real HTML, enabling tag injection and JavaScript execution.
This behavior is similar to the sanitization bypass described in CVE-2020-4054 (Sanitize for Ruby).
using HTMLSanitizer
user_input = "<svg><style></style><img src onerror=alert(1)>"
whitelist = deepcopy(HTMLSanitizer.WHITELIST)
append!(whitelist[:elements], ["style"])
result = sanitize(user_input, whitelist=whitelist)
print(result) # <style></style><img src onerror=alert(1)></style>
Possible XSS in any HTML that is sanitized with this library.
Users should upgrade to v0.2.1 as soon as possible. In this version, svg and math tags are removed by default.
Add the math and svg elements to your whitelist manually via e.g.
whitelist = deepcopy(HTMLSanitizer.WHITELIST)
append!(whitelist[:removed_elements], ["math", "svg"])
and pass this modified whitelist to sanitize:
sanitize(user_input, whitelist=whitelist)
Thanks to Chen T for finding and reporting this issue.
{
"license": "CC-BY-4.0",
"sources": [
{
"published": "2025-06-23T13:44:51Z",
"url": "https://api.github.com/repos/JuliaComputing/HTMLSanitizer.jl/security-advisories/GHSA-3mj7-qxh9-6q4p",
"modified": "2025-06-23T13:45:18Z",
"html_url": "https://github.com/JuliaComputing/HTMLSanitizer.jl/security/advisories/GHSA-3mj7-qxh9-6q4p",
"id": "GHSA-3mj7-qxh9-6q4p",
"imported": "2025-10-14T02:21:59.106Z"
}
]
}