Check for presence of script node before post eval cleanup #185

Closed
opened 2018-11-20 08:05:36 -05:00 by rungta · 1 comment
rungta commented 2018-11-20 08:05:36 -05:00 (Migrated from github.com)

52fb3bf938/lib/eval-script.js (L37)

Sometimes a script tag can contain code that, on execution, cleans up after itself by removing the original script node. For example, an obfuscation snippet that uses document.currentScript.parentNode.removeChild(document.currentScript) to remove the script node and replace it with the decoded content.

In such a case, Pjax results in a DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node. while attempting to cleanup. It would be great if there was a condition that checked for the presence of the script node post eval before attempting to remove it.

https://github.com/MoOx/pjax/blob/52fb3bf938941fc16f2731270a6c7391eb2bb61b/lib/eval-script.js#L37 Sometimes a script tag can contain code that, on execution, cleans up after itself by removing the original script node. For example, an obfuscation snippet that uses `document.currentScript.parentNode.removeChild(document.currentScript)` to remove the script node and replace it with the decoded content. In such a case, Pjax results in a `DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node.` while attempting to cleanup. It would be great if there was a condition that checked for the presence of the script node post eval before attempting to remove it.
rungta commented 2018-11-21 01:12:50 -05:00 (Migrated from github.com)

Suggestion: a parent.contains(script) check before parent.removeChild(script) might do the trick.

Suggestion: a `parent.contains(script)` check before `parent.removeChild(script)` might do the trick.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: iLoveElysia/pjax#185