File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change @@ -14821,11 +14821,11 @@
14821
14821
14822
14822
// Use a sourceURL for easier debugging.
14823
14823
// The sourceURL gets injected into the source that's eval-ed, so be careful
14824
- // with lookup (in case of e.g. prototype pollution), and strip newlines if any.
14825
- // A newline wouldn't be a valid sourceURL anyway, and it'd enable code injection .
14824
+ // to normalize all kinds of whitespace, so e.g. newlines ( and unicode versions of it) can't sneak in
14825
+ // and escape the comment, thus injecting code that gets evaled .
14826
14826
var sourceURL = '//# sourceURL=' +
14827
14827
(hasOwnProperty.call(options, 'sourceURL')
14828
- ? (options.sourceURL + '').replace(/[\r\n] /g, ' ')
14828
+ ? (options.sourceURL + '').replace(/\s /g, ' ')
14829
14829
: ('lodash.templateSources[' + (++templateCounter) + ']')
14830
14830
) + '\n';
14831
14831
14858
14858
14859
14859
// If `variable` is not specified wrap a with-statement around the generated
14860
14860
// code to add the data object to the top of the scope chain.
14861
- // Like with sourceURL, we take care to not check the option's prototype,
14862
- // as this configuration is a code injection vector.
14863
14861
var variable = hasOwnProperty.call(options, 'variable') && options.variable;
14864
14862
if (!variable) {
14865
14863
s
BCB6
ource = 'with (obj) {\n' + source + '\n}\n';
Original file line number Diff line number Diff line change 22641
22641
assert.deepEqual(actual, expected);
22642
22642
});
22643
22643
22644
+ QUnit.test('should not let a sourceURL inject code', function(assert) {
22645
+ assert.expect(1);
22646
+
22647
+ var actual,
22648
+ expected = 'no error';
22649
+ try {
22650
+ actual = _.template(expected, {'sourceURL': '\u2028\u2029\n!this would err if it was executed!'})();
22651
+ } catch (e) {}
22652
+
22653
+ assert.equal(actual, expected);
22654
+ });
22655
+
22644
22656
QUnit.test('should work as an iteratee for methods like `_.map`', function(assert) {
22645
22657
assert.expect(1);
22646
22658
You can’t perform that action at this time.
0 commit comments