I'm trying to use Google Fonts and I've never had any problems, but now when I try to add the CSS file on my header I get this error on the console:
Refused to load the stylesheet 'http://fonts.googleapis.com/css?family=Whatever'
because it violates the following Content Security Policy directive: "style-src 'self' 'unsafe-inline'"
.
There are two things to fix here:
https://fonts.googleapis.com/css?family=Whatever
)https://fonts.googleapis.com
instyle-src
directive andhttps://fonts.gstatic.com
infont-src
directive:"style-src 'self' https://fonts.googleapis.com; font-src 'self' https://fonts.gstatic.com"
If you're like me and a little confused because every answer is just saying you need to authorize a URL in a
style-src
directive without showing how to do it, here's the full tag:When working with Helmet, the following works perfectly (written in TypeScript):
There are multiple sources that can be given for
Content-Security-Policy
.Below has clear details, which worked for me.
Depending on which content (css, img, font, media) source error you have, you can change the URL in the below.
Hope that helps.