-
-
Notifications
You must be signed in to change notification settings - Fork 753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Registering hook leads to infinite loop in IE 10 / IE 11 #89
Comments
Oh, that sounds bad, I'll have a look right away! |
I can reproduce the issue. I think the problem here is the following: MSIE seems to recurse over this operation, because it appears to create a new That means, that upon setting the text, a new node appears that needs to be sanitized, then text is being set, creating a new This example hangs: DOMPurify.addHook('afterSanitizeElements', function(node) {
if (node.nodeType && node.nodeType === document.TEXT_NODE) {
node.textContent = 'foo';
}
return node;
}); This example does not: DOMPurify.addHook('afterSanitizeElements', function(node) {
if (node.nodeType && node.nodeType === document.TEXT_NODE) {
node.innerText = 'foo';
}
return node;
}); |
Okay, I came up with a first possible fix: https://github.com/cure53/DOMPurify/compare/Experimental_Fix_for_89?expand=1 This fix stores a copy of the currently processed mode as This could be a security critical change so I'd kindly ask for review, @fhemberger and @neilj. I also think the fix is ugly but I cannot come up with something better right now. |
A few thoughts:
There should be a space after the |
@neilj The hang also happens with The fix surprisingly works, because in this situation, the result is indeed About the coding inconsistencies: True, you are 100% right. But at this stage of the fix (merely experimenting in an experimental branch) I don't care too much. Cosmetics when cosmetics are due. Now I want to find a working and reasonable fix. |
Fine. So actually IE is doing something very weird, not simply replacing the text node then. In that case, I have one small change I think. Instead of:
I think you want:
We've already processed the old node, yes? So we don't want to process it again. The current code (if I understand the IE bug correctly now) skips the first node after the text node that's replaced, which is potentially a security hole. |
That makes much more sense, thanks! I'll add a test-case and then will post the diff here again for review. |
Okay, ready for review again: https://github.com/cure53/DOMPurify/compare/Experimental_Fix_for_89?expand=1 |
That looks good to me. |
Thanks, merging... |
@luhmann From what I can see we are good to close this issue. Any thoughts? |
Fix works perfectly for me. Thank you very much for the quick help. |
Either I am doing something very obvious wrong or registering a hook (I tested
afterSanitizeElements
andbeforeSanitizeElements
) and then calling the sanitize-method leads to an infinite loop in IE 10 and IE 11, which hangs up the browser. If I remove the hook, everything works fine. My JS Code just does this:I would expect it to keep the DOM-structure intact and just replace the text-nodes with "foo".
I created a pen which is enough to cause the error in IE 10 and IE 11. Other browsers (I tested Edge, Chrome, Firefox and Safari) look fine to me: http://codepen.io/anon/pen/YywGXz
The text was updated successfully, but these errors were encountered: