-
Notifications
You must be signed in to change notification settings - Fork 2.1k
fetch for SVG source result in CSP violations. #1025
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
Thanks. Can you provide a GitHub repo I can use to reproduce this issue? |
We are running into the same issue. I am not sure it is something that can easily be put into a GitHub repo because it relates to the CSP headers for the server hosting the web application that uses ionic vs. the application code. If CSP is allowed to fetch anything then that could introduce security risks for the application beyond ion-icon usage (e.g. XSS). A simplified version of what we were using in the header is:
Here is the error:
In this case the icons fail because it is trying to fetch I think ionic added the code to be able to bundle icons in the code vs. as external files. Instead of using fetch you could simply use a regex or string patterns to get the svg content without a fetch and avoid any CSP problems. Longer term it could also be made more efficient with bypassing intersection observers, creating Dom nodes to get the innerHTML, etc. We were able to get around the issue by changing the CSP header but I am worried about potential security risks. It works with:
Here is a good discussion of risks associated with |
We also experienced this issue after updating our Ionic 5 app to Ionic 6. We were able to modify the CSP header, but we are worried about the security risks. It would be great if there was an other solution to this issue. |
There is another solution without enable "content-security-policy: connect-src 'self' data:" change and replace
|
We also have this issue after upgrading to ionic 6. As mentioned in the link on the first post, the way the icons are defined + loaded clashes with a recommended secure CSP policy (ie not using the data: scheme in connect-src).
This obviously isn't an issue unique to ionic but would appreciate a way to implement a secure CSP policy for serving ionic icons for PWAs. |
Hey Liam, I've created a sample reproduction here: |
Thanks for the issue. This has been resolved via #1141, and a fix will be available in an upcoming release of Ionicons. Ionic Framework will also be updated to advantage of this fix. |
It looks like the icons are loaded with
fetch
viadata:
schemahttps://github.com/ionic-team/ionicons/blob/main/src/components/icon/request.ts#L13
With
Content Security Policy
headers enabled, theconnect-src
directive will block the icons from loading, unless if we also allowdata:
source.However, this is not a safe practice. https://security.stackexchange.com/questions/94993/is-including-the-data-scheme-in-your-content-security-policy-safe
I am curious, why is
fetch
used to load local resources?The text was updated successfully, but these errors were encountered: