Skip to content

Commit

Permalink
fix: Added changes to 2.x regarding attribute value checks
Browse files Browse the repository at this point in the history
  • Loading branch information
cure53 committed Jun 25, 2024
1 parent 9a7cd98 commit 38e8410
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 29 deletions.
13 changes: 7 additions & 6 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

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions dist/purify.es.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.es.js.map

Large diffs are not rendered by default.

13 changes: 7 additions & 6 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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

13 changes: 7 additions & 6 deletions src/purify.js
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,13 @@ function createDOMPurify(window = getGlobal()) {
hookEvent.forceKeepAttr = undefined; // Allows developers to see this is a property they can set
_executeHook('uponSanitizeAttribute', currentNode, hookEvent);
value = hookEvent.attrValue;

/* Work around a security issue with comments inside attributes */
if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title)/i, value)) {
_removeAttribute(name, currentNode);
continue;
}

/* Did the hooks approve of the attribute? */
if (hookEvent.forceKeepAttr) {
continue;
Expand All @@ -1278,12 +1285,6 @@ function createDOMPurify(window = getGlobal()) {
continue;
}

/* Work around a security issue with comments inside attributes */
if (SAFE_FOR_XML && regExpTest(/((--!?|])>)|<\/(style|title)/i, value)) {
_removeAttribute(name, currentNode);
continue;
}

/* Sanitize attribute content to be template-safe */
if (SAFE_FOR_TEMPLATES) {
value = stringReplace(value, MUSTACHE_EXPR, ' ');
Expand Down

0 comments on commit 38e8410

Please sign in to comment.