iOS 拒绝连接,因为它既没有出现在内容安全策略的 connect-src 指令中,也没有出现在 default-src 指令中

iOS Refused to connect because it appears in neither the connect-src directive nor the default-src directive of the Content Security Policy

所以我制作了一个 phonegap 应用程序,它使用 socket.io 来做一些事情。
我有以下内容安全策略 (CSP)

<meta http-equiv="Content-Security-Policy" content="
                                default-src * data: blob: ws: wss:;
                                style-src * 'unsafe-inline'; 
                                script-src * 'unsafe-inline' 'unsafe-eval';
                                connect-src * ws: wss:;">

当我在 safari 上启动应用程序时 / iOS 我收到以下错误:

Refused to connect to ws://10.0.1.63:3000/socket.io/?EIO=3&transport=websocket&sid=xTaMJwP3rVy3UnIBAAAi 
because it appears in neither the connect-src directive nor the default-src directive of the Content Security Policy.

并且:

SecurityError (DOM Exception 18): The operation is insecure.

具有相同 CSP 的相同应用程序在 Chrome / Android 上运行良好,但在 Safari / iOS.
上运行良好 我认为这与以下内容有关:
a refined content security policy (WebKit)

似乎经常出现的资源:

为什么说 "Refused to connect to "URL 以 ws: 开头,因为它既没有出现在 Content-Security-Policy 的 connect-src 指令和 default-src 指令中,即使它两者都提到了?

好吧,safari/iOS 在这方面比 chrome/Android 更严格,没问题,但它仍然需要让我允许连接通过.这对应用程序开发人员来说真的很令人沮丧!解决方案?

编辑: 在 bugs.webkit.org 上提交错误报告:https://bugs.webkit.org/show_bug.cgi?id=165754

好吧,这有点愚蠢,但是好吧,我会保留这个答案,这样以后的人就可以看到它,而不必处理这个问题

我做错的是:
我有以下头部:

<head>
    <meta charset="utf-8" />
    <!--<meta http-equiv="Content-Security-Policy" 
    content="default-src *; style-src 'self' http://* 'unsafe-inline'; script-src 'self' http://* 'unsafe-inline' 'unsafe-eval'" />-->
    <meta http-equiv="Content-Security-Policy" content="
                            default-src * data: blob: ws: wss: gap://ready file://*;
                            style-src * 'unsafe-inline'; 
                            script-src * 'unsafe-inline' 'unsafe-eval';
                            connect-src * ws: wss:;">
    <meta name="format-detection" content="telephone=no" />
    <meta name="msapplication-tap-highlight" content="no" />
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width" />
    <meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline'; style-src 'self' 'unsafe-inline'; media-src"/>
    <link rel="stylesheet" type="text/css" href="css/reset.css" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <title>Kerst app!</title>
</head>

而且我没有注意到我有两次 "Content-Security-Policy" 元标记
我知道,对吧?重复导致 iOS 只采用最新的一个更严格的。删除了重复项,第一次工作。

最后是正确的代码

<head>
    <meta charset="utf-8" />
    <!--<meta http-equiv="Content-Security-Policy" 
    content="default-src *; style-src 'self' http://* 'unsafe-inline'; script-src 'self' http://* 'unsafe-inline' 'unsafe-eval'" />-->
    <meta http-equiv="Content-Security-Policy" content="
                            default-src * data: blob: ws: wss: gap://ready file://*;
                            style-src * 'unsafe-inline'; 
                            script-src * 'unsafe-inline' 'unsafe-eval';
                            connect-src * ws: wss:;">
    <meta name="format-detection" content="telephone=no" />
    <meta name="msapplication-tap-highlight" content="no" />
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width" />
    <link rel="stylesheet" type="text/css" href="css/reset.css" />
    <link rel="stylesheet" type="text/css" href="css/index.css" />
    <title>Kerst app!</title>
</head>

有同样的问题,说 'Refused to connect to blob:[...] because it does not appear in the connect-src directive of the Content Security Policy.'。

原来(不像你)我没有 Content-Security-Policy 的两个实例,而是两个 'connect-src' 实例,第二个缺少 'blob:'

非常感谢您将我推向正确的方向!