@@ -102,6 +102,16 @@ function ensureSafeFunction(obj, fullExpression) {
102
102
}
103
103
}
104
104
105
+ function ensureSafeAssignContext ( obj , fullExpression ) {
106
+ if ( obj ) {
107
+ if ( obj === ( 0 ) . constructor || obj === ( false ) . constructor || obj === '' . constructor ||
108
+ obj === { } . constructor || obj === [ ] . constructor || obj === Function . constructor ) {
109
+ throw $parseMinErr ( 'isecaf' ,
110
+ 'Assigning to a constructor is disallowed! Expression: {0}' , fullExpression ) ;
111
+ }
112
+ }
113
+ }
114
+
105
115
var OPERATORS = createMap ( ) ;
106
116
forEach ( '+ - * / % === !== == != < > <= >= && || ! = |' . split ( ' ' ) , function ( operator ) { OPERATORS [ operator ] = true ; } ) ;
107
117
var ESCAPE = { "n" :"\n" , "f" :"\f" , "r" :"\r" , "t" :"\t" , "v" :"\v" , "'" :"'" , '"' :'"' } ;
@@ -816,6 +826,7 @@ ASTCompiler.prototype = {
816
826
'ensureSafeMemberName' ,
817
827
'ensureSafeObject' ,
818
828
'ensureSafeFunction' ,
829
+ 'ensureSafeAssignContext' ,
819
830
'ifDefined' ,
820
831
'plus' ,
821
832
'text' ,
@@ -824,6 +835,7 @@ ASTCompiler.prototype = {
824
835
ensureSafeMemberName ,
825
836
ensureSafeObject ,
826
837
ensureSafeFunction ,
838
+ ensureSafeAssignContext ,
827
839
ifDefined ,
828
840
plusFn ,
829
841
expression ) ;
@@ -1050,6 +1062,7 @@ ASTCompiler.prototype = {
1050
1062
self . if_ ( self . notNull ( left . context ) , function ( ) {
1051
1063
self . recurse ( ast . right , right ) ;
1052
1064
self . addEnsureSafeObject ( self . member ( left . context , left . name , left . computed ) ) ;
1065
+ self . addEnsureSafeAssignContext ( left . context ) ;
1053
1066
expression = self . member ( left . context , left . name , left . computed ) + ast . operator + right ;
1054
1067
self . assign ( intoId , expression ) ;
1055
1068
recursionFn ( intoId || expression ) ;
@@ -1175,6 +1188,10 @@ ASTCompiler.prototype = {
1175
1188
this . current ( ) . body . push ( this . ensureSafeFunction ( item ) , ';' ) ;
1176
1189
} ,
1177
1190
1191
+ addEnsureSafeAssignContext : function ( item ) {
1192
+ this . current ( ) . body . push ( this . ensureSafeAssignContext ( item ) , ';' ) ;
1193
+ } ,
1194
+
1178
1195
ensureSafeObject : function ( item ) {
1179
1196
return 'ensureSafeObject(' + item + ',text)' ;
1180
1197
} ,
@@ -1187,6 +1204,10 @@ ASTCompiler.prototype = {
1187
1204
return 'ensureSafeFunction(' + item + ',text)' ;
1188
1205
} ,
1189
1206
1207
+ ensureSafeAssignContext : function ( item ) {
1208
+ return 'ensureSafeAssignContext(' + item + ',text)' ;
1209
+ } ,
1210
+
1190
1211
lazyRecurse : function ( ast , intoId , nameId , recursionFn , create , skipWatchIdCheck ) {
1191
1212
var self = this ;
1192
1213
return function ( ) {
@@ -1364,6 +1385,7 @@ ASTInterpreter.prototype = {
1364
1385
var lhs = left ( scope , locals , assign , inputs ) ;
1365
1386
var rhs = right ( scope , locals , assign , inputs ) ;
1366
1387
ensureSafeObject ( lhs . value , self . expression ) ;
1388
+ ensureSafeAssignContext ( lhs . context ) ;
1367
1389
lhs . context [ lhs . name ] = rhs ;
1368
1390
return context ? { value : rhs } : rhs ;
1369
1391
} ;
0 commit comments