I added integrity
and crossorigin
tags to my scripts according to Subresource Integrity, but now they give an error in the console saying
Script from origin 'http://pagead2.googlesyndication.com' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:81' is therefore not allowed access.
Here is the script:
<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>
Here is the derivation:
$ curl -s http://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js | openssl dgst -sha256 -binary | openssl base64 -A
5xwrIw3xU3VvipjVMZNyf6+27C/a1Pxl3U0jl3hTcao=
I also added the attributes to an Amazon script, and that fails too.
Script from origin 'http://s3.amazonaws.com' has been blocked from loading by Cross-Origin Resource Sharing policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:81' is therefore not allowed access.
<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 supports SRI: http://enable-cors.org/client.html, https://www.chromestatus.com/feature/6183089948590080
I verified the hash is generating correctly using the example in the specifications: http://www.w3.org/TR/SRI/#integrity-metadata
So why isn't it working? It works without the two new attributes.
Chrome Version 46.0.2490.86 m