拒绝连接到“http://someURL”,因为它违反了以下内容安全策略指令:“connect-src http://someURL”

拒绝连接到“http://someURL”,因为它违反了以下内容安全策略指令:“connect-src http://someURL”

好吧,这是我的浏览器控制台出现的错误,我正在处理一个域,该域只有一个子域,但我仍然无法访问该子域。实际上,我还收到了一些其他错误。

我猜我的错误是在add_header Content-Security-Policy,在connect-src部分。:这是域部分和Content-Security-Policy

server {
    large_client_header_buffers 1 1K;

    listen       80;
    server_name  www.just4bettors.mobi  just4bettors.mobi;
    root   /home/c0pt/capilleira/capilleiraclickandgamblemobile/www;

    location / {
        index  index.html index.htm;
        ...
    }

    add_header Content-Security-Policy
    "default-src 'self' http://just4bettors.mobi:1337;
     connect-src http://just4bettors.mobi
                 http://just4bettors.mobi:1337
                 http://www.just4bettors.mobi
                 http://www.just4bettors.mobi:1337";
}

这是子域名的部分:

server {
   listen 80;
   server_name www.desktop.just4bettors.mobi  desktop.just4bettors.mobi;
   root   /home/c0pt/capilleira/capilleiraclickandgambleweb/dist;
   location / {
        index index.html index.htm;
        ...
   }

   add_header Content-Security-Policy add_header
   "default-src 'self' http://www.just4bettors.mobi;
    connect-src http://just4bettors.mobi
                http://just4bettors.mobi:1337
                http://www.just4bettors.mobi
                http://www.just4bettors.mobi:1337
                http://www.desktop.just4bettors.mobi:1337
                http://www.desktop.just4bettors.mobi";
}

我在控制台中遇到的这部分错误

Refused to connect to 'http://www.desktop.just4bettors.mobi/views/accFiguresModal.html' because it violates the following Content Security Policy directive: "connect-src http://just4bettors.mobi http://just4bettors.mobi:1337 http://www.just4bettors.mobi http://www.just4bettors.mobi:1337".

这个问题实际上只在我尝试连接时才会出现www.desktop.just4bettors.mobi,但如果我把www.just4bettors.mobi一切都正常

那么,我的错误在哪里?

答案1

尝试将标题 Content-Security-Policy 添加到您的元标记中:

"connect-src http://just4bettors.mobi http://just4bettors.mobi:1337 http://www.just4bettors.mobi http://www.desktop.just4bettors.mobi;"

完整的元标记如下:

"default-src 'self' http://www.just4bettors.mobi; script-src 'self' 'unsafe-inline' 'unsafe-eval'; img-src 'self' http://placehold.it https://ssl.google-analytics.com https://s-static.ak.facebook.com https://assets.zendesk.com; style-src 'self' 'unsafe-inline' https://fonts.googleapis.com https://fonts.gstatic.com  https://themes.googleusercontent.com https://assets.zendesk.com; font-src 'self' https://themes.googleusercontent.com https://fonts.gstatic.com; frame-src 'self'; object-src 'none'; connect-src http://just4bettors.mobi http://just4bettors.mobi:1337 http://www.just4bettors.mobi http://www.desktop.just4bettors.mobi;"

相关内容