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

Commit

Permalink
fix($parse): check function call context to be safe
Browse files Browse the repository at this point in the history
Closes #4417
  • Loading branch information
chirayuk authored and IgorMinar committed Oct 15, 2013
1 parent 3aefd3a commit 6d324c7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ng/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions test/ng/parseSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")');
}));
});
});

Expand Down

0 comments on commit 6d324c7

Please sign in to comment.