forked from ritik4ever/stellar-goal-vault
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-sri.sh
More file actions
executable file
·37 lines (30 loc) · 1.06 KB
/
Copy pathcheck-sri.sh
File metadata and controls
executable file
·37 lines (30 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env bash
# Verify every external <link> and <script> tag in index.html carries integrity + crossorigin attributes.
# Exits non-zero if any CDN resource lacks an integrity hash.
set -euo pipefail
HTML_FILE="${1:-frontend/index.html}"
if [ ! -f "$HTML_FILE" ]; then
echo "ERROR: $HTML_FILE not found"
exit 1
fi
ERRORS=0
while IFS= read -r line; do
# Match <link> or <script> tags that load from an external URL (http/https)
if echo "$line" | grep -qiE '<(link|script)[^>]+(href|src)="https?://'; then
if ! echo "$line" | grep -q 'integrity='; then
echo "MISSING integrity: $line"
ERRORS=$((ERRORS + 1))
fi
if ! echo "$line" | grep -q 'crossorigin='; then
echo "MISSING crossorigin: $line"
ERRORS=$((ERRORS + 1))
fi
fi
done < "$HTML_FILE"
if [ "$ERRORS" -gt 0 ]; then
echo ""
echo "SRI check FAILED: $ERRORS attribute(s) missing."
echo "Generate a hash with: openssl dgst -sha384 -binary <file> | openssl base64 -A"
exit 1
fi
echo "SRI check passed — all CDN resources carry integrity and crossorigin attributes."