GHSA-fw3g-2h3j-qmm7
Improper neutralization of `noscript` element content may allow XSS in Sanitize
Quick fix
GHSA-fw3g-2h3j-qmm7 — sanitize: upgrade to the fixed version with the command below.
bundle update sanitizeDetails
### 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](https://github.com/rgrove/sanitize/releases/tag/v6.0.1)
### Credit
Thanks to David Klein from [TU Braunschweig](https://www.tu-braunschweig.de/en/ias) (@leeN) for reporting this issue.
Are you affected?
Enter the version of the package you're using.
Affected packages
References
- https://github.com/rgrove/sanitize/security/advisories/GHSA-fw3g-2h3j-qmm7[WEB]
- https://nvd.nist.gov/vuln/detail/CVE-2023-23627[ADVISORY]
- https://github.com/rgrove/sanitize/commit/ec14265e530dc3fe31ce2ef773594d3a97778d22[WEB]
- https://github.com/rgrove/sanitize[PACKAGE]
- https://github.com/rubysec/ruby-advisory-db/blob/master/gems/sanitize/CVE-2023-23627.yml[WEB]