@@ -112,6 +112,16 @@ function ensureSafeFunction(obj, fullExpression) {
112
112
}
113
113
}
114
114
115
+ function ensureSafeAssignContext ( obj , fullExpression ) {
116
+ if ( obj ) {
117
+ if ( obj === ( 0 ) . constructor || obj === ( false ) . constructor || obj === '' . constructor ||
118
+ obj === { } . constructor || obj === [ ] . constructor || obj === Function . constructor ) {
119
+ throw $parseMinErr ( 'isecaf' ,
120
+ 'Assigning to a constructor is disallowed! Expression: {0}' , fullExpression ) ;
121
+ }
122
+ }
123
+ }
124
+
115
125
var OPERATORS = createMap ( ) ;
116
126
forEach ( '+ - * / % === !== == != < > <= >= && || ! = |' . split ( ' ' ) , function ( operator ) { OPERATORS [ operator ] = true ; } ) ;
117
127
var ESCAPE = { "n" :"\n" , "f" :"\f" , "r" :"\r" , "t" :"\t" , "v" :"\v" , "'" :"'" , '"' :'"' } ;
@@ -827,6 +837,7 @@ ASTCompiler.prototype = {
827
837
'ensureSafeObject' ,
828
838
'ensureSafeFunction' ,
829
839
'getStringValue' ,
840
+ 'ensureSafeAssignContext' ,
830
841
'ifDefined' ,
831
842
'plus' ,
832
843
'text' ,
@@ -836,6 +847,7 @@ ASTCompiler.prototype = {
836
847
ensureSafeObject ,
837
848
ensureSafeFunction ,
838
849
getStringValue ,
850
+ ensureSafeAssignContext ,
839
851
ifDefined ,
840
852
plusFn ,
841
853
expression ) ;
@@ -1063,6 +1075,7 @@ ASTCompiler.prototype = {
1063
1075
self . if_ ( self . notNull ( left . context ) , function ( ) {
1064
1076
self . recurse ( ast . right , right ) ;
1065
1077
self . addEnsureSafeObject ( self . member ( left . context , left . name , left . computed ) ) ;
1078
+ self . addEnsureSafeAssignContext ( left . context ) ;
1066
1079
expression = self . member ( left . context , left . name , left . computed ) + ast . operator + right ;
1067
1080
self . assign ( intoId , expression ) ;
1068
1081
recursionFn ( intoId || expression ) ;
@@ -1188,6 +1201,10 @@ ASTCompiler.prototype = {
1188
1201
this . current ( ) . body . push ( this . ensureSafeFunction ( item ) , ';' ) ;
1189
1202
} ,
1190
1203
1204
+ addEnsureSafeAssignContext : function ( item ) {
1205
+ this . current ( ) . body . push ( this . ensureSafeAssignContext ( item ) , ';' ) ;
1206
+ } ,
1207
+
1191
1208
ensureSafeObject : function ( item ) {
1192
1209
return 'ensureSafeObject(' + item + ',text)' ;
1193
1210
} ,
@@ -1204,6 +1221,10 @@ ASTCompiler.prototype = {
1204
1221
this . assign ( item , 'getStringValue(' + item + ',text)' ) ;
1205
1222
} ,
1206
1223
1224
+ ensureSafeAssignContext : function ( item ) {
1225
+ return 'ensureSafeAssignContext(' + item + ',text)' ;
1226
+ } ,
1227
+
1207
1228
lazyRecurse : function ( ast , intoId , nameId , recursionFn , create , skipWatchIdCheck ) {
1208
1229
var self = this ;
1209
1230
return function ( ) {
@@ -1381,6 +1402,7 @@ ASTInterpreter.prototype = {
1381
1402
var lhs = left ( scope , locals , assign , inputs ) ;
1382
1403
var rhs = right ( scope , locals , assign , inputs ) ;
1383
1404
ensureSafeObject ( lhs . value , self . expression ) ;
1405
+ ensureSafeAssignContext ( lhs . context ) ;
1384
1406
lhs . context [ lhs . name ] = rhs ;
1385
1407
return context ? { value : rhs } : rhs ;
1386
1408
} ;
0 commit comments