最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to use Content-Security-Policy with localhost files - Stack Overflow

programmeradmin2浏览0评论

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 pletely 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.

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 pletely 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.

Share Improve this question asked Jan 3, 2018 at 16:27 Jamie HutberJamie Hutber 28.1k54 gold badges194 silver badges311 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

You can use localhost:, though I believe using 'self' (including the single quotes) 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.

发布评论

评论列表(0)

  1. 暂无评论