This guide will demo how to add a hash value of a script to CSP.
You could use openssl to generate the hash value, which will be installed by default on most linux system, just like below:
If you use the entire code to compute the SHA-256 hash value, you'll get the value:
echo -n 'showHello();' | openssl sha256 -binary | openssl base64
Finally, we can add the hash to our Content-Security-Policy header, as example below:
script-src 'self' 'ziuYZCxAULHgmKBeN0a7ywKsu8z+0V9IXrJ+3I3pCKY='
Copyright © 2020 by 940Apps Co., Ltd. All rights reserved.