|
11 | 11 | * This is necessary when developing things like Google Chrome Extensions.
|
12 | 12 | *
|
13 | 13 | * CSP forbids apps to use `eval` or `Function(string)` generated functions (among other things).
|
14 |
| - * For us to be compatible, we just need to implement the "getterFn" in $parse without violating |
15 |
| - * any of these restrictions. |
| 14 | + * For Angular to be CSP compatible there are only two things that we need to do differently: |
| 15 | + * |
| 16 | + * - don't use `Function` constructor to generate optimized value getters |
| 17 | + * - don't inject custom stylesheet into the document |
16 | 18 | *
|
17 | 19 | * AngularJS uses `Function(string)` generated functions as a speed optimization. Applying the `ngCsp`
|
18 | 20 | * directive will cause Angular to use CSP compatibility mode. When this mode is on AngularJS will
|
|
23 | 25 | * includes some CSS rules (e.g. {@link ng.directive:ngCloak ngCloak}).
|
24 | 26 | * To make those directives work in CSP mode, include the `angular-csp.css` manually.
|
25 | 27 | *
|
26 |
| - * In order to use this feature put the `ngCsp` directive on the root element of the application. |
| 28 | + * Angular tries to autodetect if CSP is active and automatically turn on the CSP-safe mode. This |
| 29 | + * autodetection however triggers a CSP error to be logged in the console: |
| 30 | + * |
| 31 | + * ``` |
| 32 | + * Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of |
| 33 | + * script in the following Content Security Policy directive: "default-src 'self'". Note that |
| 34 | + * 'script-src' was not explicitly set, so 'default-src' is used as a fallback. |
| 35 | + * ``` |
| 36 | + * |
| 37 | + * This error is harmless but annoying. To prevent the error from showing up, put the `ngCsp` |
| 38 | + * directive on the root element of the application or on the `angular.js` script tag, whichever |
| 39 | + * appears first in the html document. |
27 | 40 | *
|
28 | 41 | * *Note: This directive is only available in the `ng-csp` and `data-ng-csp` attribute form.*
|
29 | 42 | *
|
|
38 | 51 | ```
|
39 | 52 | */
|
40 | 53 |
|
41 |
| -// ngCsp is not implemented as a proper directive any more, because we need it be processed while we bootstrap |
42 |
| -// the system (before $parse is instantiated), for this reason we just have a csp() fn that looks for ng-csp attribute |
43 |
| -// anywhere in the current doc |
| 54 | +// ngCsp is not implemented as a proper directive any more, because we need it be processed while we |
| 55 | +// bootstrap the system (before $parse is instantiated), for this reason we just have |
| 56 | +// the csp.isActive() fn that looks for ng-csp attribute anywhere in the current doc |
0 commit comments