Skip to content

Commit

Permalink
fix: Fixed an unintended bypass when *-* is allowed for CEs, thanks @…
Browse files Browse the repository at this point in the history
  • Loading branch information
cure53 committed Feb 12, 2024
1 parent cb18519 commit 5ca0879
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion 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.

2 changes: 1 addition & 1 deletion dist/purify.es.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1088,7 +1088,7 @@ function createDOMPurify() {
* @returns {boolean} Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
*/
const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
return tagName.indexOf('-') > 0;
return tagName !== 'annotation-xml' && tagName.indexOf('-') > 0;
};

/**
Expand Down
2 changes: 1 addition & 1 deletion dist/purify.es.mjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion 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.

2 changes: 1 addition & 1 deletion src/purify.js
Original file line number Diff line number Diff line change
Expand Up @@ -1194,7 +1194,7 @@ function createDOMPurify(window = getGlobal()) {
* @returns {boolean} Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
*/
const _isBasicCustomElement = function (tagName) {
return tagName.indexOf('-') > 0;
return tagName !== 'annotation-xml' && tagName.indexOf('-') > 0;
};

/**
Expand Down
11 changes: 11 additions & 0 deletions test/test-suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -2093,5 +2093,16 @@
// cleanup hook
DOMPurify.removeHook(entryPoint);
});

QUnit.test('Test proper removal of annotation-xml w. custom elements', function (assert) {
const dirty = '<svg><annotation-xml><foreignobject><style><!--</style><p id="--><img src=\'x\' onerror=\'alert(1)\'>">';
const config = {
CUSTOM_ELEMENT_HANDLING: { tagNameCheck: /.*/ },
FORBID_CONTENTS: [""]
};
const expected = '<svg></svg>';
let clean = DOMPurify.sanitize(dirty, config);
assert.contains(clean, expected);
});
};
});

0 comments on commit 5ca0879

Please sign in to comment.