set up SRI for future use by CSP v3
This commit is contained in:
@@ -25,8 +25,17 @@ replace=""
|
||||
for file in static-tmp/**/*.css static-tmp/js/*.js static-tmp/mask-icon.svg; do
|
||||
hash=$(sha256sum "$file" | head -c 8)
|
||||
dest="$(dirname $file)/$hash.$(basename $file)"
|
||||
|
||||
if [[ $file == *.css ]]; then
|
||||
sri_hash=sha256-$(openssl dgst -sha256 -binary "$file" | openssl base64 -A)
|
||||
replace+=";s@{{css|/${file#*/}}}@<link rel=\"stylesheet\" href=\"/${dest#*/}\" integrity=\"$sri_hash\"/>@g"
|
||||
elif [[ $file == *.js ]]; then
|
||||
sri_hash=sha256-$(openssl dgst -sha256 -binary "$file" | openssl base64 -A)
|
||||
replace+=";s@{{js|/${file#*/}}}@<script type=\"module\" src=\"/${dest#*/}\" integrity=\"$sri_hash\"></script>@g"
|
||||
fi
|
||||
|
||||
mv "$file" "$dest"
|
||||
replace+=";s|/${file#*/}|/${dest#*/}|g"
|
||||
replace+=";s@{{path|/${file#*/}}}@/${dest#*/}@g"
|
||||
done
|
||||
|
||||
cp nginx/nginx.conf nginx.conf.tmp
|
||||
|
||||
Reference in New Issue
Block a user