question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use of `eval` in development mode violates Content-Security-Policy

See original GitHub issue

Version

4.4.0-beta.7

Test Case

CodeSandbox doesn’t support adding CSP, but it would look like this:

<html>
<head>
  <meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'self'; style-src 'self' 'unsafe-inline';" />
</head>
<body>
  <div id="root"></div>
  <script src="index.js"></script>
</body>
</html>

Steps to reproduce

Import react-router in some file, launch app in development mode.

Expected Behavior

Things loading fine with CSP enabled.

Actual Behavior

Browser blocks execution of react-router.js because it uses eval:

screen shot 2019-03-03 at 4 57 22 am screen shot 2019-03-03 at 5 06 36 am

Is there a way of implementing your current logic without eval?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
emmenkocommented, Mar 5, 2019

Having the same issue, I was about to report it as well. It was introduced here

https://github.com/ReactTraining/react-router/blob/b2c6fa0725b7ff1ed762064d633b26b6293e0140/packages/react-router/modules/index.js#L1-L20

@mjackson what was the reason for using eval?

0reactions
unindentedcommented, Mar 15, 2019

@mjackson verified on my app, this is working perfectly. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use of `eval` in development mode violates Content-Security ...
Import react-router in some file, launch app in development mode. Expected Behavior. Things loading fine with CSP enabled. Actual Behavior.
Read more >
How to fix 'because it violates the following content security ...
Content Security Policy blocks all resources that don't match it's policy. To view the policy for a specific website use the CSP Evaluator....
Read more >
Content security policy - web.dev
This is a great way to evaluate the effect of changes to your application's CSP: turn on reporting for a new policy, monitor...
Read more >
Webpack dev server React Content Security Policy error
If you use Webpack in your project, please add output.publicPath = '/' and devServer.historyApiFallback = true in your webpack config file.
Read more >
Use Tag Manager with a Content Security Policy
They can be used to create custom tags and variables that do not require the use of 'unsafe-eval' . Preview Mode. In order...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found