
我有以下内容安全策略(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)
资源似乎出现了很多:
> The Lounge fails to work over https due to Content Security Policy
enforcement in Safari v10
> request isn’t sent on iOS 10.0
为什么它说“拒绝连接到”以ws开头的URL:“因为它既不出现在connect-src指令中,也出现在Content-Security-Policy的default-src指令中,即使它们都被提到了?
好吧,safari / iOS比Chrome / AndroID更严格,一切都很好,但它仍然需要让我允许连接通过.对于应用开发者来说这真是令人沮丧!解决方案?
编辑:
在BUGs.webkit.org上做了一个BUG报告: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,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>总结
以上是内存溢出为你收集整理的iOS拒绝连接,因为它既不出现在connect-src指令中,也出现在内容安全策略的default-src指令中全部内容,希望文章能够帮你解决iOS拒绝连接,因为它既不出现在connect-src指令中,也出现在内容安全策略的default-src指令中所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)