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

Commit bc6fb7c

Browse files
thejhIgorMinar
authored andcommittedJun 30, 2014
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 4ab16aa: ''.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.
1 parent 0c80df2 commit bc6fb7c

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
 

‎src/ng/parse.js

+5
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ function ensureSafeObject(obj, fullExpression) {
5959
throw $parseMinErr('isecdom',
6060
'Referencing DOM nodes in Angular expressions is disallowed! Expression: {0}',
6161
fullExpression);
62+
} else if (// isObject(obj)
63+
obj.getOwnPropertyNames || obj.getOwnPropertyDescriptor) {
64+
throw $parseMinErr('isecobj',
65+
'Referencing Object in Angular expressions is disallowed! Expression: {0}',
66+
fullExpression);
6267
}
6368
}
6469
return obj;

‎test/ng/parseSpec.js

+27
Original file line numberDiff line numberDiff line change
@@ -918,6 +918,33 @@ describe('parser', function() {
918918
expect(count).toBe(1);
919919
});
920920

921+
describe('Object constructor', function() {
922+
it('should NOT allow access to scope constructor', function() {
923+
expect(function() {
924+
scope.$eval('constructor.keys({})');
925+
}).toThrowMinErr(
926+
'$parse', 'isecfld', 'Referencing "constructor" field in Angular expressions '+
927+
'is disallowed! Expression: constructor.keys({})');
928+
});
929+
930+
it('should NOT allow access to Object constructor in getter', function() {
931+
expect(function() {
932+
scope.$eval('{}["constructor"]');
933+
}).toThrowMinErr(
934+
'$parse', 'isecobj', 'Referencing Object in Angular expressions is disallowed! ' +
935+
'Expression: {}["constructor"]');
936+
});
937+
938+
it('should NOT allow access to Object constructor that has been aliased', function() {
939+
scope.foo = { "bar": Object };
940+
expect(function() {
941+
scope.$eval('foo["bar"]');
942+
}).toThrowMinErr(
943+
'$parse', 'isecobj', 'Referencing Object in Angular expressions is disallowed! ' +
944+
'Expression: foo["bar"]');
945+
946+
});
947+
});
921948

922949
it('should call the function once when it is part of the context on property lookup function', function() {
923950
var count = 0;

0 commit comments

Comments
 (0)
This repository has been archived.