CVE-2026-65902: DOMPurify before 3.4.7 Hook Mutation Pollution via allowedTags

Published Jun 15, 2026
·
Updated

Hook mutation of data.allowedTags / data.allowedAttributes permanently pollutes DEFAULTALLOWEDTAGS / DEFAULTALLOWEDATTR

CWE: CWE-501 (Trust Boundary Violation — hook-scoped mutation leaks to global default sets) via CWE-693 (Protection Mechanism Failure — the default allow-list is silently widened for all subsequent sanitize calls)

Summary

The data.allowedTags and data.allowedAttributes fields passed to uponSanitizeElement and uponSanitizeAttribute hooks are direct references to the library's live ALLOWEDTAGS / ALLOWEDATTR sets. For sanitize calls that don't supply an explicit cfg.ALLOWEDTAGS / cfg.ALLOWEDATTR array, those live sets are themselves direct references to the module-level DEFAULTALLOWEDTAGS / DEFAULTALLOWEDATTR constants. A hook that mutates these fields — a natural-looking pattern for "allow X for this iteration" — permanently writes new entries into the default constants for the DOMPurify instance's lifetime. Every subsequent sanitize call that doesn't override the config inherits the widened defaults, so an attacker payload that uses the poisoned tag/attribute name survives sanitization. removeAllHooks(), clearConfig(), and even passing a fresh cfg: {} do not recover; only constructing a new DOMPurify instance does.

The maintainer's existing defense at src/purify.ts:696-700 explicitly clones DEFAULTALLOWEDTAGS before mutating it via cfg.ADDTAGS (array form), demonstrating awareness of this exact class. The hook path remained uncovered.

Affected

- DOMPurify ≤ 3.4.5, including main at 7996f1dc78eb8b7922388aed75d94a9f8fad9a36 - Any application that installs a hook on uponSanitizeElement or uponSanitizeAttribute that writes to data.allowedTags[...] = true or data.allowedAttributes[...] = true and later sanitizes attacker-influenced content with default config (no explicit cfg.ALLOWEDTAGS / cfg.ALLOWEDATTR array)

Vulnerability details

[A] — data.allowedTags is a reference to ALLOWEDTAGS

src/purify.ts:1206-1209:

ts executeHooks(hooks.uponSanitizeElement, currentNode, { tagName, allowedTags: ALLOWEDTAGS, // [A] direct reference; hook mutation // mutates the very ALLOWEDTAGS the // library checks on the next element });

src/purify.ts:1494-1500 (the matching attribute hook):

ts const hookEvent = { attrName: '', attrValue: '', keepAttr: true, allowedAttributes: ALLOWEDATTR, // [A'] same pattern forceKeepAttr: undefined, };

[B] — ALLOWEDTAGS = DEFAULTALLOWEDTAGS for default-cfg sanitize calls

src/purify.ts:527-531:

ts ALLOWEDTAGS = objectHasOwnProperty(cfg, 'ALLOWEDTAGS') && arrayIsArray(cfg.ALLOWEDTAGS) ? addToSet({}, cfg.ALLOWEDTAGS, transformCaseFunc) : DEFAULTALLOWEDTAGS; // [B] reference assignment; ALLOWEDTAGS // IS the DEFAULTALLOWEDTAGS object

(The ALLOWEDATTR = DEFAULTALLOWEDATTR path at :532-536 is symmetric.)

The mismatch

A hook author who writes data.allowedTags['script'] = true reasonably expects per-call scope — the API name is "data", suggesting per-event payload. But [A] makes this a direct reference, and [B] makes that reference equal to the module-level default for the common default-cfg path. The hook's mutation therefore writes to a constant that every subsequent default-cfg sanitize call rebinds to.

The maintainer already recognized this class for the ADDTAGS array path — src/purify.ts:696-700:

ts } else if (arrayIsArray(cfg.ADDTAGS)) { if (ALLOWEDTAGS === DEFAULTALLOWEDTAGS) { ALLOWEDTAGS = clone(ALLOWEDTAGS); // explicitly clone DEFAULT before // mutating to avoid this pollution } addToSet(ALLOWEDTAGS, cfg.ADDTAGS, transformCaseFunc); }

The same defensive clone is missing from the hook code paths.

Proof of concept

js // 1) fresh DOMPurify, default config — script is blocked DOMPurify.sanitize('<svg><script>alert(1)</script></svg>'); // → "<svg></svg>"

// 2) install a hook that mutates data.allowedTags (natural-looking pattern) DOMPurify.addHook('uponSanitizeElement', (node, data) => { data.allowedTags['script'] = true; });

// 3) one sanitize call WITH the hook — script survives (expected during the hook) DOMPurify.sanitize('<svg><script>alert(1)</script></svg>'); // → "<svg><script>alert(1)</script></svg>"

// 4) remove the hook DOMPurify.removeAllHooks(); DOMPurify.clearConfig();

// 5) sanitize attacker content with default config — POLLUTION PERSISTS DOMPurify.sanitize('<svg><script>alert(1)</script></svg>'); // → "<svg><script>alert(1)</script></svg>" ← script survived without any hook

// 6) the only recovery: create a fresh DOMPurify instance const fresh = DOMPurify(window); fresh.sanitize('<svg><script>alert(1)</script></svg>'); // → "<svg></svg>" ← clean

Observed (Chromium 148.0.7778.96, DOMPurify HEAD 7996f1d):

| step | input | output | bypass? | |---|---|---|---| | 1 fresh baseline | <svg><script></script></svg> | <svg></svg> | no | | 1b fresh baseline | <a onclick=>x</a> | <a>x</a> | no | | 2 with hook (script) | <svg><script></script></svg> | <svg><script></script></svg> | yes (expected) | | 2b with hook (onclick) | <a onclick=>x</a> | <a onclick="">x</a> | yes (expected) | | 3 after removeAllHooks() | same | <svg><script></script></svg> | YES (pollution) | | 3b after removeAllHooks() | same | <a onclick="">x</a> | YES (pollution) | | 4 after clearConfig() | same | <svg><script></script></svg> | YES | | 4b after clearConfig() | same | <a onclick="">x</a> | YES | | 5 explicit restrictive cfg.ALLOWEDTAGS=['svg'] | same | <svg></svg> | no (cloned set) | | 6 back to no cfg | same | <svg><script></script></svg> | YES | | 6b back to no cfg | same | <a onclick="">x</a> | YES | | 7 fresh DOMPurify(window) instance | same | <svg></svg> | no | | 7b fresh instance | <a onclick=>x</a> | <a>x</a> | no |

Impact

Direct

Any application using DOMPurify that has any registered hook with the pattern data.allowedTags[...] = true or data.allowedAttributes[...] = true. The hook need not be designed to be permissive — it might be intended to temporarily allow a custom tag for one specific element shape. After the hook has executed even once, every subsequent default-config sanitize call carries the widened defaults, including:

- attacker content rendered via separate code paths (e.g., the same library serving a comments section and a profile bio, where the bio uses the hook and the comments use plain DOMPurify.sanitize(text)) - third-party libraries that call DOMPurify.sanitize on the same instance

The bypass survives DOMPurify.removeAllHooks() and DOMPurify.clearConfig() — the obvious "reset" calls a dev would reach for. Detection requires reading the DEFAULTALLOWEDTAGS / DEFAULTALLOWEDATTR sets directly, which are not part of the public API.

Indirect / second-order

- Editor / preview libraries that compose with DOMPurify — if any consumer registers a hook that mutates data.allowedTags, every other consumer's sanitize calls inherit the widening. - Test suites that exercise multiple sanitize configurations — once a test's hook pollutes the defaults, later tests that assume default behavior may pass with widened defaults and miss real regressions. - Long-running servers (SSR, edge functions) that reuse a single DOMPurify instance — pollution accumulates over the process lifetime.

Why the existing maintainer defense for ADDTAGS doesn't catch this

src/purify.ts:696-700 already documents awareness:

ts } else if (arrayIsArray(cfg.ADDTAGS)) { if (ALLOWEDTAGS === DEFAULTALLOWEDTAGS) { ALLOWEDTAGS = clone(ALLOWEDTAGS); } addToSet(ALLOWEDTAGS, cfg.ADDTAGS, transformCaseFunc); }

The clone-before-mutate pattern is exactly what's needed at the hook callsites (:1206-1209 and :1494-1500) but was not extended there. The new entries this report's bypass adds to the defaults survive the same way ADDTAGS array entries would have survived before that fix landed.

Suggested fix

Three minimal-impact options, in order of preference:

1. Hand the hook a defensive copy (most surgical):

ts executeHooks(hooks.uponSanitizeElement, currentNode, { tagName, allowedTags: { ...ALLOWEDTAGS }, // shallow copy; mutations stay scoped });

Doc note: "data.allowedTags is a snapshot; to widen the live set, use cfg.ADDTAGS or set the value to true in the snapshot and check the snapshot from a subsequent attribute hook." Hooks that read it for inspection still work; hooks that intended cross-call mutation must be rewritten to use a proper config path (which is the correct API anyway).

2. Clone-on-write inside the hook path, mirroring the existing ADDTAGS defense at :696-700: detect that ALLOWEDTAGS === DEFAULTALLOWEDTAGS after the hook returns, and if so, replace it with a clone for subsequent processing. This preserves the live-mutation semantics for in-call effects while preventing cross-call leakage.

3. Lazy-clone ALLOWEDTAGS/ALLOWEDATTR from defaults on first mutation: install a Proxy or accessor that triggers a clone before mutation. Largest surface area, but bulletproof.

Option (1) is the cleanest API contract: hook event objects should be event-local, never references to library-internal state.

Other sources

DOMPurify before 3.4.7 (affected versions <= 3.4.5) passes direct references to the module-level DEFAULTALLOWEDTAGS and DEFAULTALLOWEDATTR sets to the uponSanitizeElement and uponSanitizeAttribute hooks via data.allowedTags / data.allowedAttributes when sanitize is called without an explicit cfg.ALLOWEDTAGS / cfg.ALLOWEDATTR array. A hook that mutates these fields permanently widens the default allow-lists for the lifetime of the DOMPurify instance, so all subsequent default-config sanitize calls inherit the widened defaults and attacker payloads using the poisoned tag/attribute name survive sanitization. removeAllHooks(), clearConfig(), and passing a fresh cfg do not recover the state; only constructing a new DOMPurify instance does.

— Red Hat

DOMPurify before 3.4.7 passes direct references to the module-level DEFAULTALLOWEDTAGS and DEFAULTALLOWEDATTR sets to the uponSanitizeElement and uponSanitizeAttribute hooks via data.allowedTags / data.allowedAttributes when sanitize is called without an explicit cfg.ALLOWEDTAGS / cfg.ALLOWEDATTR array. A hook that mutates these fields permanently widens the default allow-lists for the lifetime of the DOMPurify instance, so all subsequent default-config sanitize calls inherit the widened defaults and attacker payloads using the poisoned tag/attribute name survive sanitization. removeAllHooks(), clearConfig(), and passing a fresh cfg do not recover the state; only constructing a new DOMPurify instance does.

— NVD

Affected Software

10 affected componentsFixes available
DOMPurify DOMPurify<=3.4.5
Cure53 DOMPurify<3.4.7
debian/node-dompurify*
debian/node-dompurify*
debian/node-dompurify<3.4.12+dfsg-1
3.4.12+dfsg-1
npm/dompurify<3.4.7
3.4.7
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 debian/node-dompurify to a version that resolves this vulnerability.

    Fixed in 3.4.12+dfsg-1
  2. Upgrade

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

    Fixed in 3.4.7
  3. Upgrade

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

    Fixed in 3.4.7
  4. Operational

    After an instance has been polluted, construct a fresh DOMPurify instance; removeAllHooks() and clearConfig() do not restore the default allow-lists.

Event History

Jun 15, 2026
Advisory Published
via GitHub·07:59 PM
Data Sourced
via GitHub·07:59 PM
DescriptionSeverityWeaknessAffected Software
Jul 23, 2026
CVE Published
via MITRE·01:16 PM
Data Sourced
via MITRE·01:16 PM
DescriptionSeverityWeakness
Data Sourced
via Red Hat·02:01 PM
DescriptionSeverityAffected Software
Data Sourced
via NVD·02:18 PM
DescriptionSeverityWeakness
Event
via NVD·02:18 PM
Jul 28, 2026
Data Sourced
via NVD·03:51 PM
RemedyAffected Software
Oct 29, 2026
Updated
via MITRE·08:19 PM
Description
Updated
via NVD·09:17 PM
Description
Oct 30, 2026
Updated
via OSV·10:00 AM
Severity
Nov 5, 2026
Data Sourced
via OSV·11:47 AM
Affected Software

Frequently Asked Questions

1

What is the severity of CVE-2026-65902?

The severity of CVE-2026-65902 is rated as medium with a score of 6.1.

2

How do I fix CVE-2026-65902?

To fix CVE-2026-65902, upgrade DOMPurify to version 3.4.7 or later.

3

What products are affected by CVE-2026-65902?

CVE-2026-65902 affects versions of DOMPurify up to and including 3.4.5.

4

What kind of vulnerability is CVE-2026-65902?

CVE-2026-65902 is a Hook Mutation Pollution vulnerability affecting DOMPurify's sanitization process.

5

What should I do if I cannot upgrade to fix CVE-2026-65902?

If you cannot upgrade, consider implementing additional input validation or sanitization measures to mitigate the risk associated with CVE-2026-65902.

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