There is any way to get or calculate the file integrity hash?
e.g:
<script src="https://code.jquery.com/jquery-3.6.1.min.js" integrity="sha256-o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=" crossorigin="anonymous"></script>
For the script above the browser calculate the file sha256 and comparing it to the given attribute integrity o88AwQnZB+VDvE9tvIXrMQaPlFFSUTR+nldQm1LuPXQ=.
So my question is if I can get the browser calculation for the real file (the one that the client received) via web api or something like that?
I read about Request.integrity at https://developer.mozilla.org/en-US/docs/Web/API/Request/integrity but wen i try to use it i get an empty string.
const myRequest = new Request('https://code.jquery.com/jquery-3.6.1.min.js');
const myIntegrity = myRequest.integrity;
There is a site for Subresource Integrity (SRI) hashtag generation - https://www.srihash.org/
Or it can be generated manually with
openssl. Likeopenssl dgst -sha512 -binary myfile.js | openssl base64 -A. Then add a constantsha512-before the hash to get the proper value for theintegrityattribute.