#!/usr/bin/env bash set -euo pipefail usage() { echo "Использование: $0 URL [--all]" } url="${1:-https://example.com/}" show_all=0 if [[ "${2:-}" == "--all" ]]; then show_all=1 fi command -v curl >/dev/null 2>&1 || { echo "Нужен curl" >&2; exit 2; } tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT curl -sS -L --max-time 20 -D "$tmp/headers" -o /dev/null "$url" mapfile -t policies < <(grep -i '^content-security-policy:' "$tmp/headers" | cut -d: -f2- | sed 's/^[[:space:]]*//' | tr -d '\r' || true) if [[ "${#policies[@]}" -eq 0 ]]; then echo "Content-Security-Policy не найден" exit 1 fi policy="${policies[0]}" echo "Политик найдено: ${#policies[@]}" echo "Политика: $policy" echo for directive in default-src script-src object-src base-uri frame-ancestors; do if grep -qiE "(^|;[[:space:]]*)${directive}([[:space:]]|;|$)" <<< "$policy"; then echo " есть: $directive" else echo " нет: $directive" fi done for token in "unsafe-inline" "unsafe-eval"; do if grep -qi "$token" <<< "$policy"; then echo " риск: $token" fi done if grep -qE '(^|[[:space:]])[*]([[:space:]]|;|$)' <<< "$policy"; then echo " риск: wildcard в источниках" fi if [[ "$show_all" -eq 1 ]]; then echo echo "Все директивы:" tr ';' '\n' <<< "$policy" | sed '/^[[:space:]]*$/d' | sed 's/^[[:space:]]*//' fi