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

Commit 528be29

Browse files
thejhIgorMinar
authored andcommitted
fix($parse): forbid referencing Object in angular expressions
It was possible to run arbitrary JS from inside angular expressions using the `Object.getOwnPropertyDescriptor` method like this since commit 4ab16aa: ''.sub.call.call( ({})["constructor"].getOwnPropertyDescriptor(''.sub.__proto__, "constructor").value, null, "alert(1)" )() Fix that by blocking access to `Object` because `Object` isn't accessible without tricks anyway and it provides some other nasty functions. BREAKING CHANGE: This prevents the use of `Object` inside angular expressions. If you need Object.keys, make it accessible in the scope.
1 parent 2df7219 commit 528be29

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/ng/parse.js

+5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ function ensureSafeObject(obj, fullExpression) {
5757
throw $parseMinErr('isecdom',
5858
'Referencing DOM nodes in Angular expressions is disallowed! Expression: {0}',
5959
fullExpression);
60+
} else if (// isObject(obj)
61+
obj.getOwnPropertyNames || obj.getOwnPropertyDescriptor) {
62+
throw $parseMinErr('isecobj',
63+
'Referencing Object in Angular expressions is disallowed! Expression: {0}',
64+
fullExpression);
6065
}
6166
}
6267
return obj;

test/ng/parseSpec.js

+27
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,33 @@ describe('parser', function() {
743743
});
744744
});
745745

746+
describe('Object constructor', function() {
747+
it('should NOT allow access to scope constructor', function() {
748+
expect(function() {
749+
scope.$eval('constructor.keys({})');
750+
}).toThrowMinErr(
751+
'$parse', 'isecfld', 'Referencing "constructor" field in Angular expressions '+
752+
'is disallowed! Expression: constructor.keys({})');
753+
});
754+
755+
it('should NOT allow access to Object constructor in getter', function() {
756+
expect(function() {
757+
scope.$eval('{}["constructor"]');
758+
}).toThrowMinErr(
759+
'$parse', 'isecobj', 'Referencing Object in Angular expressions is disallowed! ' +
760+
'Expression: {}["constructor"]');
761+
});
762+
763+
it('should NOT allow access to Object constructor that has been aliased', function() {
764+
scope.foo = { "bar": Object };
765+
expect(function() {
766+
scope.$eval('foo["bar"]');
767+
}).toThrowMinErr(
768+
'$parse', 'isecobj', 'Referencing Object in Angular expressions is disallowed! ' +
769+
'Expression: foo["bar"]');
770+
771+
});
772+
});
746773

747774
describe('Window and $element/node', function() {
748775
it('should NOT allow access to the Window or DOM when indexing', inject(function($window, $document) {

0 commit comments

Comments
 (0)