Описание
OWASP Java HTML Sanitizer is vulnerable to XSS via noscript tag and improper style tag sanitization
Summary
It is observed that OWASP java html sanitizer is vulnerable to XSS if HtmlPolicyBuilder allows noscript and style tags with allowTextIn inside the style tag. This could lead to XSS if the payload is crafted in such a way that it does not sanitise the CSS and allows tags which is not mentioned in HTML policy.
Details
The OWASP java HTML sanitizer is vulnerable to XSS. This only happens when HtmlPolicyBuilder allows noscript & style tag with allowTextIn inside style tags.
The following condition is very edge case but if users combine a HtmlPolicyBuilder with any other tags except noscript and allow style tag with allowTextIn inside the style tag then In this case sanitizer would be safe from XSS. This happens because how the browser also perceives noscript tags post sanitization.
PoC
- Lets create a
HtmlPolicyBuilderwhich allowsp, noscript, stylehtml tags and allows.allowTextIn("style"). - There are two XSS payloads which very identical and only difference is one has p tag and other has noscript tag. These payload have script tags that could be vulnerable to XSS and should be stripped out after sanitisation.
- Run the following piece of code which sanitizes the payload.
Use the latest library version
- Output of the POC code should look like this
- Lets understand what happened in sanitization process below
- Lets create a sample html page and copy both sanitized output which should be generated in step 5
- Open this HTML page in the browser it should pop an alert.
- Open inspect element to understand what happened. If users look closely a payload combined with p tag and style tag did not cause XSS and browser percived anything after style tag as CSS.
- The payload which combined with noscript tag and style tag did caused XSS.
The broswer perceived noscript and which wrapped
styletag then closed noscript tag and after that script payload is considered as valid HTML tag and it executed in browser and this leads to XSS because this is very different then what happened in the last example with p tag.
Impact
- This potentially could leads to XSS in applications. Ref : https://owasp.org/www-community/attacks/xss/
Ссылки
- https://github.com/OWASP/java-html-sanitizer/security/advisories/GHSA-g9gq-3pfx-2gw2
- https://nvd.nist.gov/vuln/detail/CVE-2025-66021
- https://github.com/OWASP/java-html-sanitizer/issues/363
- https://github.com/OWASP/java-html-sanitizer/commit/4149cf02ba84db13e8e9d7ee1b01b3f47238e072
- https://github.com/OWASP/java-html-sanitizer/commit/b98cdf1cd5e156a6259b01aa8cdc7372c6efde1e
- https://github.com/OWASP/java-html-sanitizer/commit/d6e0463ed3b48777ecd187913ffdbe767508ff45
Пакеты
com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer
= 20240325.1
20260101.1
Связанные уязвимости
OWASP Java HTML Sanitizer is a configureable HTML Sanitizer written in Java, allowing inclusion of HTML authored by third-parties in web applications while protecting against XSS. In version 20240325.1, OWASP java html sanitizer is vulnerable to XSS if HtmlPolicyBuilder allows noscript and style tags with allowTextIn inside the style tag. This could lead to XSS if the payload is crafted in such a way that it does not sanitise the CSS and allows tags which is not mentioned in HTML policy. At time of publication no known patch is available.