Headline
GHSA-fw3g-2h3j-qmm7: Improper neutralization of `noscript` element content may allow XSS in Sanitize
Impact
Using carefully crafted input, an attacker may be able to sneak arbitrary HTML through Sanitize >= 5.0.0, < 6.0.1
when Sanitize is configured with a custom allowlist that allows noscript
elements. This could result in XSS (cross-site scripting) or other undesired behavior when that HTML is rendered in a browser.
Sanitize’s default configs don’t allow noscript
elements and are not vulnerable. This issue only affects users who are using a custom config that adds noscript
to the element allowlist.
Patches
Sanitize >= 6.0.1
always removes noscript
elements and their contents, even when noscript
is in the allowlist.
Workarounds
Users who are unable to upgrade can prevent this issue by using one of Sanitize’s default configs or by ensuring that their custom config does not include noscript
in the element allowlist.
Details
The root cause of this issue is that HTML parsing rules treat the contents of a noscript
element differently depending on whether scripting is enabled in the user agent. Nokogiri (the HTML parser Sanitize uses) doesn’t support scripting so it follows the “scripting disabled” rules, but a web browser with scripting enabled will follow the “scripting enabled” rules. This means that Sanitize can’t reliably make the contents of a noscript
element safe for scripting enabled browsers. The safest thing to do is to remove the element and its contents entirely, which is now what Sanitize does in version 6.0.1 and later.
References
Credit
Thanks to David Klein from TU Braunschweig (@leeN) for reporting this issue.
Impact
Using carefully crafted input, an attacker may be able to sneak arbitrary HTML through Sanitize >= 5.0.0, < 6.0.1 when Sanitize is configured with a custom allowlist that allows noscript elements. This could result in XSS (cross-site scripting) or other undesired behavior when that HTML is rendered in a browser.
Sanitize’s default configs don’t allow noscript elements and are not vulnerable. This issue only affects users who are using a custom config that adds noscript to the element allowlist.
Patches
Sanitize >= 6.0.1 always removes noscript elements and their contents, even when noscript is in the allowlist.
Workarounds
Users who are unable to upgrade can prevent this issue by using one of Sanitize’s default configs or by ensuring that their custom config does not include noscript in the element allowlist.
Details
The root cause of this issue is that HTML parsing rules treat the contents of a noscript element differently depending on whether scripting is enabled in the user agent. Nokogiri (the HTML parser Sanitize uses) doesn’t support scripting so it follows the “scripting disabled” rules, but a web browser with scripting enabled will follow the “scripting enabled” rules. This means that Sanitize can’t reliably make the contents of a noscript element safe for scripting enabled browsers. The safest thing to do is to remove the element and its contents entirely, which is now what Sanitize does in version 6.0.1 and later.
References
- Release Notes
Credit
Thanks to David Klein from TU Braunschweig (@leeN) for reporting this issue.
References
- GHSA-fw3g-2h3j-qmm7
- https://nvd.nist.gov/vuln/detail/CVE-2023-23627
- rgrove/sanitize@ec14265
Related news
Ubuntu Security Notice 6748-1 - It was discovered that Sanitize incorrectly handled noscript elements under certain circumstances. An attacker could possibly use this issue to execute a cross-site scripting attack. This issue only affected Ubuntu 22.04 LTS. It was discovered that Sanitize incorrectly handled style elements under certain circumstances. An attacker could possibly use this issue to execute a cross-site scripting attack.
Sanitize is an allowlist-based HTML and CSS sanitizer. Versions 5.0.0 and later, prior to 6.0.1, are vulnerable to Cross-site Scripting. When Sanitize is configured with a custom allowlist that allows `noscript` elements, attackers are able to include arbitrary HTML, resulting in XSS (cross-site scripting) or other undesired behavior when that HTML is rendered in a browser. The default configurations do not allow `noscript` elements and are not vulnerable. This issue only affects users who are using a custom config that adds `noscript` to the element allowlist. This issue has been patched in version 6.0.1. Users who are unable to upgrade can prevent this issue by using one of Sanitize's default configs or by ensuring that their custom config does not include `noscript` in the element allowlist.