Skip to content

Commit 5a674f3

Browse files
lgalfasopetebacondarwin
authored andcommitted
fix($parse): prevent assignment on constructor properties
Prevent malicious attacks involving assignment on `constructor` properties. Closes angular#13417
1 parent e94b37e commit 5a674f3

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

src/ng/parse.js

+13-4
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,9 @@ ASTCompiler.prototype = {
988988
intoId = intoId || this.nextId();
989989
self.recurse(ast.object, left, undefined, function() {
990990
self.if_(self.notNull(left), function() {
991+
if (create && create !== 1) {
992+
self.addEnsureSafeAssignContext(left);
993+
}
991994
if (ast.computed) {
992995
right = self.nextId();
993996
self.recurse(ast.property, right);
@@ -1602,8 +1605,11 @@ ASTInterpreter.prototype = {
16021605
rhs = right(scope, locals, assign, inputs);
16031606
rhs = getStringValue(rhs);
16041607
ensureSafeMemberName(rhs, expression);
1605-
if (create && create !== 1 && lhs && !(lhs[rhs])) {
1606-
lhs[rhs] = {};
1608+
if (create && create !== 1) {
1609+
ensureSafeAssignContext(lhs);
1610+
if (lhs && !(lhs[rhs])) {
1611+
lhs[rhs] = {};
1612+
}
16071613
}
16081614
value = lhs[rhs];
16091615
ensureSafeObject(value, expression);
@@ -1618,8 +1624,11 @@ ASTInterpreter.prototype = {
16181624
nonComputedMember: function(left, right, expensiveChecks, context, create, expression) {
16191625
return function(scope, locals, assign, inputs) {
16201626
var lhs = left(scope, locals, assign, inputs);
1621-
if (create && create !== 1 && lhs && !(lhs[right])) {
1622-
lhs[right] = {};
1627+
if (create && create !== 1) {
1628+
ensureSafeAssignContext(lhs);
1629+
if (lhs && !(lhs[right])) {
1630+
lhs[right] = {};
1631+
}
16231632
}
16241633
var value = lhs != null ? lhs[right] : undefined;
16251634
if (expensiveChecks || isPossiblyDangerousMemberName(right)) {

test/ng/parseSpec.js

+6
Original file line numberDiff line numberDiff line change
@@ -2740,6 +2740,12 @@ describe('parser', function() {
27402740
expect(function() {
27412741
scope.$eval("objConstructor = {}.constructor; objConstructor.join = ''");
27422742
}).toThrow();
2743+
expect(function() {
2744+
scope.$eval("'a'.constructor.prototype.charAt=[].join");
2745+
}).toThrow();
2746+
expect(function() {
2747+
scope.$eval("'a'.constructor.prototype.charCodeAt=[].concat");
2748+
}).toThrow();
27432749
});
27442750
});
27452751

0 commit comments

Comments
 (0)