Safari 13.1.2 无法识别内容安全策略哈希
Content Security Policy hash not recognized by Safari 13.1.2
我在 CSP 有这个脚本指令:
script-src 'sha256-0pXdwEz+mZ/xD0qLLNDMVgeorh4Qr4Fv06RA35mAlk4='
和一个脚本标签:
<script type="text/javascript" src="https://domain.xxx/frontframe.js" integrity="sha256-0pXdwEz+mZ/xD0qLLNDMVgeorh4Qr4Fv06RA35mAlk4=" crossorigin="anonymous"></script>
它适用于 chrome 和 firefox,但不适用于 safari,除非我将 CSP 更改为:
script-src 'self' 'sha256-0pXdwEz+mZ/xD0qLLNDMVgeorh4Qr4Fv06RA35mAlk4='
没有指令 'self' 我得到的错误是:
Refused to load https://domain.xxx/frontframe.js because it does not appear in script-src directive of the Content Security Policy.
我是做错了什么还是 safari 的常见怪癖之一?我的 objective 是只加载具有有效 sha256 值的脚本,而不是任何其他指令 'self' 给出的可能性。
在 CSP 级别 2.0 之前,哈希仅适用于内联脚本和样式。从 CSP 级别 3.0 开始,还允许对外部源使用哈希。参见 https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src。 Safari 可能不太兼容 CSP 级别 3.0。
Safari 在 iOS does not support SRI(integrity=
属性)上。因此 Safari 不支持 hash-value 允许外部脚本,因为是基于上述属性。
更新:Safari 12.1.1 support SRI 尽管有 MDN 的信息。
我在 CSP 有这个脚本指令:
script-src 'sha256-0pXdwEz+mZ/xD0qLLNDMVgeorh4Qr4Fv06RA35mAlk4='
和一个脚本标签:
<script type="text/javascript" src="https://domain.xxx/frontframe.js" integrity="sha256-0pXdwEz+mZ/xD0qLLNDMVgeorh4Qr4Fv06RA35mAlk4=" crossorigin="anonymous"></script>
它适用于 chrome 和 firefox,但不适用于 safari,除非我将 CSP 更改为:
script-src 'self' 'sha256-0pXdwEz+mZ/xD0qLLNDMVgeorh4Qr4Fv06RA35mAlk4='
没有指令 'self' 我得到的错误是:
Refused to load https://domain.xxx/frontframe.js because it does not appear in script-src directive of the Content Security Policy.
我是做错了什么还是 safari 的常见怪癖之一?我的 objective 是只加载具有有效 sha256 值的脚本,而不是任何其他指令 'self' 给出的可能性。
在 CSP 级别 2.0 之前,哈希仅适用于内联脚本和样式。从 CSP 级别 3.0 开始,还允许对外部源使用哈希。参见 https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src。 Safari 可能不太兼容 CSP 级别 3.0。
Safari 在 iOS does not support SRI(integrity=
属性)上。因此 Safari 不支持 hash-value 允许外部脚本,因为是基于上述属性。
更新:Safari 12.1.1 support SRI 尽管有 MDN 的信息。