by westurner · 4y ago · 0 comments
> Subresource Integrity with the <script> element
> You can use the following <script> element to tell a browser that before executing the https://example.com/example-framework.js script, the browser must first compare the script to the expected hash, and verify that there's a match.
<script
src="https://example.com/example-framework.js"
integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC"
crossorigin="anonymous"></script>
[...]
Note: An integrity value may contain multiple hashes separated by whitespace. A resource will be loaded if it matches one of those hashes
To create a SHA384 SRI HTTP resource hash for the integrity= attr: cat FILENAME.js | openssl dgst -sha384 -binary | openssl base64 -A <a
href="https://example.com/data.bin"
integrity="sha384-oqVuAfXRKap7fdgcCY5uykM6+R9GqQ8K/uxy9rx7HNQlGYl1kPzQho1wx4JwY8wC"
>link</a>
I think this would be useful to have the browser check the integrity of the linked content, rather than asking the user to do it. You could have the hashsum being performed as the file is being downloaded.I think we would then want to the browser to indicate that the link actually has this integrity check, although it would be difficult to do in a way that cannot be easily spoofed. You could have something happen on hover over, but this won't work for touch devices.
Copying and pasting doesn't copy integrity= node attribute, but does copy URL query arguments and URI fragments.