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

Commit ec98c94

Browse files
lgalfasopetebacondarwin
authored andcommitted
fix($parse): throw error when accessing a restricted property indirectly
When accessing an instance thru a computed member and the property is an array, then also check the string value of the array. Closes #12833
1 parent f13055a commit ec98c94

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/ng/parse.js

+9
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ var $parseMinErr = minErr('$parse');
3838

3939

4040
function ensureSafeMemberName(name, fullExpression) {
41+
// From the JavaScript docs:
42+
// Property names must be strings. This means that non-string objects cannot be used
43+
// as keys in an object. Any non-string object, including a number, is typecasted
44+
// into a string via the toString method.
45+
//
46+
// So, to ensure that we are checking the same `name` that JavaScript would use,
47+
// we cast it to a string, if possible
48+
name = (isObject(name) && name.toString) ? name.toString() : name;
49+
4150
if (name === "__defineGetter__" || name === "__defineSetter__"
4251
|| name === "__lookupGetter__" || name === "__lookupSetter__"
4352
|| name === "__proto__") {

test/ng/parseSpec.js

+14
Original file line numberDiff line numberDiff line change
@@ -1190,6 +1190,20 @@ describe('parser', function() {
11901190
scope.$eval('{}["__proto__"].foo = 1');
11911191
}).toThrowMinErr('$parse', 'isecfld');
11921192

1193+
expect(function() {
1194+
scope.$eval('{}[["__proto__"]]');
1195+
}).toThrowMinErr('$parse', 'isecfld');
1196+
expect(function() {
1197+
scope.$eval('{}[["__proto__"]].foo = 1');
1198+
}).toThrowMinErr('$parse', 'isecfld');
1199+
1200+
expect(function() {
1201+
scope.$eval('0[["__proto__"]]');
1202+
}).toThrowMinErr('$parse', 'isecfld');
1203+
expect(function() {
1204+
scope.$eval('0[["__proto__"]].foo = 1');
1205+
}).toThrowMinErr('$parse', 'isecfld');
1206+
11931207
scope.a = "__pro";
11941208
scope.b = "to__";
11951209
expect(function() {

0 commit comments

Comments
 (0)