This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CSP (content security policy) forbids apps to use eval or Function(string) generated functions (among other things). For us to be compatible, we just need to implement the "getterFn" in $parse without violating any of these restrictions. We currently use Function(string) generated functions as a speed optimization. With this change, it will be possible to opt into the CSP compatible mode using the ngCsp directive. When this mode is on Angular will evaluate all expressions up to 30% slower than in non-CSP mode, but no security violations will be raised. In order to use this feature put ngCsp directive on the root element of the application. For example: <!doctype html> <html ng-app ng-csp> ... ... </html> Closes #893
- Loading branch information
Showing
7 changed files
with
544 additions
and
397 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
'use strict'; | ||
|
||
/** | ||
* TODO(i): this directive is not publicly documented until we know for sure that CSP can't be | ||
* safely feature-detected. | ||
* | ||
* @name angular.module.ng.$compileProvider.directive.ngCsp | ||
* @priority 1000 | ||
* | ||
* @description | ||
* Enables CSP (Content Security Protection) support. This directive should be used on the `<html>` | ||
* element before any kind of interpolation or expression is processed. | ||
* | ||
* If enabled the performance of $parse will suffer. | ||
* | ||
* @element html | ||
*/ | ||
|
||
var ngCspDirective = ['$sniffer', function($sniffer) { | ||
return { | ||
priority: 1000, | ||
compile: function() { | ||
$sniffer.csp = true; | ||
} | ||
}; | ||
}]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
|
||
describe('ngCsp', function() { | ||
|
||
it('it should turn on CSP mode in $sniffer', inject(function($sniffer, $compile) { | ||
expect($sniffer.csp).toBe(false); | ||
$compile('<div ng-csp></div>'); | ||
expect($sniffer.csp).toBe(true); | ||
})); | ||
}); |
Oops, something went wrong.