DOMPurify: `CUSTOM_ELEMENT_HANDLING` bypasses `afterSanitizeElements` for allowed custom elements.
DOMPurify 3.4.11 has a vulnerability involving the CUSTOM_ELEMENT_HANDLING configuration where allowed custom elements bypass the afterSanitizeElements hook. This causes sensitive attributes to be preserved on these custom elements while they are stripped from normal elements. Although DOMPurify itself does not directly allow executable payloads at sanitize time, the preserved attributes can lead to second-order XSS when re-injected into HTML sinks later. The issue arises from early return logic in the sanitization flow that skips further sanitization steps for allowed custom elements. This vulnerability is fixed in versions 3.4.12 and later.
AI Analysis
Technical Summary
The vulnerability in DOMPurify 3.4.11 stems from an inconsistency in the sanitization hook policy related to CUSTOM_ELEMENT_HANDLING. When a custom element is allowed via the tagNameCheck configuration, the sanitization function _sanitizeDisallowedNode returns early, skipping the afterSanitizeElements hook and other sanitization checks such as namespace validation and fallback-tag mXSS checks. This results in sensitive attributes not being removed from allowed custom elements, unlike normal elements. While the sanitized attribute values remain inert initially, they can become exploitable if the custom element later injects these values into an HTML sink like innerHTML, enabling a second-order XSS vector. The flaw is due to control flow that bypasses critical sanitization steps for allowed custom elements. The affected versions are all prior to 3.4.12.
Potential Impact
Sensitive attributes that would normally be stripped from elements during sanitization are preserved on allowed custom elements due to the bypass of the afterSanitizeElements hook. This preservation does not directly enable immediate XSS at sanitize time, but it creates a second-order XSS risk if the custom element later injects these attributes into an HTML sink such as innerHTML. The vulnerability thus weakens the security guarantees of DOMPurify in applications relying on afterSanitizeElements to enforce attribute removal on all elements, potentially leading to client-side code injection.
Mitigation Recommendations
A fix is available in DOMPurify version 3.4.12 and later. Users should upgrade to version 3.4.12 or newer to ensure that the afterSanitizeElements hook and other sanitization checks are properly applied to allowed custom elements. Until upgraded, applications should be cautious about relying solely on afterSanitizeElements for security policy enforcement on custom elements. No vendor advisory indicates that no action is required or that the issue is otherwise mitigated.
DOMPurify: `CUSTOM_ELEMENT_HANDLING` bypasses `afterSanitizeElements` for allowed custom elements.
Description
DOMPurify 3.4.11 has a vulnerability involving the CUSTOM_ELEMENT_HANDLING configuration where allowed custom elements bypass the afterSanitizeElements hook. This causes sensitive attributes to be preserved on these custom elements while they are stripped from normal elements. Although DOMPurify itself does not directly allow executable payloads at sanitize time, the preserved attributes can lead to second-order XSS when re-injected into HTML sinks later. The issue arises from early return logic in the sanitization flow that skips further sanitization steps for allowed custom elements. This vulnerability is fixed in versions 3.4.12 and later.
CVSS v4.0
Affected software
Run on your own infrastructure? Check whether these packages are installed with threat-finder — our free open-source scanner.
AI-Powered Analysis
Machine-generated threat intelligence
Technical Analysis
The vulnerability in DOMPurify 3.4.11 stems from an inconsistency in the sanitization hook policy related to CUSTOM_ELEMENT_HANDLING. When a custom element is allowed via the tagNameCheck configuration, the sanitization function _sanitizeDisallowedNode returns early, skipping the afterSanitizeElements hook and other sanitization checks such as namespace validation and fallback-tag mXSS checks. This results in sensitive attributes not being removed from allowed custom elements, unlike normal elements. While the sanitized attribute values remain inert initially, they can become exploitable if the custom element later injects these values into an HTML sink like innerHTML, enabling a second-order XSS vector. The flaw is due to control flow that bypasses critical sanitization steps for allowed custom elements. The affected versions are all prior to 3.4.12.
Potential Impact
Sensitive attributes that would normally be stripped from elements during sanitization are preserved on allowed custom elements due to the bypass of the afterSanitizeElements hook. This preservation does not directly enable immediate XSS at sanitize time, but it creates a second-order XSS risk if the custom element later injects these attributes into an HTML sink such as innerHTML. The vulnerability thus weakens the security guarantees of DOMPurify in applications relying on afterSanitizeElements to enforce attribute removal on all elements, potentially leading to client-side code injection.
Mitigation Recommendations
A fix is available in DOMPurify version 3.4.12 and later. Users should upgrade to version 3.4.12 or newer to ensure that the afterSanitizeElements hook and other sanitization checks are properly applied to allowed custom elements. Until upgraded, applications should be cautious about relying solely on afterSanitizeElements for security policy enforcement on custom elements. No vendor advisory indicates that no action is required or that the issue is otherwise mitigated.
Technical Details
- Gcve Source
- db.gcve.eu
- Osv Id
- GHSA-c2j3-45gr-mqc4
- Osv Schema Version
- 1.4.0
- Aliases
- []
- Ecosystems
- ["npm"]
- Database Specific Severity
- LOW
- Cvss Version
- 4.0
Threat ID: 6a600ac39c2644c7f8fe33be
Added to database: 07/22/2026, 00:11:47 UTC
Last enriched: 07/22/2026, 00:56:04 UTC
Last updated: 07/22/2026, 01:35:57 UTC
Views: 4
Community Reviews
0 reviewsCrowdsource mitigation strategies, share intel context, and vote on the most helpful responses. Sign in to add your voice and help keep defenders ahead.
Want to contribute mitigation steps or threat intel context? Sign in or create an account to join the community discussion.
Actions
Updates to AI analysis require Pro Console access. Upgrade inside Console → Billing.
Need more coverage?
Upgrade to Pro Console for AI refresh and higher limits.
For incident response and remediation, OffSeq services can help resolve threats faster.
Latest Threats
Check if your credentials are on the dark web
Instant breach scanning across billions of leaked records. Free tier available.