Skip to content

Commit

Permalink
Fix prototype pollution
Browse files Browse the repository at this point in the history
  • Loading branch information
ChenKS12138 committed Nov 24, 2020
1 parent f91f1c3 commit 3b2b6fc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Unreleased
respect `throwOnUndefined` if sort attribute is undefined.
* Add `base` arg to
[`int` filter](https://mozilla.github.io/nunjucks/templating.html#int).
* Fix Bug About Prototype Pollution.

3.2.2 (Jul 20 2020)
-------------------
Expand Down
2 changes: 1 addition & 1 deletion nunjucks/src/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ var supportsIterators = (
// variables, for example.
class Frame {
constructor(parent, isolateWrites) {
this.variables = {};
this.variables = Object.create(null);
this.parent = parent;
this.topLevel = false;
// if this is true, writes (set) should never propagate upwards past
Expand Down
16 changes: 16 additions & 0 deletions tests/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,21 @@

finish(done);
});

it('should not read variables property from Object.prototype', function(done) {
var payload = 'function(){ return 1+2; }()';
var data = {};
Object.getPrototypeOf(data).payload = payload;

render('{{ payload }}', data, {
noThrow: true
}, function(err, res) {
expect(err).to.equal(null);
expect(res).to.equal(payload);
});
delete Object.getPrototypeOf(data).payload;

finish(done);
});
});
}());

0 comments on commit 3b2b6fc

Please sign in to comment.