diff options
| author | Daniel Micay <danielmicay@gmail.com> | 2021-11-18 18:50:44 -0500 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2021-11-18 19:08:54 -0500 |
| commit | 75f4b333232ee99cd6af146c08a66c6ee4865f98 (patch) | |
| tree | 256d77eff66b5b8300fc0abde375047776d37b3a /process-static | |
| parent | 61e13582028790192d61b367c6e605e50765db4b (diff) | |
set up SRI for future use by CSP v3
Diffstat (limited to 'process-static')
| -rwxr-xr-x | process-static | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/process-static b/process-static index 9f33578c..22532ebf 100755 --- a/process-static +++ b/process-static @@ -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 |
