|
465 | 465 | assert.strictEqual(template(), '<<\nx\n>>');
|
466 | 466 | });
|
467 | 467 |
|
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) { |
469 | 469 | QUnit.holyProperty = 'holy';
|
470 | 470 | var invalidVariableNames = [
|
471 | 471 | '){delete QUnit.holyProperty}; with(obj',
|
472 | 472 | '(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!")' |
474 | 477 | ];
|
475 | 478 | _.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; |
477 | 484 | });
|
478 | 485 | var holy = QUnit.holyProperty;
|
479 | 486 | 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'); |
481 | 489 | });
|
482 | 490 |
|
483 | 491 | }());
|
0 commit comments