Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit f47e218

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

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
@@ -2795,6 +2795,12 @@ describe('parser', function() {
27952795
expect(function() {
27962796
scope.$eval("objConstructor = {}.constructor; objConstructor.join = ''");
27972797
}).toThrow();
2798+
expect(function() {
2799+
scope.$eval("'a'.constructor.prototype.charAt=[].join");
2800+
}).toThrow();
2801+
expect(function() {
2802+
scope.$eval("'a'.constructor.prototype.charCodeAt=[].concat");
2803+
}).toThrow();
27982804
});
27992805
});
28002806

0 commit comments

Comments
 (0)