Skip to content

Commit 20262e8

Browse files
committed
Refactor SRI script to use local variables and safe trap expansion
1 parent 1e9467a commit 20262e8

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

calc_sri_fix.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
set -euo pipefail
44

55
calculate_sri() {
6-
url="$1"
6+
local url="$1"
7+
local temp_file
78
temp_file=$(mktemp)
8-
trap 'rm -f "$temp_file"' RETURN
9+
trap "rm -f \"$temp_file\"" RETURN
910

1011
# curl options: -f (fail on HTTP error), -S (show error), -s (silent equivalent), -L (follow redirects)
1112
if ! curl -fS -sL "$url" -o "$temp_file"; then
@@ -19,6 +20,7 @@ calculate_sri() {
1920
return 1
2021
fi
2122

23+
local hash
2224
hash=$(openssl dgst -sha384 -binary < "$temp_file" | openssl base64 -A)
2325
echo "$url sha384-$hash"
2426
rm -f "$temp_file"

0 commit comments

Comments
 (0)