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

Commit 6d324c7

Browse files
chirayukIgorMinar
authored andcommitted
fix($parse): check function call context to be safe
Closes #4417
1 parent 3aefd3a commit 6d324c7

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/ng/parse.js

+1
Original file line numberDiff line numberDiff line change
@@ -754,6 +754,7 @@ Parser.prototype = {
754754
}
755755
var fnPtr = fn(scope, locals, context) || noop;
756756

757+
ensureSafeObject(context, parser.text);
757758
ensureSafeObject(fnPtr, parser.text);
758759

759760
// IE stupidity! (IE doesn't have apply for some native functions)

test/ng/parseSpec.js

+14
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,20 @@ describe('parser', function() {
730730
'$parse', 'isecdom', 'Referencing DOM nodes in Angular expressions is ' +
731731
'disallowed! Expression: getDoc()');
732732
}));
733+
734+
it('should NOT allow calling functions on Window or DOM', inject(function($window, $document) {
735+
scope.a = {b: { win: $window, doc: $document }};
736+
expect(function() {
737+
scope.$eval('a.b.win.alert(1)', scope);
738+
}).toThrowMinErr(
739+
'$parse', 'isecwindow', 'Referencing the Window in Angular expressions is ' +
740+
'disallowed! Expression: a.b.win.alert(1)');
741+
expect(function() {
742+
scope.$eval('a.b.doc.on("click")', scope);
743+
}).toThrowMinErr(
744+
'$parse', 'isecdom', 'Referencing DOM nodes in Angular expressions is ' +
745+
'disallowed! Expression: a.b.doc.on("click")');
746+
}));
733747
});
734748
});
735749

0 commit comments

Comments
 (0)