If I implement CSP 2.0 on my angular app, and forbid unsafe-inline from script-src, would ng-click and other angular events work? I guess CSP will block all these.
AngularJS and Content-Security-Policy are well documented under the ngCsp directive. Here are how the unsafe rules affect Angular:
unsafe-eval: this rule forbids apps to useevalorFunction(string)generated functions (among other things). Angular makes use of this in the $parse service to provide a 30% increase in the speed of evaluating Angular expressions.
unsafe-inline: this rule forbids apps from inject custom styles into the document. Angular makes use of this to include some CSS rules (e.g.ngCloakandngHide). To make these directives work when a CSP rule is blocking inline styles, you must link to theangular-csp.cssin your HTML manually.
Specifically ngClick uses an AngularJS expression...
<ANY
ng-click="expression">
...
</ANY>
...and an AngularJS expression does not need eval.
Angular does not use JavaScript's
eval()to evaluate expressions. Instead Angular's$parseservice processes these expressions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With