Skip to content

Commit ef646cc

Browse files
committedMar 14, 2021
Reflect real issue of #2911 in test from #2912
1 parent a6159ff commit ef646cc

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed
 

‎test/utility.js

+12-4
Original file line numberDiff line numberDiff line change
@@ -465,19 +465,27 @@
465465
assert.strictEqual(template(), '<<\nx\n>>');
466466
});
467467

468-
QUnit.test('#2911 - _.template must not trigger CVE-2021-23337.', function(assert) {
468+
QUnit.test('#2911 - _.templateSettings.variable must not allow third parties to inject code.', function(assert) {
469469
QUnit.holyProperty = 'holy';
470470
var invalidVariableNames = [
471471
'){delete QUnit.holyProperty}; with(obj',
472472
'(x = QUnit.holyProperty = "evil"), obj',
473-
'document.write("got you!")'
473+
'document.write("got you!")',
474+
'a = (function() { delete QUnit.holyProperty; }())',
475+
'a = (QUnit.holyProperty = "evil")',
476+
'a = document.write("got you!")'
474477
];
475478
_.each(invalidVariableNames, function(name) {
476-
assert.throws(function() { _.template('', { variable: name })(); });
479+
_.templateSettings.variable = name;
480+
assert.throws(function() {
481+
_.template('')();
482+
}, 'code injection through _.templateSettings.variable: ' + name);
483+
delete _.templateSettings.variable;
477484
});
478485
var holy = QUnit.holyProperty;
479486
delete QUnit.holyProperty;
480-
assert.strictEqual(holy, 'holy');
487+
assert.strictEqual(holy, 'holy', '_.template variable cannot touch global state');
488+
assert.ok(_.isUndefined(_.templateSettings.variable), 'cleanup');
481489
});
482490

483491
}());

0 commit comments

Comments
 (0)
Please sign in to comment.