-
Notifications
You must be signed in to change notification settings - Fork 0
Fix SRI calculation validation in calc_sri_fix.sh #268
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,9 +4,10 @@ set -euo pipefail | |||||||
|
|
||||||||
| # calculate_sri downloads the given URL, computes the SHA-384 SRI hash of its content (base64) and echoes a line "<url> sha384-<base64_hash>". | ||||||||
| calculate_sri() { | ||||||||
| url="$1" | ||||||||
| local url="$1" | ||||||||
| local temp_file | ||||||||
| temp_file=$(mktemp) | ||||||||
| trap 'rm -f "$temp_file"' RETURN | ||||||||
| trap "rm -f \"$temp_file\"" RETURN | ||||||||
|
|
||||||||
| # curl options: -f (fail on HTTP error), -S (show error), -s (silent equivalent), -L (follow redirects) | ||||||||
| if ! curl -fS -sL "$url" -o "$temp_file"; then | ||||||||
|
|
@@ -20,6 +21,7 @@ calculate_sri() { | |||||||
| return 1 | ||||||||
| fi | ||||||||
|
|
||||||||
| local hash | ||||||||
| hash=$(openssl dgst -sha384 -binary < "$temp_file" | openssl base64 -A) | ||||||||
| echo "$url sha384-$hash" | ||||||||
| rm -f "$temp_file" | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial
Line 10 の ♻️ トラップに任せる場合の修正案 echo "$url sha384-$hash"
- rm -f "$temp_file"
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trapでダブルクォートを使用すると、$temp_fileがトラップ定義時に展開されます。ShellCheck SC2064 の指摘通り、ダブルクォートを使うと
$temp_fileはトラップ設定時に即座に展開されます。この場合、直前のmktempの結果をキャプチャするため意図通りに動作しますが、シングルクォートを使用するのがより慣用的で安全です。🔧 修正案
📝 Committable suggestion
🧰 Tools
🪛 Shellcheck (0.11.0)
[warning] 10-10: Use single quotes, otherwise this expands now rather than when signalled.
(SC2064)
🤖 Prompt for AI Agents