fix($parse): check function call context to be safe

Closes #4417
This commit is contained in:
Chirayu Krishnappa 2013-10-14 16:05:53 -07:00 committed by Igor Minar
parent 3aefd3a4f0
commit 6d324c76f0
2 changed files with 15 additions and 0 deletions

View file

@ -754,6 +754,7 @@ Parser.prototype = {
}
var fnPtr = fn(scope, locals, context) || noop;
ensureSafeObject(context, parser.text);
ensureSafeObject(fnPtr, parser.text);
// IE stupidity! (IE doesn't have apply for some native functions)

View file

@ -730,6 +730,20 @@ describe('parser', function() {
'$parse', 'isecdom', 'Referencing DOM nodes in Angular expressions is ' +
'disallowed! Expression: getDoc()');
}));
it('should NOT allow calling functions on Window or DOM', inject(function($window, $document) {
scope.a = {b: { win: $window, doc: $document }};
expect(function() {
scope.$eval('a.b.win.alert(1)', scope);
}).toThrowMinErr(
'$parse', 'isecwindow', 'Referencing the Window in Angular expressions is ' +
'disallowed! Expression: a.b.win.alert(1)');
expect(function() {
scope.$eval('a.b.doc.on("click")', scope);
}).toThrowMinErr(
'$parse', 'isecdom', 'Referencing DOM nodes in Angular expressions is ' +
'disallowed! Expression: a.b.doc.on("click")');
}));
});
});