File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
14183.2.2 (Jul 20 2020)
1519-------------------
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ var supportsIterators = (
1212// variables, for example.
1313class 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
Original file line number Diff line number Diff line change 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} ( ) ) ;
You can’t perform that action at this time.
0 commit comments