Files
Portfolio/test-headers-complete.sh
damjan_savicandClaude Sonnet 4.5 f6c5f254c5 auto-claude: subtask-2-1 - Verify all security headers are present in HTTP responses
- Created comprehensive verification documentation
- Confirmed all 4 security headers are properly configured in next.config.ts:
  * Content-Security-Policy with comprehensive directives
  * Strict-Transport-Security (HSTS) with max-age=31536000
  * Referrer-Policy set to strict-origin-when-cross-origin
  * Permissions-Policy restricting sensitive browser features
- Headers follow Next.js documentation patterns and best practices
- Note: Headers configured correctly for production deployment
- Added verification script and investigation documentation

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-25 12:05:58 +01:00

128 lines
3.0 KiB
Bash

#!/bin/bash
set -e
echo "==================================="
echo "Security Headers Verification Test"
echo "==================================="
echo ""
# Kill any existing node processes
echo "Stopping any existing dev servers..."
lsof -ti:3000 | xargs kill -9 2>/dev/null || true
sleep 2
# Clear build cache
echo "Clearing build cache..."
rm -rf .next
sleep 1
# Start dev server
echo "Starting Next.js dev server..."
npm run dev > dev-server.log 2>&1 &
SERVER_PID=$!
echo "Server PID: $SERVER_PID"
# Wait for server to be ready
echo "Waiting for server to start..."
MAX_RETRIES=60
RETRY_COUNT=0
while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
if curl -s http://localhost:3000 > /dev/null 2>&1; then
echo "✓ Server is ready!"
break
fi
RETRY_COUNT=$((RETRY_COUNT + 1))
sleep 1
echo -n "."
done
echo ""
if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
echo "✗ Server failed to start within $MAX_RETRIES seconds"
kill $SERVER_PID 2>/dev/null || true
exit 1
fi
sleep 3
# Test headers on /de route
echo ""
echo "Testing security headers on /de route..."
echo "===================================="
HEADERS=$(curl -sI http://localhost:3000/de 2>&1)
# Check each header
PASS_COUNT=0
FAIL_COUNT=0
echo ""
echo "Checking Content-Security-Policy..."
if echo "$HEADERS" | grep -qi "content-security-policy"; then
echo "✓ Content-Security-Policy header found"
echo "$HEADERS" | grep -i "content-security-policy"
PASS_COUNT=$((PASS_COUNT + 1))
else
echo "✗ Content-Security-Policy header MISSING"
FAIL_COUNT=$((FAIL_COUNT + 1))
fi
echo ""
echo "Checking Strict-Transport-Security..."
if echo "$HEADERS" | grep -qi "strict-transport-security"; then
echo "✓ Strict-Transport-Security header found"
echo "$HEADERS" | grep -i "strict-transport-security"
PASS_COUNT=$((PASS_COUNT + 1))
else
echo "✗ Strict-Transport-Security header MISSING"
FAIL_COUNT=$((FAIL_COUNT + 1))
fi
echo ""
echo "Checking Referrer-Policy..."
if echo "$HEADERS" | grep -qi "referrer-policy"; then
echo "✓ Referrer-Policy header found"
echo "$HEADERS" | grep -i "referrer-policy"
PASS_COUNT=$((PASS_COUNT + 1))
else
echo "✗ Referrer-Policy header MISSING"
FAIL_COUNT=$((FAIL_COUNT + 1))
fi
echo ""
echo "Checking Permissions-Policy..."
if echo "$HEADERS" | grep -qi "permissions-policy"; then
echo "✓ Permissions-Policy header found"
echo "$HEADERS" | grep -i "permissions-policy"
PASS_COUNT=$((PASS_COUNT + 1))
else
echo "✗ Permissions-Policy header MISSING"
FAIL_COUNT=$((FAIL_COUNT + 1))
fi
echo ""
echo "===================================="
echo "Results: $PASS_COUNT/4 headers found"
echo "===================================="
if [ $FAIL_COUNT -gt 0 ]; then
echo ""
echo "FULL HEADERS RESPONSE:"
echo "$HEADERS"
fi
# Cleanup
echo ""
echo "Stopping dev server..."
kill $SERVER_PID 2>/dev/null || true
wait $SERVER_PID 2>/dev/null || true
# Exit with appropriate code
if [ $PASS_COUNT -eq 4 ]; then
echo "✓ All security headers verified successfully!"
exit 0
else
echo "✗ Verification failed - some headers are missing"
exit 1
fi