A lightweight REST API built with Go and Fiber that analyzes a website’s HTTP security response headers. It checks the presence of key headers, computes a weighted score (0–100), and returns a letter grade (A–F) with a human‑readable summary.
- Analyze a target URL’s response headers with a single POST call
- Weighted scoring for critical/important/recommended headers
- HTTPS usage bonus and tiered coverage bonuses
- Health endpoint for readiness checks
- Response:
{"status":"ok"}
- Request body (JSON):
{
"url": "https://example.com"
}-
Notes:
urlmay be provided without a scheme;https://will be prefixed automatically if missing.
-
Success response (example):
{
"headers": {
"Strict-Transport-Security": true,
"X-Content-Type-Options": true,
"X-Frame-Options": false,
"Content-Security-Policy": false,
"Referrer-Policy": true,
"Permissions-Policy": false,
"Cross-Origin-Opener-Policy": false,
"Cross-Origin-Resource-Policy": false
},
"score": 72,
"grade": "B",
"summary": [
{
"name": "Strict-Transport-Security",
"present": true,
"description": "Forces HTTPS connections to protect against man-in-the-middle attacks.",
"weight": 20
}
],
"url": "https://example.com"
}- Error responses:
- 400:
{"error":"Invalid request body"}or{"error":"URL is required"} - 500:
{"error":"Failed to analyze URL: <details>"}
- 400:
- Header weights contribute 70% of the total score.
- HTTPS usage contributes a base of +30 points.
- Tiered bonuses:
- Critical headers: up to +10 points total
- Important headers: up to +5 points total
- Score is capped at 100.
Letter grades:
- A: ≥ 80
- B: ≥ 65
- C: ≥ 45
- D: ≥ 25
- F: < 25
-
Critical
Strict-Transport-Security— forces HTTPSX-Content-Type-Options— prevents MIME sniffingX-Frame-Options— mitigates clickjacking
-
Important
Content-Security-Policy(aliases:Content-Security-Policy-Report-Only) — mitigates XSS by restricting sourcesReferrer-Policy— controls referrer information sharing
-
Recommended
Permissions-Policy(aliases:Feature-Policy) — restricts browser features/APIsCross-Origin-Opener-Policy— isolates browsing contextCross-Origin-Resource-Policy— restricts cross-origin resource loading
- Go toolchain (see
go.modfor version; recent Go is recommended)
go mod tidygo run .- The server listens on
PORTif set, otherwise8080.
Examples:
curl http://localhost:8080/health
curl -X POST http://localhost:8080/analyze \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com"}'go build -o header-analyzerRun the binary:
./header-analyzer # Linux/macOS
header-analyzer.exe # WindowsPORT: HTTP port (default:8080).- CORS is enabled for all origins by default (
*).
- The HTTP client uses
InsecureSkipVerify: trueto avoid TLS verification failures during analysis. This is convenient for scanning but should be used cautiously in production contexts. - CORS allows all origins. Consider restricting allowed origins/methods/headers if exposing this service publicly.
main.go— HTTP server, routes (/analyze,/health), error handling, CORSinternal/analyzer.go— header checks, scoring and grading logicgo.mod,go.sum— dependenciesLICENSE— license information
See LICENSE for details.