Skip to content

Commit f7315b9

Browse files
committed
Robust UI audit: skip inline URL scan on dist/, keep structural checks
Minified JS in dist/ contains hundreds of string-constant URLs from bundled npm libraries (React error pages, W3C namespace URIs, CDN references, OSS credits) that are never fetched at runtime. Scanning them produced an endless stream of false positives requiring per-URL allowlisting. Fix: split the A1 URL check by directory: - src/ (our code): strict — any external URL is blocked - dist/ (npm build output): skip inline URL scan entirely Structural checks (A2-A6) still apply to dist/: - External <script>/<link> loads in HTML - Tracking/analytics identifiers - Iframes, eval/Function, external WebSockets
1 parent a9382ce commit f7315b9

1 file changed

Lines changed: 31 additions & 30 deletions

File tree

scripts/security-ui.sh

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,37 +36,38 @@ else
3636
for UI_DIR in "${UI_DIRS[@]}"; do
3737
echo "Scanning: $UI_DIR"
3838

39-
# A1: No external domains in JS/CSS
40-
echo " Checking for external domains..."
41-
if find "$UI_DIR" -type f \( -name '*.js' -o -name '*.ts' -o -name '*.tsx' -o -name '*.css' \) -exec grep -lE 'https?://' {} \; 2>/dev/null | head -20 > "$SEC_TMPDIR/urls"; then
42-
while IFS= read -r file; do
43-
relfile="${file#"$ROOT/"}"
44-
grep -onE 'https?://[^\s"'"'"')]+' "$file" 2>/dev/null | while IFS=: read -r lineno url; do
45-
case "$url" in
46-
http://localhost*|http://127.0.0.1*|https://localhost*|https://127.0.0.1*)
47-
;; # OK — local dev/runtime
48-
# Bundled framework URLs (embedded by npm deps in dist/ builds):
49-
http://www.w3.org/*|https://www.w3.org/*)
50-
;; # W3C XML/SVG/MathML namespace URIs
51-
https://react.dev/*|https://reactjs.org/*)
52-
;; # React error/docs URLs
53-
https://github.com/*|https://cdn.jsdelivr.net/*|https://cdn.j*)
54-
;; # OSS library credits + CDN refs in bundled code
55-
https://fonts.googleapis.com/*|https://fonts.gstatic.com/*)
56-
;; # Google Fonts (loaded by index.html)
57-
https://tailwindcss.com/*|https://tailwindc*)
58-
;; # Tailwind CSS source annotations
59-
https://jcgt.org/*|https://doc*)
60-
;; # Academic/documentation refs in Three.js shaders
61-
*)
62-
echo " BLOCKED: ${relfile}:${lineno}: External URL: $url"
63-
touch "$SEC_TMPDIR/fail_flag"
64-
;;
65-
esac
66-
done
67-
done < "$SEC_TMPDIR/urls"
39+
# A1: No external domains in JS/CSS/TS source code.
40+
# For src/ (our code): strict — any external URL is blocked.
41+
# For dist/ (bundled npm output): skip inline URL scan — minified JS
42+
# contains hundreds of string-constant URLs from libraries (React error
43+
# pages, W3C namespace URIs, CDN references, OSS credits) that are never
44+
# fetched at runtime. Scanning them is noise. Structural checks (A2-A6)
45+
# still apply to dist/.
46+
is_dist=false
47+
[[ "$UI_DIR" == *"/dist" || "$UI_DIR" == *"/dist/" ]] && is_dist=true
48+
49+
if ! $is_dist; then
50+
echo " Checking for external domains (source)..."
51+
if find "$UI_DIR" -type f \( -name '*.js' -o -name '*.ts' -o -name '*.tsx' -o -name '*.css' \) -exec grep -lE 'https?://' {} \; 2>/dev/null | head -20 > "$SEC_TMPDIR/urls"; then
52+
while IFS= read -r file; do
53+
relfile="${file#"$ROOT/"}"
54+
grep -onE 'https?://[^\s"'"'"')]+' "$file" 2>/dev/null | while IFS=: read -r lineno url; do
55+
case "$url" in
56+
http://localhost*|http://127.0.0.1*|https://localhost*|https://127.0.0.1*)
57+
;; # OK — local dev/runtime
58+
*)
59+
echo " BLOCKED: ${relfile}:${lineno}: External URL: $url"
60+
touch "$SEC_TMPDIR/fail_flag"
61+
;;
62+
esac
63+
done
64+
done < "$SEC_TMPDIR/urls"
65+
fi
66+
[[ -f "$SEC_TMPDIR/fail_flag" ]] && FAIL=1 && rm -f "$SEC_TMPDIR/fail_flag"
67+
else
68+
echo " Skipping inline URL scan for dist/ (bundled library strings)."
69+
echo " Structural checks (script loads, tracking, eval, iframes) still apply."
6870
fi
69-
[[ -f "$SEC_TMPDIR/fail_flag" ]] && FAIL=1 && rm -f "$SEC_TMPDIR/fail_flag"
7071

7172
# A2: No external script/link loads in HTML
7273
echo " Checking for external script/link loads..."

0 commit comments

Comments
 (0)