Skip to content

Commit 918a201

Browse files
committed
fix: Improved the handling of risky content inside CDATA
fix: Slightly improved the webiste attack vector loader fix: Fixed the tests to make more sense given the recent CDATA change
1 parent c2871f9 commit 918a201

File tree

11 files changed

+41
-13
lines changed

11 files changed

+41
-13
lines changed

dist/purify.cjs.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.cjs.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.es.mjs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,11 @@ function createDOMPurify() {
913913
_forceRemove(currentNode);
914914
return true;
915915
}
916+
/* Remove any kind of possibly harmful rawtext elements */
917+
if (SAFE_FOR_XML && currentNode.hasChildNodes() && regExpTest(/<\/(style|script|xmp|iframe|noembed|noframes|plaintext|noscript)/gi, currentNode.textContent)) {
918+
_forceRemove(currentNode);
919+
return true;
920+
}
916921
/* Remove any kind of possibly harmful comments */
917922
if (SAFE_FOR_XML && currentNode.nodeType === NODE_TYPE.comment && regExpTest(/<[/\w]/g, currentNode.data)) {
918923
_forceRemove(currentNode);

dist/purify.es.mjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.js

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/purify.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/purify.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,6 +1061,19 @@ function createDOMPurify(window: WindowLike = getGlobal()): DOMPurify {
10611061
return true;
10621062
}
10631063

1064+
/* Remove any kind of possibly harmful rawtext elements */
1065+
if (
1066+
SAFE_FOR_XML &&
1067+
currentNode.hasChildNodes() &&
1068+
regExpTest(
1069+
/<\/(style|script|xmp|iframe|noembed|noframes|plaintext|noscript)/gi,
1070+
currentNode.textContent
1071+
)
1072+
) {
1073+
_forceRemove(currentNode);
1074+
return true;
1075+
}
1076+
10641077
/* Remove any kind of possibly harmful comments */
10651078
if (
10661079
SAFE_FOR_XML &&

test/test-suite.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -278,23 +278,23 @@
278278
),
279279
'<a>123</a><option></option>'
280280
);
281-
assert.equal(
281+
assert.contains(
282282
DOMPurify.sanitize(
283283
'<option><style></option></select><b><img src=xx: onerror=alert(1)></style></option>'
284284
),
285-
'<option></option>'
285+
['<option></option>', '']
286286
);
287-
assert.equal(
287+
assert.contains(
288288
DOMPurify.sanitize(
289289
'<option><iframe></select><b><script>alert(1)</script>'
290290
),
291-
'<option></option>'
291+
['<option></option>', '']
292292
);
293-
assert.equal(
293+
assert.contains(
294294
DOMPurify.sanitize(
295295
'<option><iframe></select><b><script>alert(1)</script>'
296296
),
297-
'<option></option>'
297+
['<option></option>', '']
298298
);
299299
assert.equal(
300300
DOMPurify.sanitize(
@@ -1132,7 +1132,7 @@
11321132
QUnit.test('DOMPurify.removed should be correct', function (assert) {
11331133
var dirty = '<option><iframe></select><b><script>alert(1)</script>';
11341134
DOMPurify.sanitize(dirty);
1135-
assert.equal(DOMPurify.removed.length, 1);
1135+
assert.equal(DOMPurify.removed.length, 2);
11361136
});
11371137

11381138
// Test 8 to check that DOMPurify.removed is correct if tags are clean

0 commit comments

Comments
 (0)