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

Commit

Permalink
fix($parse): throw error when accessing a restricted property indirectly
Browse files Browse the repository at this point in the history
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
  • Loading branch information
lgalfaso authored and petebacondarwin committed Sep 13, 2015
1 parent 24cd700 commit b2f8b0b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/ng/parse.js
Expand Up @@ -38,6 +38,15 @@ var $parseMinErr = minErr('$parse');


function ensureSafeMemberName(name, fullExpression) {
// From the JavaScript docs:
// Property names must be strings. This means that non-string objects cannot be used
// as keys in an object. Any non-string object, including a number, is typecasted
// into a string via the toString method.
//
// So, to ensure that we are checking the same `name` that JavaScript would use,
// we cast it to a string, if possible
name = (isObject(name) && name.toString) ? name.toString() : name;

if (name === "__defineGetter__" || name === "__defineSetter__"
|| name === "__lookupGetter__" || name === "__lookupSetter__"
|| name === "__proto__") {
Expand Down
24 changes: 18 additions & 6 deletions test/ng/parseSpec.js
Expand Up @@ -1679,12 +1679,10 @@ describe('parser', function() {
forEach([true, false], function(cspEnabled) {
describe('csp: ' + cspEnabled, function() {

beforeEach(module(function($provide) {
$provide.decorator('$sniffer', function($delegate) {
expect($delegate.csp.noUnsafeEval === true ||
$delegate.csp.noUnsafeEval === false).toEqual(true);
$delegate.csp.noUnsafeEval = cspEnabled;
});
beforeEach(module(function() {
expect(csp().noUnsafeEval === true ||
csp().noUnsafeEval === false).toEqual(true);
csp().noUnsafeEval = cspEnabled;
}, provideLog));

beforeEach(inject(function($rootScope) {
Expand Down Expand Up @@ -2669,6 +2667,20 @@ describe('parser', function() {
scope.$eval('{}["__proto__"].foo = 1');
}).toThrowMinErr('$parse', 'isecfld');

expect(function() {
scope.$eval('{}[["__proto__"]]');
}).toThrowMinErr('$parse', 'isecfld');
expect(function() {
scope.$eval('{}[["__proto__"]].foo = 1');
}).toThrowMinErr('$parse', 'isecfld');

expect(function() {
scope.$eval('0[["__proto__"]]');
}).toThrowMinErr('$parse', 'isecfld');
expect(function() {
scope.$eval('0[["__proto__"]].foo = 1');
}).toThrowMinErr('$parse', 'isecfld');

scope.a = "__pro";
scope.b = "to__";
expect(function() {
Expand Down

0 comments on commit b2f8b0b

Please sign in to comment.