Package: node-dompurify
Version: 2.4.1+dfsg+~2.4.0-2+deb12u1
Severity: grave
Justification: renders package unusable
X-Debbugs-Cc: [email protected]
Dear Maintainer,
The security update 2.4.1+dfsg+~2.4.0-2+deb12u1 (bookworm, "Fix prototype
pollutions (Closes: CVE-2024-45801, CVE-2024-48910)") introduced a
regression that makes DOMPurify.sanitize() throw on any input containing
markup.
The previous version, 2.4.1+dfsg+~2.4.0-2, sanitizes the same inputs
correctly.
Reproduction
------------
# apt install node-dompurify node-jsdom
$ node -e '
const { JSDOM } = require("jsdom");
const DOMPurify =
require("/usr/share/nodejs/dompurify/dist/purify.cjs.js")(new
JSDOM("").window);
console.log(DOMPurify.sanitize("<b>hello</b>"));
'
Expected: <b>hello</b>
Actual: ReferenceError: shadowNode is not defined
at .../dompurify/dist/purify.cjs.js:1358
Every input with markup throws (<b>hello</b>, <div><p>x</p></div>,
<img src=x onerror=...>, an HTML comment). Only markup-free plain text
survives, because sanitize() returns before the faulty line is reached.
dist/purify.min.js is affected identically.
Root cause
----------
debian/patches/CVE-2024-45801.patch backports upstream commit 26e1d69.
Upstream adds a numberIsNaN() guard to two existing "nested too deeply"
depth checks: one on `shadowNode` inside the function _sanitizeShadowDOM(),
and one on `currentNode` inside DOMPurify.sanitize(). In the 2.4.x source
the second hunk landed in the wrong function. It matched on the
`_forceRemove(body.firstChild)` context in sanitize() and replaced the
FORCE_BODY block there with the shadowNode check:
@@ -1484,8 +1485,14 @@
- /* Remove first element node (ours) if FORCE_BODY is set */
- if (body && FORCE_BODY) {
+ /*
+ * Remove an element if nested too deeply to avoid mXSS
+ * or if the __depth might have been tampered with
+ */
+ if (
+ shadowNode.__depth >= MAX_NESTING_DEPTH ||
+ numberIsNaN(shadowNode.__depth)
+ ) {
_forceRemove(body.firstChild);
}
`shadowNode` is a local variable declared only in _sanitizeShadowDOM(), so
in sanitize() it is undefined and the reference throws. In the built bundle:
_sanitizeShadowDOM() var shadowNode;
dist/purify.cjs.js:1208
DOMPurify.sanitize() function (dirty) {
dist/purify.cjs.js:1262
the faulty line if (shadowNode.__depth >= ...)
dist/purify.cjs.js:1358
Three consequences of the mislocation:
1. sanitize() throws on all markup (shadowNode out of scope);
2. the FORCE_BODY handling in sanitize() is deleted;
3. the depth check this hunk was meant for -- the real one in
_sanitizeShadowDOM() at dist/purify.cjs.js:1236,
`if (shadowNode.__depth >= MAX_NESTING_DEPTH)` -- was never upgraded
with
the numberIsNaN() guard, so CVE-2024-45801 is not actually fixed on the
shadow-DOM path.
The patch's other two hunks (the numberIsNaN import, and the `currentNode`
guard in sanitize()) are applied correctly.
Impact
------
node-dompurify is a sanitiser; in this build it is unusable for its
purpose. A consumer that does not wrap sanitize() in a try/catch crashes;
one that does catch fails closed (no sanitised output). Either way the
package does not do its job, and the CVE-2024-45801 fix is incomplete.
Suggested fix
-------------
Rework CVE-2024-45801.patch so the shadowNode guard is applied to the
existing check in _sanitizeShadowDOM() (the `if (shadowNode.__depth >=
MAX_NESTING_DEPTH)` line) rather than to the FORCE_BODY block in
sanitize(), and restore the FORCE_BODY block. The currentNode hunk needs no
change. Equivalent to carrying upstream 2.5.1 commit 26e1d69 onto the 2.4.x
tree at the correct anchors.
Affected: bookworm, 2.4.1+dfsg+~2.4.0-2+deb12u1 (the highest 2.x version, so
the one `apt` installs).
Not affected: 2.4.1+dfsg+~2.4.0-2 (in bookworm-security, but
lower-versioned);
trixie/sid on the 3.x line.
Thanks,
Oreofe.