Skip to content

Commit 9c71e04

Browse files
committed
fix: Added clobbering check for sanitizeAttribute to prevent an error
1 parent c183cd6 commit 9c71e04

8 files changed

+34
-50
lines changed

dist/purify.cjs.js

+7-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.cjs.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.es.mjs

+7-11
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ function createDOMPurify() {
10311031
attributes
10321032
} = currentNode;
10331033
/* Check if we have attributes; if not we might have a text node */
1034-
if (!attributes) {
1034+
if (!attributes || _isClobbered(currentNode)) {
10351035
return;
10361036
}
10371037
const hookEvent = {
@@ -1147,12 +1147,10 @@ function createDOMPurify() {
11471147
while (shadowNode = shadowIterator.nextNode()) {
11481148
/* Execute a hook if present */
11491149
_executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
1150-
/* Check attributes first */
1151-
_sanitizeAttributes(shadowNode);
11521150
/* Sanitize tags and elements */
1153-
if (_sanitizeElements(shadowNode)) {
1154-
continue;
1155-
}
1151+
_sanitizeElements(shadowNode);
1152+
/* Check attributes next */
1153+
_sanitizeAttributes(shadowNode);
11561154
/* Deep shadow DOM detected */
11571155
if (shadowNode.content instanceof DocumentFragment) {
11581156
_sanitizeShadowDOM(shadowNode.content);
@@ -1244,12 +1242,10 @@ function createDOMPurify() {
12441242
const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
12451243
/* Now start iterating over the created document */
12461244
while (currentNode = nodeIterator.nextNode()) {
1247-
/* Check attributes first */
1248-
_sanitizeAttributes(currentNode);
12491245
/* Sanitize tags and elements */
1250-
if (_sanitizeElements(currentNode)) {
1251-
continue;
1252-
}
1246+
_sanitizeElements(currentNode);
1247+
/* Check attributes next */
1248+
_sanitizeAttributes(currentNode);
12531249
/* Shadow DOM detected, sanitize it */
12541250
if (currentNode.content instanceof DocumentFragment) {
12551251
_sanitizeShadowDOM(currentNode.content);

dist/purify.es.mjs.map

+1-1
Original file line numberDiff line numberDiff line change

dist/purify.js

+7-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/purify.ts

+9-13
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ function createDOMPurify(window: WindowLike = getGlobal()): DOMPurify {
12731273
const { attributes } = currentNode;
12741274

12751275
/* Check if we have attributes; if not we might have a text node */
1276-
if (!attributes) {
1276+
if (!attributes || _isClobbered(currentNode)) {
12771277
return;
12781278
}
12791279

@@ -1415,13 +1415,11 @@ function createDOMPurify(window: WindowLike = getGlobal()): DOMPurify {
14151415
/* Execute a hook if present */
14161416
_executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
14171417

1418-
/* Check attributes first */
1419-
_sanitizeAttributes(shadowNode);
1420-
14211418
/* Sanitize tags and elements */
1422-
if (_sanitizeElements(shadowNode)) {
1423-
continue;
1424-
}
1419+
_sanitizeElements(shadowNode);
1420+
1421+
/* Check attributes next */
1422+
_sanitizeAttributes(shadowNode);
14251423

14261424
/* Deep shadow DOM detected */
14271425
if (shadowNode.content instanceof DocumentFragment) {
@@ -1537,13 +1535,11 @@ function createDOMPurify(window: WindowLike = getGlobal()): DOMPurify {
15371535

15381536
/* Now start iterating over the created document */
15391537
while ((currentNode = nodeIterator.nextNode())) {
1540-
/* Check attributes first */
1541-
_sanitizeAttributes(currentNode);
1542-
15431538
/* Sanitize tags and elements */
1544-
if (_sanitizeElements(currentNode)) {
1545-
continue;
1546-
}
1539+
_sanitizeElements(currentNode);
1540+
1541+
/* Check attributes next */
1542+
_sanitizeAttributes(currentNode);
15471543

15481544
/* Shadow DOM detected, sanitize it */
15491545
if (currentNode.content instanceof DocumentFragment) {

0 commit comments

Comments
 (0)