【发布时间】:2016-02-15 13:19:19
【问题描述】:
我根据Subresource Integrity在我的脚本中添加了integrity和crossorigin标签,但现在他们在控制台中给出了一个错误提示
来自“http://pagead2.googlesyndication.com”的脚本已被跨域资源共享策略阻止加载:请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问 Origin 'http://localhost:81'。
这是脚本:
<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"
integrity="sha256-5xwrIw3xU3VvipjVMZNyf6+27C/a1Pxl3U0jl3hTcao="
crossorigin="anonymous"></script> <!-- Banner --> <ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-3346556035533863" data-ad-slot="8052306231"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script>
这是推导:
$ curl -s http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js | openssl dgst -sha256 -binary | openssl base64 -A
5xwrIw3xU3VvipjVMZNyf6+27C/a1Pxl3U0jl3hTcao=
我还将属性添加到 Amazon 脚本中,但也失败了。
来自“http://s3.amazonaws.com”的脚本已被跨域资源共享策略阻止加载:请求的资源上不存在“Access-Control-Allow-Origin”标头。因此不允许访问 Origin 'http://localhost:81'。
<script async="async" type="text/javascript" src="//s3.amazonaws.com/cc.silktide.com/cookieconsent.latest.min.js"
integrity="sha256-/8egBZx4+UIzXH8il2CNdL5+npDYgoAsjC76KHO/re4=" crossorigin="anonymous"></script>
Chrome 支持 SRI:http://enable-cors.org/client.html、https://www.chromestatus.com/feature/6183089948590080
我使用规范中的示例验证了哈希是否正确生成:http://www.w3.org/TR/SRI/#integrity-metadata
那么为什么它不起作用?它可以在没有两个新属性的情况下工作。
Chrome 版本 46.0.2490.86 m
【问题讨论】:
标签: javascript google-chrome security subresource-integrity