Skip to content

Commit aec12c4

Browse files
committedSep 24, 2020
fix: Re-added an mXSS check for old Chrome
1 parent 4586294 commit aec12c4

10 files changed

+41
-6
lines changed
 

‎dist/purify.cjs.js

+6
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.js

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

‎dist/purify.es.js.map

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

‎dist/purify.js

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

+9
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,15 @@ function createDOMPurify(window = getGlobal()) {
840840
continue;
841841
}
842842

843+
/* Take care of an mXSS pattern using namespace switches */
844+
if (
845+
regExpTest(/svg|math/i, currentNode.namespaceURI) &&
846+
regExpTest(/<\//, value)
847+
) {
848+
_removeAttribute(name, currentNode);
849+
continue;
850+
}
851+
843852
/* Sanitize attribute content to be template-safe */
844853
if (SAFE_FOR_TEMPLATES) {
845854
value = stringReplace(value, MUSTACHE_EXPR, ' ');

‎test/fixtures/expect.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -1005,7 +1005,7 @@ module.exports = [
10051005
""
10061006
]
10071007
}, {
1008-
"title": "Tests against mXSS behavior with SVG in Chrome 77 and alike",
1008+
"title": "Tests against mXSS behavior with SVG in Chrome 77 and alike 1/2",
10091009
"payload": "<svg></p><textarea><title><style></textarea><img src=x onerror=alert(1)></style></title></svg>",
10101010
"expected": [
10111011
"",
@@ -1015,6 +1015,14 @@ module.exports = [
10151015
"<svg xmlns=\"http://www.w3.org/2000/svg\"><p></p><textarea><title /></textarea></svg>",
10161016
"<svg xmlns=\"http://www.w3.org/2000/svg\"><p></p><textarea></textarea></svg>"
10171017
]
1018+
}, {
1019+
"title": "Tests against mXSS behavior with SVG in Chrome 77 and alike 2/2",
1020+
"payload": "<svg></p><title><a id=\"</title><img src=x onerror=alert()>\"></textarea></svg>",
1021+
"expected": [
1022+
"",
1023+
"<svg><p></p><title><a id=\"</title><img src=x onerror=alert()>\"></a></title></svg>",
1024+
"<svg></svg><p></p><title>&lt;a id=\"</title><img src=\"x\">\"&gt;"
1025+
]
10181026
}, {
10191027
"title": "Tests against mXSS behavior with MathML in Chrome 77 and alike",
10201028
"payload": "<math></p><textarea><mi><style></textarea><img src=x onerror=alert(1)></mi></math>",

0 commit comments

Comments
 (0)
Please sign in to comment.