#!/bin/bash
# 23 - Client-Side & JavaScript Security
# Tests: clickjacking, content-type sniffing, CSP headers, CSRF token exposure,
# prototype pollution via API, DOM XSS reflection vectors, SRI, service worker paths
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/../config.sh"
OUT_FILE="$OUT/23_client_side_js.txt"
echo "=== 23. Client-Side & JavaScript Security ===" | tee "$OUT_FILE"
echo "Target: $TARGET" | tee -a "$OUT_FILE"
echo "" | tee -a "$OUT_FILE"
W() { printf '%s' "$1" | python3 -c "import sys,urllib.parse; print(urllib.parse.quote(sys.stdin.read().strip()))"; }
do_test() {
local label="$1"; shift
local code
code=$(curl -sk -o /dev/null -w '%{http_code}' "$@")
printf '[%s] %s\n' "$code" "$label" | tee -a "$OUT_FILE"
}
do_test_headers() {
local label="$1"; shift
local out
out=$(curl -sk -D - -o /dev/null "$@")
local code=$(echo "$out" | head -1 | grep -oP '\d{3}' | head -1)
printf '[%s] %s\n' "$code" "$label" | tee -a "$OUT_FILE"
# Print security-relevant headers
echo "$out" | grep -iE '^(x-frame-options|content-security-policy|x-content-type-options|cache-control|referrer-policy|permissions-policy|cross-origin|vary):' | sed 's/^/ /' | tee -a "$OUT_FILE"
}
# ── 1. Clickjacking / X-Frame-Options ─────────────────────────────────────────
echo "--- Clickjacking / Framing Controls ---" | tee -a "$OUT_FILE"
do_test_headers "Main page framing headers" -A "$BROWSER_UA" "$TARGET/"
do_test_headers "Encrypt page framing headers" -A "$BROWSER_UA" "$TARGET/crypt.php"
do_test_headers "Admin page framing headers" -A "$BROWSER_UA" "$TARGET/admin/"
echo "" | tee -a "$OUT_FILE"
# ── 2. Content-Type Sniffing (X-Content-Type-Options) ─────────────────────────
echo "--- Content-Type Sniffing ---" | tee -a "$OUT_FILE"
do_test_headers "Static JS asset headers" -A "$BROWSER_UA" "$TARGET/dist/assets/index.js" 2>/dev/null || \
do_test_headers "CSS asset headers" -A "$BROWSER_UA" "$TARGET/css/homepage.css"
do_test_headers "API JSON response headers" -A "$BROWSER_UA" \
-H 'Content-Type: application/json' \
-d '{"test":"x"}' \
"$API_TARGET/status"
echo "" | tee -a "$OUT_FILE"
# ── 3. MIME-type confusion — serve JS as text/plain ───────────────────────────
echo "--- MIME Confusion / Content Sniffing Attack ---" | tee -a "$OUT_FILE"
do_test "Script with Accept: text/plain (MIME sniff probe)" \
-A "$BROWSER_UA" -H "Accept: text/plain" "$TARGET/js/crypt.js" 2>/dev/null || \
do_test "CSS with Accept: text/plain" \
-A "$BROWSER_UA" -H "Accept: text/plain" "$TARGET/css/homepage.css"
echo "" | tee -a "$OUT_FILE"
# ── 4. Reflected parameter — DOM XSS reflection ───────────────────────────────
echo "--- DOM XSS / Reflected Parameter Vectors ---" | tee -a "$OUT_FILE"
XSS_FRAG=$(W "")
XSS_IMG=$(W "
")
XSS_SVG=$(W "