Consider the following single HTML file:
What is the the right hash to specify so that the browser does not throw any errors in the Console?
I found this example good to test "unsafe-hashes" because it is minimal. I took this example from: https://bugzilla.mozilla.org/show_bug.cgi?id=1788864
The bug itself is irrelevant. I am using this Linux command to determine SHA256 hash on file:
sha256sum test.txt | xxd -r -p | base64
It generates the same hash as in ASP.NET - the website that I am having trouble with.
The respective hashes would be:
javascript:alert(1);
=> 5OdtjsKuRneco+QGmtdJ48OzQ4ZYG8JnWV+4T/1zhxg=
alert(1);
=> vyWxnR5/SfkpBXTjK7tyUvoeEZCT+fK2ayxsse+sBvs=
Placing the hash that Firefox complains in the Console tab in Developer Tools works:
sha256-6rHS0m9l4sDJsB2k/Z3d/OJlJSv1H6Y6jKYIcK6zaks=
The question:
What is SHA256 hash algorithm that is expected by browsers? Please provide a code snippet in any language or clarify existing bugs or limitations.
Side question:
Maybe this has to do will most browsers injecting custom JS to prevent trackers on other things?
Related questions:
Content Security Policy (CSP) with unsafe-hashes is not working on mozilla firefox => Does not longer seem relevant
Content Security Policy (CSP) with unsafe-hashes is not working on mozilla firefox => Does not describe the SHA256 calculation specifically