How to use Content-Security-Policy with localhost files

无人久伴 提交于 2019-12-24 15:27:43

问题


I am getting the following error on my page:

Refused to load the script 'http://127.0.0.1:35729/livereload.js' because it violates the following Content Security Policy directive: "script-src https: 'unsafe-inline' 'unsafe-eval'".

HTML

<meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline'; style-src * 'unsafe-inline'; script-src * 'unsafe-inline' 'unsafe-eval'; img-src * data: 'unsafe-inline'; connect-src * 'unsafe-inline'; frame-src *;">
 </head>
 <body>
    <script src="http://127.0.0.1:35729/livereload.js"></script>

I have tried to use a completely open just to get it working and then work backwards, however I even get the same error with this.

To be clear, this isn't for producition code, this is just to enable my live-reload-webpack on a domain that is using https.


回答1:


You can use localhost:, though I believe using 'self' would also suffice in this situation. There are some odd cases where * is not actually all-inclusive (blob: for example is also excluded from * I believe).

As always it's good to check out your CSP with Google's Evaluator first.



来源:https://stackoverflow.com/questions/48081328/how-to-use-content-security-policy-with-localhost-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!