mirror of
https://github.com/zhigang1992/angular.js.git
synced 2026-04-24 03:55:49 +08:00
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 4ab16aaa:
''.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.
This commit is contained in:
@@ -918,6 +918,33 @@ describe('parser', function() {
|
||||
expect(count).toBe(1);
|
||||
});
|
||||
|
||||
describe('Object constructor', function() {
|
||||
it('should NOT allow access to scope constructor', function() {
|
||||
expect(function() {
|
||||
scope.$eval('constructor.keys({})');
|
||||
}).toThrowMinErr(
|
||||
'$parse', 'isecfld', 'Referencing "constructor" field in Angular expressions '+
|
||||
'is disallowed! Expression: constructor.keys({})');
|
||||
});
|
||||
|
||||
it('should NOT allow access to Object constructor in getter', function() {
|
||||
expect(function() {
|
||||
scope.$eval('{}["constructor"]');
|
||||
}).toThrowMinErr(
|
||||
'$parse', 'isecobj', 'Referencing Object in Angular expressions is disallowed! ' +
|
||||
'Expression: {}["constructor"]');
|
||||
});
|
||||
|
||||
it('should NOT allow access to Object constructor that has been aliased', function() {
|
||||
scope.foo = { "bar": Object };
|
||||
expect(function() {
|
||||
scope.$eval('foo["bar"]');
|
||||
}).toThrowMinErr(
|
||||
'$parse', 'isecobj', 'Referencing Object in Angular expressions is disallowed! ' +
|
||||
'Expression: foo["bar"]');
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
it('should call the function once when it is part of the context on property lookup function', function() {
|
||||
var count = 0;
|
||||
|
||||
Reference in New Issue
Block a user