-
-
Notifications
You must be signed in to change notification settings - Fork 822
Closed
Description
BUG: version 2.0.8 VS 2.2.7 different behaviour on the same input when running from phantomJS tests.
Background & Context
Consider this HTML to sanitize:
<allowStyleAsFirstTag/><span class="btn" href="" data-cwdb="%7B%22confirmation%22%3A%22Some%20confirmation%20here%22%2C%22action%22%3A%7B%22html%22%3A%22%23%23%23%20HTML%20content%20%23%23%23%22%7D%2C%22display%22%3A%22widget%22%7D">Test button</span>
When running on casper / phantonJS the version 2.0.8 works fine and returns the full html stripping out just <allowStyleAsFirstTag/>
The last version of Dompurify 2.2.7 instead removes all HTML returning an empty string.
Bug
Remove HTML that shouldn't be removed on specific browser engines.
Input
<allowStyleAsFirstTag/><span class="btn" href="" data-cwdb="%7B%22confirmation%22%3A%22Some%20confirmation%20here%22%2C%22action%22%3A%7B%22html%22%3A%22%23%23%23%20HTML%20content%20%23%23%23%22%7D%2C%22display%22%3A%22widget%22%7D">Test button</span>
Given output
EMPTY
Expected output
<span class="btn" href="" data-cwdb="%7B%22confirmation%22%3A%22Some%20confirmation%20here%22%2C%22action%22%3A%7B%22html%22%3A%22%23%23%23%20HTML%20content%20%23%23%23%22%7D%2C%22display%22%3A%22widget%22%7D">Test button</span>
Digging into the code all comes to this lines of DOMPurify 2.2.7:
if (KEEP_CONTENT && !FORBID_CONTENTS[tagName]) {
console.error('===========>>>KEEP_CONTENT', KEEP_CONTENT);
var parentNode = getParentNode(currentNode);
var childNodes = getChildNodes(currentNode);
if (childNodes && parentNode) {
var childCount = childNodes.length;
for (var i = childCount - 1; i >= 0; --i) {
parentNode.insertBefore(cloneNode(childNodes[i], true), getNextSibling(currentNode));
}
}
}
Replacing the above with the old method in 2.0.8, works fine:
/* Keep content except for black-listed elements */
if (KEEP_CONTENT && !FORBID_CONTENTS[tagName] && typeof currentNode.insertAdjacentHTML === 'function') {
try {
var htmlToInsert = currentNode.innerHTML;
currentNode.insertAdjacentHTML(
'AfterEnd',
trustedTypesPolicy ? trustedTypesPolicy.createHTML(htmlToInsert) : htmlToInsert
);
} catch (error) {}
}
Any thoughts?
Thanks
Alban
Metadata
Metadata
Assignees
Labels
No labels