Skip to content

Commit aa9e5b9

Browse files
ChenKS12138fdintino
authored andcommitted
Fix prototype pollution security issue. fixes #1331
1 parent f51afa3 commit aa9e5b9

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ Unreleased
1010
* Add `base` arg to
1111
[`int` filter](https://mozilla.github.io/nunjucks/templating.html#int).
1212
* Move `chokidar` to `peerDependencies` and mark it `optional` in `peerDependenciesMeta`.
13+
* Fix prototype pollution issue for template variables. Merge of
14+
[#1330](https://github.com/mozilla/nunjucks/pull/1330); fixes
15+
[#1331](https://github.com/mozilla/nunjucks/issues/1331). Thanks
16+
[ChenKS12138](https://github.com/ChenKS12138)!
1317

1418
3.2.2 (Jul 20 2020)
1519
-------------------

nunjucks/src/runtime.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ var supportsIterators = (
1212
// variables, for example.
1313
class Frame {
1414
constructor(parent, isolateWrites) {
15-
this.variables = {};
15+
this.variables = Object.create(null);
1616
this.parent = parent;
1717
this.topLevel = false;
1818
// if this is true, writes (set) should never propagate upwards past

tests/runtime.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,21 @@
110110

111111
finish(done);
112112
});
113+
114+
it('should not read variables property from Object.prototype', function(done) {
115+
var payload = 'function(){ return 1+2; }()';
116+
var data = {};
117+
Object.getPrototypeOf(data).payload = payload;
118+
119+
render('{{ payload }}', data, {
120+
noThrow: true
121+
}, function(err, res) {
122+
expect(err).to.equal(null);
123+
expect(res).to.equal(payload);
124+
});
125+
delete Object.getPrototypeOf(data).payload;
126+
127+
finish(done);
128+
});
113129
});
114130
}());

0 commit comments

Comments
 (0)