#!/usr/bin/env bash set -euo pipefail usage() { cat <<'EOF' Использование: http_headers.sh [--timeout S] EOF } url="" timeout=15 while [[ $# -gt 0 ]]; do case "$1" in --timeout) timeout="${2:-}"; shift 2 ;; -h|--help) usage; exit 0 ;; -*) echo "Неизвестный параметр: $1" >&2; usage >&2; exit 2 ;; *) if [[ -n "$url" ]]; then echo "Укажите только один URL" >&2 exit 2 fi url="$1" shift ;; esac done if [[ -z "$url" ]]; then usage >&2 exit 2 fi if [[ ! "$url" =~ ^https?:// ]]; then echo "Нужен URL с http или https" >&2 exit 2 fi if ! command -v curl >/dev/null 2>&1; then echo "Не найден curl" >&2 exit 2 fi tmp="$(mktemp)" trap 'rm -f "$tmp"' EXIT if ! curl -sS -L -D "$tmp" -o /dev/null --max-time "$timeout" "$url"; then echo "Не удалось получить заголовки" >&2 exit 1 fi echo "Заголовки ответа:" cat "$tmp" echo echo "Проверка защитных заголовков:" check_header() { local name="$1" local value value="$(grep -i "^${name}:" "$tmp" | tail -1 | sed 's/^[^:]*:[[:space:]]*//' | tr -d '\r' || true)" if [[ -n "$value" ]]; then printf ' [есть] %s: %s\n' "$name" "$value" else printf ' [нет] %s\n' "$name" fi } for header in \ "Strict-Transport-Security" \ "Content-Security-Policy" \ "X-Content-Type-Options" \ "X-Frame-Options" \ "Referrer-Policy" \ "Permissions-Policy" \ "Cross-Origin-Opener-Policy"; do check_header "$header" done