Make interrupt-checking function injection during js sanitzation more precise to avoid eval errors on complex scripts #26
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When processing complex scripts, e.g. containing browserified code, the sanitizer inserts teh interrupt checking function at wrong places and later fails to eval the secured js.
Example prefix:
var browserify_require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
will insert __if(); at 2 wrong places:
This PR adjusts the regexes for the interrupt-checking function injection to be more selective and also include brace-less for-loops. Surely there is more to be done (e.g. the sanitizer currently also injects __if(); inside comments if the 10th semicolon happens to be inside a comment) but it's prudent to be defensive with altering regexes so this can be improved incrementally after having been tested thoroughly.
cheers