Security headers

From woohyun212/security-skill · View interactive version

Security headers is an AI agent skill from the GitHub repository woohyun212/security-skill. Analyze HTTP security headers of a target URL and provide remediation advice

How to use this skill

Skill file

What this skill does

Sends an HTTP request to the target URL, collects response headers, and checks for the presence and proper configuration of security-related headers. Classifies each header as present, missing, or misconfigured, and provides remediation recommendations for missing or improperly configured headers.

When to use

Prerequisites

Inputs

| Variable | Description | Example |

|----------|-------------|---------|

| TARGET_URL | Target URL to check (including scheme) | https://example.com |

Workflow

Step 1: Collect response headers

TARGET_URL="https://example.com"

curl -s -I -L \
  --max-time 10 \
  --user-agent "SecurityHeadersCheck/1.0" \
  "$TARGET_URL" 2>&1 | tee /tmp/headers_raw.txt

echo "=== Collected Headers ==="
cat /tmp/headers_raw.txt

Step 2: Check individual security headers

check_header() {
  local name="$1"
  local pattern="$2"
  local value
  value=$(grep -i "^${pattern}:" /tmp/headers_raw.txt | head -1)
  if [ -z "$value" ]; then
    echo "[MISSING]  $name"
  else
    echo "[PRESENT]  $value"
  fi
}

echo ""
echo "=== Security Header Check Results ==="
check_header "X-Content-Type-Options"    "x-content-type-options"
check_header "X-Frame-Options"           "x-frame-options"
check_header "Strict-Transport-Security" "strict-transport-security"
check_header "Content-Security-Policy"   "content-security-policy"
check_header "X-XSS-Protection"          "x-xss-protection"
check_header "Referrer-Policy"           "referrer-policy"
check_header "Permissions-Policy"        "permissions-policy"

Step 3: Detect misconfigured headers

echo ""
echo "=== Misconfiguration Check ==="

# HSTS: warn if max-age is too short
hsts=$(grep -i "^strict-transport-security:" /tmp/headers_raw.txt | head -1)
if [ -n "$hsts" ]; then
  max_age=$(echo "$hsts" | grep -oP 'max-age=\K[0-9]+')
  if [ -n "$max_age" ] && [ "$max_age" -lt 31536000 ]; then
    echo "[MISCONFIGURED] HSTS max-age=$max_age (recommended: 31536000 or higher)"
  else
    echo "[OK] HSTS max-age is sufficient"
  fi
fi

# X-XSS-Protection: warn if not set to 1; mode=block
xxp=$(grep -i "^x-xss-protection:" /tmp/headers_raw.txt | head -1)
if [ -n "$xxp" ]; then
  if echo "$xxp" | grep -qi "0"; then
    echo "[MISCONFIGURED] X-XSS-Protection: disabled with value 0"
  fi
fi

# X-Frame-Options: ALLOW-FROM is an outdated approach
xfo=$(grep -i "^x-frame-options:" /tmp/headers_raw.txt | head -1)
if [ -n "$xfo" ]; then
  if echo "$xfo" | grep -qi "allow-from"; then
    echo "[MISCONFIGURED] X-Frame-Options ALLOW-FROM is not supported by most browsers. Use CSP frame-ancestors instead."
  fi
fi

Step 4: Output remediation recommendations

echo ""
echo "=== Remediation Recommendations ==="

grep -qi "^x-content-type-options:" /tmp/headers_raw.txt || \
  echo "X-Content-Type-Options: nosniff  # Prevent MIME type sniffing"

grep -qi "^x-frame-options:" /tmp/headers_raw.txt || \
  echo "X-Frame-Options: DENY  # Prevent clickjacking (or use Content-Security-Policy: frame-ancestors 'none')"

grep -qi "^strict-transport-security:" /tmp/headers_raw.txt || \
  echo "Strict-Transport-Security: max-age=31536000; includeSubDomains; preload  # Enforce HTTPS"

grep -qi "^content-security-policy:" /tmp/headers_raw.txt || \
  echo "Content-Security-Policy: default-src 'self'  # Prevent XSS/data injection attacks (adjust policy to your application)"

grep -qi "^referrer-policy:" /tmp/headers_raw.txt || \
  echo "Referrer-Policy: strict-origin-when-cross-origin  # Limit Referer header information exposure"

grep -qi "^permissions-policy:" /tmp/headers_raw.txt || \
  echo "Permissions-Policy: geolocation=(), microphone=(), camera=()  # Restrict browser feature access"

echo ""
echo "Reference: https://securityheaders.com for detailed grading"

Done when

Failure modes

| Symptom | Cause and Resolution |

|---------|---------------------|

| curl: (6) Could not resolve host | DNS not resolving. Check URL and network connectivity |

| curl: (60) SSL certificate problem | Self-signed certificate. Add -k flag (test environments only) |

| Headers are empty | CDN/proxy may be stripping headers. Consider checking the origin server directly |

| Different headers after 302/301 redirect | Use -L flag to follow redirects to the final destination |

Notes

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.