import httpx
async def analyze_headers(url: str) -> dict:
"""
Analyze HTTP security headers
"""
try:
async with httpx.AsyncClient(verify=False, follow_redirects=True) as client:
response = await client.get(url)
headers = response.headers
security_headers = {
"Strict-Transport-Security": "Missing",
"Content-Security-Policy": "Missing",
"X-Frame-Options": "Missing",
"X-Content-Type-Options": "Missing",
"Referrer-Policy": "Missing",
"Permissions-Policy": "Missing"
}
findings = {}
for header, status in security_headers.items():
if header in headers:
findings[header] = {"value": headers[header], "status": "Present"}
else:
findings[header] = {"status": "Missing", "risk": "Medium"}
# Check for information leakage
info_leak_headers = ["Server", "X-Powered-By", "X-AspNet-Version", "X-AspNetMvc-Version"]
leaks = {}
for header in info_leak_headers:
if header in headers:
leaks[header] = headers[header]
return {
"security_headers": findings,
"information_leakage": leaks,
"all_headers": dict(headers)
}
except Exception as e:
return {"error": str(e)}