【问题标题】:Contenct Security Policy refuses connect to Websocket Error内容安全策略拒绝连接到 Websocket 错误
【发布时间】:2018-03-30 07:30:25
【问题描述】:

由于我的 CSP(内容安全策略),我无法连接到 websocket - 出了什么问题?

错误:

ps-client-component-websocket-adapter.js:412 拒绝连接 'wss://hostname.domain:port/jsonWebSocket' 因为它违反 以下内容安全策略指令:“connect-src 'self'”。

我的 IIS web.config

 <?xml version="1.0" encoding="UTF-8"?>
        <configuration>
            <system.webServer>
                <httpProtocol>
                    <customHeaders>
                        <add name="Cache-Control" value="no-cache" />   
                        <!---<add name="X-Content-Security-Policy" value="default-src 'self' 'unsafe-eval'; connect-src 'self'; img-src 'self'; object-src 'none'; child-src *;" />-->
                        <add name="Content-Security-Policy" value="connect-src 'self' wss://hostname.domain:port/jsonWebSocket; default-src 'self' 'unsafe-eval'; img-src * data:; object-src 'none'; child-src *;" />              
                    </customHeaders>
                </httpProtocol>
            </system.webServer>
        </configuration>
        </configuration>

【问题讨论】:

    标签: iis websocket content-security-policy


    【解决方案1】:

    您似乎在connect-src 中缺少逗号。

    【讨论】:

    • 你能澄清一下吗?你能把更新的版本发过来吗?
    【解决方案2】:

    聚会有点晚了,但是as per MDN

    connect-src 'self' 不能在所有浏览器中解析为 websocket 模式,更多信息请参见 this issue

    您可能希望将wss 添加到connect-src,例如in this answer

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-04
      • 1970-01-01
      • 2021-08-06
      • 1970-01-01
      • 2020-02-27
      • 2012-11-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多