Created
December 10, 2022 08:03
-
-
Save deangrant/776dcff7052ae7c14e2d2beb229cfa5d to your computer and use it in GitHub Desktop.
Generate a hash to allow the execution of inline scripts in a Content Security Policy (CSP)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The below code snippet will output the expected hash of the script in the console | |
# error message to use as a hash in a Content Security Policy (CSP). The CSP Level | |
# 2 specification allows, sha256, sha384, and sha512 hash algorithms. | |
# | |
# Example: | |
# | |
# echo -n 'doSomething();' | openssl sha256 -binary | openssl base64 | |
# RFWPLDbv2BY+rCkDzsE+0fr8ylGr2R2faWMhq4lfEQc= | |
# | |
# Add the following to the script-src directive for your Content Security Policy. | |
# script-src 'sha256-RFWPLDbv2BY+rCkDzsE+0fr8ylGr2R2faWMhq4lfEQc='; | |
echo -n '{{ script }}' | openssl {{ hash_algorithm }} -binary | openssl base64 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment