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

Commit cb713e6

Browse files
thejhIgorMinar
authored andcommitted
fix($parse): forbid __proto__ properties in angular expressions
__proto__ can be used to mess with global prototypes and it's deprecated. Therefore, blacklisting it seems like a good idea. BREAKING CHANGE: The (deprecated) __proto__ propery does not work inside angular expressions anymore.
1 parent 89ca859 commit cb713e6

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/ng/parse.js

+7
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ function ensureSafeMemberName(name, fullExpression) {
4343
throw $parseMinErr('isecgetset',
4444
'Defining and looking up getters and setters in Angular expressions is disallowed! '
4545
+'Expression: {0}', fullExpression);
46+
} else if (name === "__proto__") {
47+
throw $parseMinErr('isecproto', 'Using __proto__ in Angular expressions is disallowed! '
48+
+'Expression: {0}', fullExpression);
4649
}
4750
return name;
4851
}
@@ -713,6 +716,10 @@ Parser.prototype = {
713716
i = indexFn(self, locals),
714717
v, p;
715718

719+
if (i === "__proto__") {
720+
throw $parseMinErr('isecproto', 'Using __proto__ in Angular expressions is disallowed! '
721+
+'Expression: {0}', parser.text);
722+
}
716723
if (!o) return undefined;
717724
v = ensureSafeObject(o[i], parser.text);
718725
if (v && v.then && parser.options.unwrapPromises) {

test/ng/parseSpec.js

+16
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,22 @@ describe('parser', function() {
11061106
});
11071107
});
11081108

1109+
1110+
describe('__proto__', function() {
1111+
it('should NOT allow access to __proto__', function() {
1112+
expect(function() {
1113+
scope.$eval('{}.__proto__.foo = 1');
1114+
}).toThrowMinErr(
1115+
'$parse', 'isecproto', 'Using __proto__ in Angular expressions is disallowed!'+
1116+
' Expression: {}.__proto__.foo = 1');
1117+
expect(function() {
1118+
scope.$eval('{}["__pro"+"to__"].foo = 1');
1119+
}).toThrowMinErr(
1120+
'$parse', 'isecproto', 'Using __proto__ in Angular expressions is disallowed!'+
1121+
' Expression: {}["__pro"+"to__"].foo = 1');
1122+
});
1123+
});
1124+
11091125

11101126
describe('constant', function() {
11111127
it('should mark scalar value expressions as constant', inject(function($parse) {

0 commit comments

Comments
 (0)