Skip to content
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

Refused to execute inline script because it violates the following Content Security Policy directive #53

Open
henrymcbean opened this issue May 9, 2021 · 6 comments

Comments

@henrymcbean
Copy link

Exported my Node API calls from Postman then used Docgen to generate my index.html file then copied to the root of my public folder. When I view the html file via my node server in the browser I am getting a console errors. The first error complained about the favicon.ico so I copied one to the public folder which removed the error. I am unable to remove the CSP error after trying suggested methods in the error using Helmet middleware options.

If open html file directly with the browser I don't get the CSP error so it only happens when I accessing the file via Node API server root. Please advice, full error listed below.

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'". Either the 'unsafe-inline' keyword, a hash ('sha256-ZomnyosL2bmZ79LmErHEhL+1fVaBj9NngvpOK/l4qio='), or a nonce ('nonce-...') is required to enable inline execution.

@jcsuazo
Copy link

jcsuazo commented Jun 27, 2021

For me is the same

@saiteja13427
Copy link

Facing exactly same issue, this need to be solved

@VighneshManjrekar
Copy link

I moved inline script to new js file and it worked for me.

@hassanaref
Copy link

hassanaref commented Jul 16, 2022

I moved inline script to new js file and it worked for me.

but how ?

@tedsemashov
Copy link

  1. Open index.html file
  2. Grab all functionality from <script> ............. </script>
  3. Create new file FE: js.js near the index.html
  4. Paste functionality from script tag into new js.js file
  5. Connect js file into index.html file -> <script src="js.js"></script>

@markCwatson
Copy link

This also worked for me (i.e. the comments from @VighneshManjrekar )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants