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

Commit 77ada4c

Browse files
rodyhaddadIgorMinar
authored andcommittedJun 30, 2014
fix($parse): prevent invocation of Function's bind, call and apply
BREAKING CHANGE: You can no longer invoke .bind, .call or .apply on a function in angular expressions. This is to disallow changing the behaviour of existing functions in an unforseen fashion.
1 parent db713a1 commit 77ada4c

File tree

3 files changed

+75
-0
lines changed

3 files changed

+75
-0
lines changed
 
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
@ngdoc error
2+
@name $parse:isecff
3+
@fullName Referencing 'call', 'apply' and 'bind' Disallowed
4+
@description
5+
6+
Occurs when an expression attempts to invoke Function's 'call', 'apply' or 'bind'.
7+
8+
Angular bans the invocation of 'call', 'apply' and 'bind' from within expressions
9+
since access is a known way to modify the behaviour of existing functions.
10+
11+
To resolve this error, avoid using these methods in expressions.
12+
13+
Example expression that would result in this error:
14+
15+
```
16+
<div>{{user.sendInfo.call({}, true)}}</div>
17+
```

‎src/ng/parse.js

+8
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,20 @@ function ensureSafeObject(obj, fullExpression) {
6262
return obj;
6363
}
6464

65+
var CALL = Function.prototype.call;
66+
var APPLY = Function.prototype.apply;
67+
var BIND = Function.prototype.bind;
68+
6569
function ensureSafeFunction(obj, fullExpression) {
6670
if (obj) {
6771
if (obj.constructor === obj) {
6872
throw $parseMinErr('isecfn',
6973
'Referencing Function in Angular expressions is disallowed! Expression: {0}',
7074
fullExpression);
75+
} else if (obj === CALL || obj === APPLY || obj === BIND) {
76+
throw $parseMinErr('isecff',
77+
'Referencing call, apply or bind in Angular expressions is disallowed! Expression: {0}',
78+
fullExpression);
7179
}
7280
}
7381
}

‎test/ng/parseSpec.js

+50
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,56 @@ describe('parser', function() {
695695
});
696696
});
697697

698+
describe('Function prototype functions', function () {
699+
it('should NOT allow invocation to Function.call', function() {
700+
scope.fn = Function.prototype.call;
701+
702+
expect(function() {
703+
scope.$eval('$eval.call()')
704+
}).toThrowMinErr(
705+
'$parse', 'isecff', 'Referencing call, apply or bind in Angular expressions is disallowed! ' +
706+
'Expression: $eval.call()');
707+
708+
expect(function() {
709+
scope.$eval('fn()')
710+
}).toThrowMinErr(
711+
'$parse', 'isecff', 'Referencing call, apply or bind in Angular expressions is disallowed! ' +
712+
'Expression: fn()');
713+
});
714+
715+
it('should NOT allow invocation to Function.apply', function() {
716+
scope.apply = Function.prototype.apply;
717+
718+
expect(function() {
719+
scope.$eval('$eval.apply()')
720+
}).toThrowMinErr(
721+
'$parse', 'isecff', 'Referencing call, apply or bind in Angular expressions is disallowed! ' +
722+
'Expression: $eval.apply()');
723+
724+
expect(function() {
725+
scope.$eval('apply()')
726+
}).toThrowMinErr(
727+
'$parse', 'isecff', 'Referencing call, apply or bind in Angular expressions is disallowed! ' +
728+
'Expression: apply()');
729+
});
730+
731+
it('should NOT allow invocation to Function.bind', function() {
732+
scope.bind = Function.prototype.bind;
733+
734+
expect(function() {
735+
scope.$eval('$eval.bind()')
736+
}).toThrowMinErr(
737+
'$parse', 'isecff', 'Referencing call, apply or bind in Angular expressions is disallowed! ' +
738+
'Expression: $eval.bind()');
739+
740+
expect(function() {
741+
scope.$eval('bind()')
742+
}).toThrowMinErr(
743+
'$parse', 'isecff', 'Referencing call, apply or bind in Angular expressions is disallowed! ' +
744+
'Expression: bind()');
745+
});
746+
});
747+
698748
describe('Object constructor', function() {
699749

700750
it('should NOT allow access to Object constructor that has been aliased', function() {

0 commit comments

Comments
 (0)
This repository has been archived.