-
Notifications
You must be signed in to change notification settings - Fork 26.2k
Make Angular2 works with restrictive Content Security Policy (CSP) #11939
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Can you clearly state what causes the issue ? |
Here's the console error that I'm getting: zone.js:344 Unhandled Promise rejection: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self'".
zone.js:346 Error: Uncaught (in promise): EvalError: Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src 'self'".(…)consoleError @ zone.js:346 |
Also want to confirm this: |
@manklu and @vicb, thank you for your prompt reply. I was able to do a offline template compile based on instruction here: Looking forward for this issue (#6361) to be answered. We have to make our web app works in restrictive CSP mode. |
The issue is not only to make angular work with CSP but to make angular cli work with CSP as well. It would be wonderfull if angular + angular-cli could actually be used to create something secure. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
I'm submitting a ... (check one with "x")
Current behavior
We are working on a brand new project with restrict CSP(Content Security Policy) requirement. Here's our CSP requirement: X-Content-Security-Policy:default-src 'self'; style-src 'self' 'unsafe-inline'
This has been set through headers.
For our production setting, we've bundled all source files and templates (with system builder) during build process. While the app loading in CSP strict mode, we see the same issue as this one: https://stackoverflow.com/questions/38734708/make-angular2-works-with-restrictive-content-security-policy-csp
Searched all possible solutions, offline template compiler seems to be a way to solve the issue. However, we could not find a valid offline template compiler yet.
Things we've tried so far - (with the Angular 2 production release)
https://github.com/smmorneau/tour-of-heroes -- tested the build process, the output doesn't work in restrict CSP mode.
Angular cli tool: Does not support offline template compiler yet?
https://www.npmjs.com/package/angular2-template-compiler : This seems to be outdated. Got this: "Error: Cannot find module '@angular/compiler/src/html_parser' ..... at Object....."
compiler-cli (https://github.com/angular/angular/tree/master/modules/%40angular/compiler-cli): Could not get it to work. Is this one ready for production yet?
Also by search through the angular 2 core files, I see https://npmcdn.com/@angular/core@2.0.0/bundles/core.umd.js has 5 "new Function()" calls. This is outside template compiler. Even I can get the offline template compiler works, could this trigger the "unsafe-eval" from browser?
Expected behavior
Does the Angular 2 currently support restrictive Content Security Policy ? If yes, what should we do to make it work?
Reproduction of the problem
What is the motivation / use case for changing the behavior?
We really need to make our web app works in restrictive Content Security Policy mode, can be get a clear answer for this?
Please tell us about your environment:
We'are using the Angular 2 production release version.
Angular version: 2.0.X
Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
Language: [all | TypeScript X.X | ES6/7 | ES5]
Node (for AoT issues):
node --version
=The text was updated successfully, but these errors were encountered: