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

Commit 794b770

Browse files
refact($parse): remove Angular expression sandbox
The angular expression parser (`$parse`) attempts to sandbox expressions to prevent unrestricted access to the global context. While the sandbox was not on the frontline of the security defense, developers kept relying upon it as a security feature even though it was always possible to access arbitrary JavaScript code if a malicious user could control the content of Angular templates in applications. This commit removes this sandbox, which has the following benefits: * it sends a clear message to developers that they should not rely on the sandbox to prevent XSS attacks; that they must prevent control of expression and templates instead. * it allows performance and size improvements in the core Angular 1 library. * it simplifies maintenance and provides opportunities to make the parser more capable. Please see the [Sandbox Removal Blog Post](XXXX) for more detail on what you should do to ensure that your application is secure.
1 parent 854da35 commit 794b770

File tree

1 file changed

+4
-23
lines changed

1 file changed

+4
-23
lines changed

src/ng/parse.js

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,7 @@
1313

1414
var $parseMinErr = minErr('$parse');
1515

16-
var ARRAY_CTOR = [].constructor;
17-
var BOOLEAN_CTOR = (false).constructor;
18-
var FUNCTION_CTOR = Function.constructor;
19-
var NUMBER_CTOR = (0).constructor;
20-
var OBJECT_CTOR = {}.constructor;
21-
var STRING_CTOR = ''.constructor;
22-
var ARRAY_CTOR_PROTO = ARRAY_CTOR.prototype;
23-
var BOOLEAN_CTOR_PROTO = BOOLEAN_CTOR.prototype;
24-
var FUNCTION_CTOR_PROTO = FUNCTION_CTOR.prototype;
25-
var NUMBER_CTOR_PROTO = NUMBER_CTOR.prototype;
26-
var OBJECT_CTOR_PROTO = OBJECT_CTOR.prototype;
27-
var STRING_CTOR_PROTO = STRING_CTOR.prototype;
28-
29-
var CALL = FUNCTION_CTOR_PROTO.call;
30-
var APPLY = FUNCTION_CTOR_PROTO.apply;
31-
var BIND = FUNCTION_CTOR_PROTO.bind;
32-
33-
var objectValueOf = OBJECT_CTOR_PROTO.valueOf;
16+
var objectValueOf = {}.constructor.prototype.valueOf;
3417

3518
// Sandboxing Angular Expressions
3619
// ------------------------------
@@ -1696,7 +1679,7 @@ function getValueOf(value) {
16961679
* service.
16971680
*/
16981681
function $ParseProvider() {
1699-
var cacheDefault = createMap();
1682+
var cache = createMap();
17001683
var literals = {
17011684
'true': true,
17021685
'false': false,
@@ -1768,17 +1751,15 @@ function $ParseProvider() {
17681751
exp = exp.trim();
17691752
cacheKey = exp;
17701753

1771-
var cache = cacheDefault;
17721754
parsedExpression = cache[cacheKey];
17731755

17741756
if (!parsedExpression) {
17751757
if (exp.charAt(0) === ':' && exp.charAt(1) === ':') {
17761758
oneTime = true;
17771759
exp = exp.substring(2);
17781760
}
1779-
var parseOptions = $parseOptions;
1780-
var lexer = new Lexer(parseOptions);
1781-
var parser = new Parser(lexer, $filter, parseOptions);
1761+
var lexer = new Lexer($parseOptions);
1762+
var parser = new Parser(lexer, $filter, $parseOptions);
17821763
parsedExpression = parser.parse(exp);
17831764
if (parsedExpression.constant) {
17841765
parsedExpression.$$watchDelegate = constantWatchDelegate;

0 commit comments

Comments
 (0)