Skip to content

Commit 88d59cd

Browse files
committed
- Mitigate reference to arguments for new Function
1 parent 1687892 commit 88d59cd

File tree

7 files changed

+30
-9
lines changed

7 files changed

+30
-9
lines changed

dist/index-es.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,17 @@ var vm = supportsNodeVM() ? require('vm') : {
224224
}
225225

226226
return 'var ' + func + '=' + fString + ';' + s;
227-
}, ''); // Remove last semi so `return` will be inserted before
227+
}, '');
228+
expr = funcString + expr; // Mitigate http://perfectionkills.com/global-eval-what-are-the-options/#new_function
229+
230+
if (!expr.match(/(["'])use strict\1/) && !keys.includes('arguments')) {
231+
expr = 'var arguments = undefined;' + expr;
232+
} // Remove last semi so `return` will be inserted before
228233
// the previous one instead, allowing for the return
229234
// of a bare ending expression
230235

231-
expr = (funcString + expr).replace(/;[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*$/, ''); // Insert `return`
236+
237+
expr = expr.replace(/;[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*$/, ''); // Insert `return`
232238

233239
var lastStatementEnd = expr.lastIndexOf(';');
234240
var code = lastStatementEnd > -1 ? expr.slice(0, lastStatementEnd + 1) + ' return ' + expr.slice(lastStatementEnd + 1) : ' return ' + expr; // eslint-disable-next-line no-new-func

dist/index-es.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/index-es.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.

dist/index-umd.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,17 @@
230230
}
231231

232232
return 'var ' + func + '=' + fString + ';' + s;
233-
}, ''); // Remove last semi so `return` will be inserted before
233+
}, '');
234+
expr = funcString + expr; // Mitigate http://perfectionkills.com/global-eval-what-are-the-options/#new_function
235+
236+
if (!expr.match(/(["'])use strict\1/) && !keys.includes('arguments')) {
237+
expr = 'var arguments = undefined;' + expr;
238+
} // Remove last semi so `return` will be inserted before
234239
// the previous one instead, allowing for the return
235240
// of a bare ending expression
236241

237-
expr = (funcString + expr).replace(/;[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*$/, ''); // Insert `return`
242+
243+
expr = expr.replace(/;[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]*$/, ''); // Insert `return`
238244

239245
var lastStatementEnd = expr.lastIndexOf(';');
240246
var code = lastStatementEnd > -1 ? expr.slice(0, lastStatementEnd + 1) + ' return ' + expr.slice(lastStatementEnd + 1) : ' return ' + expr; // eslint-disable-next-line no-new-func

dist/index-umd.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/index-umd.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/jsonpath.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,19 @@ const vm = supportsNodeVM()
7272
return 'var ' + func + '=' + fString + ';' + s;
7373
}, '');
7474

75+
expr = funcString + expr;
76+
77+
// Mitigate http://perfectionkills.com/global-eval-what-are-the-options/#new_function
78+
if (!expr.match(/(['"])use strict\1/u) &&
79+
!keys.includes('arguments')
80+
) {
81+
expr = 'var arguments = undefined;' + expr;
82+
}
83+
7584
// Remove last semi so `return` will be inserted before
7685
// the previous one instead, allowing for the return
7786
// of a bare ending expression
78-
expr = (funcString + expr).replace(/;\s*$/u, '');
87+
expr = expr.replace(/;\s*$/u, '');
7988

8089
// Insert `return`
8190
const lastStatementEnd = expr.lastIndexOf(';');

0 commit comments

Comments
 (0)