Skip to content

Commit 5ca0879

Browse files
committedFeb 12, 2024
fix: Fixed an unintended bypass when *-* is allowed for CEs, thanks @kevin-mizu
1 parent cb18519 commit 5ca0879

10 files changed

+20
-9
lines changed
 

‎dist/purify.cjs.js

+1-1
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,7 @@ function createDOMPurify() {
10881088
* @returns {boolean} Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
10891089
*/
10901090
const _isBasicCustomElement = function _isBasicCustomElement(tagName) {
1091-
return tagName.indexOf('-') > 0;
1091+
return tagName !== 'annotation-xml' && tagName.indexOf('-') > 0;
10921092
};
10931093

10941094
/**

‎dist/purify.es.mjs.map

+1-1
Large diffs are not rendered by default.

‎dist/purify.js

+1-1
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.

‎dist/purify.min.js.map

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

‎src/purify.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1194,7 +1194,7 @@ function createDOMPurify(window = getGlobal()) {
11941194
* @returns {boolean} Returns true if the tag name meets the basic criteria for a custom element, otherwise false.
11951195
*/
11961196
const _isBasicCustomElement = function (tagName) {
1197-
return tagName.indexOf('-') > 0;
1197+
return tagName !== 'annotation-xml' && tagName.indexOf('-') > 0;
11981198
};
11991199

12001200
/**

‎test/test-suite.js

+11
Original file line numberDiff line numberDiff line change
@@ -2093,5 +2093,16 @@
20932093
// cleanup hook
20942094
DOMPurify.removeHook(entryPoint);
20952095
});
2096+
2097+
QUnit.test('Test proper removal of annotation-xml w. custom elements', function (assert) {
2098+
const dirty = '<svg><annotation-xml><foreignobject><style><!--</style><p id="--><img src=\'x\' onerror=\'alert(1)\'>">';
2099+
const config = {
2100+
CUSTOM_ELEMENT_HANDLING: { tagNameCheck: /.*/ },
2101+
FORBID_CONTENTS: [""]
2102+
};
2103+
const expected = '<svg></svg>';
2104+
let clean = DOMPurify.sanitize(dirty, config);
2105+
assert.contains(clean, expected);
2106+
});
20962107
};
20972108
});

0 commit comments

Comments
 (0)
Please sign in to comment.