My create-react-app
was working fine and after no modification my console displayed Content Security Policy: The page’s settings blocked the loading of a resource at inline (“script-src”).
(mozilla browser, no error on Chrome).
On both browsers the display is white : I can't see my app content anymore.
./public/index.html
file :
With the help of the MDN doc.<!DOCTYPE html> <html lang="en"> <head> <!-- commented out to solve issue : <script id="Cookiebot" src="https://consent.cookiebot.com/uc.js" data-cbid=string_of_my_key data-blockingmode="auto" type="text/javascript"></script> --> <!-- the <meta> I tried to solve my problem : --> <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline' 'unsafe-eval' https://otherurl.com/ https://*.otherurl2.com/ " /> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <meta name="theme-color" content="#000000" /> <link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico?v=2" /> <link rel="apple-touch-icon" sizes="76x76" href="%PUBLIC_URL%/apple-icon.png" /> <link rel="stylesheet" type="text/css" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Roboto+Slab:400,700|Material+Icons" /> <link href="https://use.fontawesome.com/releases/v5.0.10/css/all.css" rel="stylesheet" /> <title>My title</title> </head> <body> <noscript> You need to enable JavaScript to run this app. </noscript> <div id="root"></div> <!-- also commented out for when I'll solve the problem <script id="CookieDeclaration" src="https://consent.cookiebot.com/string_of_my_key/cd.js" type="text/javascript" async></script> --> </body> </html>
- First I did add the
'self'
keyword, which made me get an error for each services using something other thanhttp://localhost:3000
. - So I did add the corresponding foreign URLs one by one after each error appearing.
- After seeing
Content Security Policy: The page’s settings blocked the loading of a resource at eval (“script-src”).
I added'unsafe-eval'
. It stops showing this error. - Then I have the error I show you in my first sentence. I add
'unsafe-inline'
to test but nothing changes.
- First I did add the
- I did make a new branch, and removed commits one by one to see when the error appears. For each
git reset --hard HEAD~1
I see the same error in the browser console. - I tried to compile the
/public
folder. - No Google result or Sackoverflow helped me for now (searching yesterday afternoon to today right now. I hope I'm just bad at searching)
I never had to deal with this before in my react applications.
UPDATES
- I'm using Material-UI, maybe it could influence
- I tried to add
INLINE_RUNTIME_CHUNK=false
to.env
file like this, then rebuild and deploy. It didn't change anything - I commented out all recent
<a>
, and<img required("...") />
tags to make sure I'm not in this case. - EDIT : replace html sample with full
index.html
code.