Skip to content

Commit

Permalink
fix: Added clobbering check for sanitizeAttribute to prevent an error
Browse files Browse the repository at this point in the history
  • Loading branch information
cure53 committed Dec 7, 2024
1 parent c183cd6 commit 9c71e04
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 50 deletions.
18 changes: 7 additions & 11 deletions dist/purify.cjs.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/purify.cjs.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 7 additions & 11 deletions dist/purify.es.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,7 +1031,7 @@ function createDOMPurify() {
attributes
} = currentNode;
/* Check if we have attributes; if not we might have a text node */
if (!attributes) {
if (!attributes || _isClobbered(currentNode)) {
return;
}
const hookEvent = {
Expand Down Expand Up @@ -1147,12 +1147,10 @@ function createDOMPurify() {
while (shadowNode = shadowIterator.nextNode()) {
/* Execute a hook if present */
_executeHooks(hooks.uponSanitizeShadowNode, shadowNode, null);
/* Check attributes first */
_sanitizeAttributes(shadowNode);
/* Sanitize tags and elements */
if (_sanitizeElements(shadowNode)) {
continue;
}
_sanitizeElements(shadowNode);
/* Check attributes next */
_sanitizeAttributes(shadowNode);
/* Deep shadow DOM detected */
if (shadowNode.content instanceof DocumentFragment) {
_sanitizeShadowDOM(shadowNode.content);
Expand Down Expand Up @@ -1244,12 +1242,10 @@ function createDOMPurify() {
const nodeIterator = _createNodeIterator(IN_PLACE ? dirty : body);
/* Now start iterating over the created document */
while (currentNode = nodeIterator.nextNode()) {
/* Check attributes first */
_sanitizeAttributes(currentNode);
/* Sanitize tags and elements */
if (_sanitizeElements(currentNode)) {
continue;
}
_sanitizeElements(currentNode);
/* Check attributes next */
_sanitizeAttributes(currentNode);
/* Shadow DOM detected, sanitize it */
if (currentNode.content instanceof DocumentFragment) {
_sanitizeShadowDOM(currentNode.content);
Expand Down
2 changes: 1 addition & 1 deletion dist/purify.es.mjs.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 7 additions & 11 deletions dist/purify.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/purify.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/purify.min.js

Large diffs are not rendered by default.

22 changes: 9 additions & 13 deletions src/purify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1273,7 +1273,7 @@ function createDOMPurify(window: WindowLike = getGlobal()): DOMPurify {
const { attributes } = currentNode;

/* Check if we have attributes; if not we might have a text node */
if (!attributes) {
if (!attributes || _isClobbered(currentNode)) {
return;
}

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

/* Check attributes first */
_sanitizeAttributes(shadowNode);

/* Sanitize tags and elements */
if (_sanitizeElements(shadowNode)) {
continue;
}
_sanitizeElements(shadowNode);

/* Check attributes next */
_sanitizeAttributes(shadowNode);

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

/* Now start iterating over the created document */
while ((currentNode = nodeIterator.nextNode())) {
/* Check attributes first */
_sanitizeAttributes(currentNode);

/* Sanitize tags and elements */
if (_sanitizeElements(currentNode)) {
continue;
}
_sanitizeElements(currentNode);

/* Check attributes next */
_sanitizeAttributes(currentNode);

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

0 comments on commit 9c71e04

Please sign in to comment.