Helenis API
Start for free

Web data & toolsWeb Security

Security Headers Checker API: Grade Any Website A+ to F, with Fixes

Security headers checker API tutorial: grade a website A+ to F on CSP, HSTS, cookies and TLS, get nginx, Apache and Cloudflare fixes, and check CI builds.

Security Headers Checker API cover: a shield sticker, an arrow and a JSON response for https://www.python.org/ with grade C, score 70, 2 failed checks and a report-only Content-Security-Policy as the first finding.
python.org graded C: a strict CSP that only reports, and no nosniff header.

A customer's security questionnaire asks for your Content-Security-Policy. A penetration test report lists "missing security headers" as five low-severity findings. A client asks their agency why a free scanner gave their new site a D. Each time, someone checks one site in a browser tool, copies the findings and searches how to write each fix for nginx.

That does not scale to an agency with 60 client sites, a SaaS grading every customer domain, or a CI pipeline that should stop a release that drops a header. A security headers checker API gives the same verdict as code: the grade, every finding, and the exact line to deploy.

This tutorial explains which headers matter and why, how a grade can be made explainable, then audits real websites from Python with the Website Security Audit API, including headers pasted from a staging server the internet cannot reach.

Which security headers matter, and what each one stops

Header Stops Typical value
Content-Security-Policy Injected scripts (XSS) running with the page's rights; also clickjacking via frame-ancestors default-src 'self'; script-src 'self' 'nonce-...'; object-src 'none'; base-uri 'self'
Strict-Transport-Security Downgrade to plain HTTP and cookie theft on hostile networks (RFC 6797) max-age=31536000; includeSubDomains
X-Frame-Options Clickjacking (the page framed by another site) DENY or SAMEORIGIN
X-Content-Type-Options Browsers guessing a file's type and running an upload as a script nosniff
Referrer-Policy Full URLs (with tokens or IDs) leaking to other sites strict-origin-when-cross-origin
Permissions-Policy Embedded third parties asking for camera, microphone, location camera=(), microphone=(), geolocation=()
Cross-Origin-Opener-Policy and friends Cross-window attacks and Spectre-style leaks same-origin

X-XSS-Protection is obsolete: modern browsers removed the filter it controlled, and a CSP does the job. The OWASP HTTP Headers Cheat Sheet is the reference list.

Headers are only part of what an outside observer can check:

  • Cookies: Secure (never sent over HTTP), HttpOnly (unreadable by scripts), SameSite (not sent on cross-site requests).
  • HTTPS: does http:// redirect to https://, and does the page still load scripts or images over http:// (mixed content)?
  • TLS: is the certificate valid, when does it expire, and does the server still accept TLS 1.0 or 1.1, deprecated by RFC 8996 and refused by PCI DSS?
  • Version leaks: Server: nginx/1.18.0 or X-Powered-By: PHP/8.1.2 tell an attacker which known vulnerabilities to try.
  • security.txt: a file at /.well-known/security.txt (RFC 9116) that tells researchers whom to contact.

How an explainable grade works

A grade is only useful if you can tell why it moved. The API starts every site at 100 points and each check adds its points:

Check Points
No Content-Security-Policy, or report-only -20
Weak CSP (no script restriction, 'unsafe-inline', wildcards, 'unsafe-eval') -5 to -15
No HSTS / HSTS under 180 days -20 / -10
http:// serves the page instead of redirecting -20
No clickjacking protection -15
Certificate renewal overdue / due -15 / -5
Cookies without Secure -10
Active mixed content; TLS 1.0 or 1.1 accepted -10 each
No nosniff, Referrer-Policy or Permissions-Policy; version leak; cookies without HttpOnly; no TLS 1.3 -5 each
HSTS ready for preload; strict CSP (nonces or hashes) +5 each

A+ needs 100 or more with no failure and no warning; A is 90, B 75, C 60, D 45, below is F. Two caps override the score: no working HTTPS or an invalid certificate is F, and accepting TLS 1.0 or 1.1 is B at best.

Audit a website's security headers in Python

GET /v1/site-audit/audit?url= takes a domain or a page URL, follows the redirects, checks http:// separately and returns everything in one response, for 1 credit.

Python
import requests

HOST = "website-security-audit-headers-ssl-grade.p.rapidapi.com"
API = f"https://{HOST}"
HEADERS = {"x-rapidapi-key": "YOUR_API_KEY", "x-rapidapi-host": HOST}

r = requests.get(
    f"{API}/v1/site-audit/audit",
    headers=HEADERS,
    params={"url": "python.org"},
    timeout=90,
)
r.raise_for_status()
audit = r.json()
print(audit["grade"], audit["score"], audit["summary"])
for check in audit["checks"]:
    if check["status"] in ("fail", "warn"):
        print(f"{check['points']:>4}  {check['title']}: {check['message']}")

The real response for python.org, in 1.9 seconds (shortened: long values cut with ..., passing checks and the TLS block left out):

JSON
{
  "url": "https://python.org/",
  "final_url": "https://www.python.org/",
  "status_code": 200,
  "grade": "C",
  "score": 70,
  "summary": { "passed": 10, "warnings": 2, "failed": 2, "info": 4 },
  "checks": [
    {
      "id": "csp",
      "title": "Content-Security-Policy",
      "status": "fail",
      "points": -20,
      "value": "default-src 'self'; connect-src 'self' https://console.python.org ... script-src 'self' 'nonce-hqQSUx/3wbQNRPlWuEinBw==' https://analytics.python.org https://media.ethicalads.io https://server.ethicalads.io https://ajax.googleapis.com",
      "message": "CSP is in report-only mode: nothing is blocked yet.",
      "fix": {
        "header": "Content-Security-Policy: default-src 'self'; connect-src 'self' https://console.python.org ... script-src 'self' 'nonce-hqQSUx/3wbQNRPlWuEinBw==' https://analytics.python.org https://media.ethicalads.io https://server.ethicalads.io https://ajax.googleapis.com; upgrade-insecure-requests",
        "note": "Your report-only policy, enforced (plus the directives it lacked): send it as Content-Security-Policy once the reports are clean. Set it where your application sets the header today, so the 'nonce-…' stays the fresh value it generates for each response; never as a static copy."
      }
    },
    {
      "id": "content_type_options",
      "title": "X-Content-Type-Options",
      "status": "fail",
      "points": -5,
      "message": "Without nosniff, browsers may guess a file's type and run an upload as a script.",
      "fix": {
        "header": "X-Content-Type-Options: nosniff",
        "nginx": "add_header X-Content-Type-Options \"nosniff\" always;",
        "apache": "Header always set X-Content-Type-Options \"nosniff\"",
        "cloudflare": "Rules › Transform Rules › Modify Response Header › Set static header: X-Content-Type-Options = nosniff"
      }
    },
    {
      "id": "referrer_policy",
      "title": "Referrer-Policy",
      "status": "warn",
      "points": -5,
      "message": "No Referrer-Policy: set one so full URLs (and what they carry) are not sent to other sites."
    },
    {
      "id": "hsts",
      "title": "Strict-Transport-Security (HSTS)",
      "status": "pass",
      "points": 5,
      "value": "max-age=63072000; includeSubDomains; preload",
      "message": "HSTS for 730 days, subdomains included, ready for preload."
    }
  ],
  "notes": [
    "The page has 2 inline script(s): give them a nonce or move them to files before enforcing a strict CSP.",
    "Headers checked on https://www.python.org/, where the site redirects."
  ]
}

The arithmetic is visible: 100, minus 20 for the report-only CSP, 5 each for nosniff, Referrer-Policy and Permissions-Policy, plus 5 for a preload-ready HSTS, gives 70, a C. Checks come worst first, so checks[0] is always the first thing to fix, and fixes at the top level gathers every fix into one nginx block, one Apache block and a list of Cloudflare rules.

The CSP fix starts from what the site already has. python.org runs a strict, nonce-based policy in report-only mode, so the fix is that same policy sent as Content-Security-Policy, plus the one directive it lacked (upgrade-insecure-requests). There is no nginx line for it on purpose: the nonce changes on every response, so the header must be set by the application that generates it, as the note says. For a site with no CSP at all, the API builds a starter policy from the scripts, styles and frames the page loads.

The same audit with curl:

Terminal
curl "https://website-security-audit-headers-ssl-grade.p.rapidapi.com/v1/site-audit/audit?url=python.org" \
  -H "X-RapidAPI-Key: YOUR_API_KEY" \
  -H "X-RapidAPI-Host: website-security-audit-headers-ssl-grade.p.rapidapi.com"

Audit several websites in one call

POST /v1/site-audit/audit/bulk audits up to 10 sites in parallel, in order. A site that cannot be reached gets its error and is not billed.

Python
sites = [
    "python.org",
    "github.com",
    "mozilla.org",
    "http.badssl.com",
    "expired.badssl.com",
    "this-domain-does-not-exist-4821.com",
]
r = requests.post(
    f"{API}/v1/site-audit/audit/bulk",
    headers=HEADERS,
    json={"urls": sites},
    timeout=120,
)
r.raise_for_status()
for row in r.json()["results"]:
    a = row.get("audit")
    print(row["input"], a["grade"] if a else row["error"]["code"])

The six sites came back in 3.1 seconds, billed 5 credits:

Site Grade Score First finding Note
github.com A 100 Permissions-Policy (warn) Strict CSP and preload-ready HSTS earn bonuses; a second warning (the _octo cookie without HttpOnly) also keeps it from A+
mozilla.org B 80 CSP (warn) Weak CSP, no Permissions-Policy
python.org C 70 CSP (fail) Report-only CSP
http.badssl.com F 15 TLS versions (fail) Page served over plain HTTP, no redirect
expired.badssl.com F 90 Certificate (fail) grade_cap: "Invalid certificate: certificate has expired."
this-domain-does-not-exist-4821.com none site_unreachable "Could not resolve ...", 0 credits

The expired host shows why caps exist. Its score is 90, because the page could not be loaded and its headers were never checked (the notes say so), yet a visitor sees a full-page certificate warning. The cap turns that into an F with the reason attached.

Grade staging headers in CI with /headers/analyze

Staging servers, intranets and preview deployments are often unreachable from the internet. POST /v1/site-audit/headers/analyze grades a block of headers you send, the output of curl -I, and fetches nothing. This is a typical PHP app behind nginx:

Terminal
curl -X POST "https://website-security-audit-headers-ssl-grade.p.rapidapi.com/v1/site-audit/headers/analyze" \
  -H "X-RapidAPI-Key: YOUR_API_KEY" \
  -H "X-RapidAPI-Host: website-security-audit-headers-ssl-grade.p.rapidapi.com" \
  -H "Content-Type: application/json" \
  -d '{"raw": "HTTP/2 200\nserver: nginx/1.18.0\nx-powered-by: PHP/8.1.2\ncontent-type: text/html; charset=UTF-8\nx-frame-options: SAMEORIGIN\nset-cookie: session=abc123; Path=/; HttpOnly\nstrict-transport-security: max-age=86400"}'

It scores 40, an F (shortened):

JSON
{
  "grade": "F",
  "score": 40,
  "summary": { "passed": 2, "warnings": 4, "failed": 3, "info": 4 },
  "checks": [
    { "id": "csp", "status": "fail", "points": -20, "message": "No Content-Security-Policy: an injected script runs with full access to the page." },
    { "id": "content_type_options", "status": "fail", "points": -5 },
    { "id": "cookie_secure", "status": "fail", "points": -10, "value": "session", "message": "1 cookie(s) without Secure can leak over plain HTTP." },
    { "id": "hsts", "status": "warn", "points": -10, "value": "max-age=86400", "message": "HSTS max-age is 1 days: use at least 180 days (1 year is usual)." },
    {
      "id": "server_leak",
      "status": "warn",
      "points": -5,
      "value": "Server: nginx/1.18.0 | x-powered-by: PHP/8.1.2",
      "fix": {
        "nginx": "server_tokens off;\nproxy_hide_header X-Powered-By;\nfastcgi_hide_header X-Powered-By;",
        "note": "PHP: expose_php = Off. Express: app.disable('x-powered-by'). ASP.NET: <httpRuntime enableVersionHeader=\"false\" />."
      }
    }
  ],
  "cookies": [{ "name": "session", "secure": false, "http_only": true }]
}

The cookie's value (abc123) never appears in the response: only names and flags are kept. In a pipeline, collect the headers from the staging build and fail the job below B:

Python
import sys

import requests

HOST = "website-security-audit-headers-ssl-grade.p.rapidapi.com"
API = f"https://{HOST}"
HEADERS = {"x-rapidapi-key": "YOUR_API_KEY", "x-rapidapi-host": HOST}
PASSING = {"A+", "A", "B"}

staging = requests.get("https://staging.internal.example/", timeout=30)
raw = "\n".join(f"{k}: {v}" for k, v in staging.headers.items())
r = requests.post(
    f"{API}/v1/site-audit/headers/analyze",
    headers=HEADERS,
    json={"raw": raw},
    timeout=30,
)
r.raise_for_status()
report = r.json()
if report["grade"] not in PASSING:
    for check in report["checks"]:
        if check["status"] == "fail":
            print(f"FAIL {check['id']}: {check['message']}")
    sys.exit(f"Security headers graded {report['grade']} ({report['score']})")

requests merges repeated headers such as Set-Cookie into one line; to see every cookie, pass the output of curl -sI instead.

TLS versions and certificate expiry

GET /v1/site-audit/tls?host= checks only the certificate and the protocol versions, with their own grade. badssl.com still accepts TLS 1.0 and 1.1 (shortened):

JSON
{
  "host": "badssl.com",
  "grade": "B",
  "score": 90,
  "grade_cap": { "grade": "B", "reason": "TLS 1.0 and TLS 1.1 accepted." },
  "checks": [
    {
      "id": "tls_versions",
      "status": "fail",
      "points": -10,
      "value": "TLS 1.0, TLS 1.1, TLS 1.2",
      "message": "TLS 1.0 and TLS 1.1 still accepted: deprecated since 2021 (RFC 8996), and refused by PCI DSS.",
      "fix": {
        "nginx": "ssl_protocols TLSv1.2 TLSv1.3;",
        "apache": "SSLProtocol -all +TLSv1.2 +TLSv1.3",
        "cloudflare": "SSL/TLS › Edge Certificates › Minimum TLS Version: TLS 1.2"
      }
    }
  ],
  "protocols": { "tls_1_0": true, "tls_1_1": true, "tls_1_2": true, "tls_1_3": false }
}

www.wikipedia.org gets an A+ on the same endpoint: only TLS 1.2 and 1.3, and a valid Let's Encrypt certificate covering 41 names. Expiry thresholds follow the certificate's lifetime (a third of it for a warning, a sixth for a failure, capped at 14 and 3 days), so a 90-day certificate renewed on schedule is never flagged, and neither are the very short-lived ones some ACME setups use.

Pricing and the Apify actor

Every endpoint costs 1 credit, and bulk costs 1 per site audited. The free BASIC plan gives 10 audits a day. PRO is $3.99 a month for 10,000 audits ($0.0004 each), ULTRA $9.99 for 50,000 and MEGA $29.99 for 200,000 ($0.00015 each). Unreachable sites use no credits. Plans are on the website security audit page, parameters in the API reference.

For a list of sites in a spreadsheet, the Website Security Audit - Bulk Headers, SSL & Grade actor on Apify audits them and exports one row per site, at $0.0015 per website. The email side of a domain (SPF, DKIM, DMARC) is covered in the SPF, DKIM and DMARC checker article, and the tech stack lookup article shows how to see which CMS and CDN a site runs.

What the security headers checker does not do

  • It is not a vulnerability scanner or a penetration test. It reads what any browser receives and performs normal TLS handshakes. It does not look for XSS, SQL injection or outdated plugins, and attacks nothing.
  • One page per call. Headers can differ between the home page, the login page and the API; audit the pages that matter.
  • No content behind a login. Pages that need a session are graded as an anonymous visitor sees them.
  • Bot walls. A site that serves a challenge page to unknown clients is graded on that page; the notes say so.
  • TLS without revocation or cipher detail. OCSP revocation is not checked, and cipher suites are not listed one by one.
  • Ports 80 and 443 only, and no private addresses: for internal hosts, paste the headers into /headers/analyze.
  • The starter CSP is a draft. Scripts can load other scripts at runtime; deploy it in report-only mode first.

Frequently asked questions

Which security headers should every website have?

At least Strict-Transport-Security, a Content-Security-Policy that restricts scripts, clickjacking protection (frame-ancestors or X-Frame-Options), X-Content-Type-Options: nosniff and a Referrer-Policy. Permissions-Policy is cheap to add. Cookies should carry Secure, HttpOnly and SameSite.

Do I still need X-XSS-Protection?

No. Chrome and Edge removed the XSS filter it controlled, and Firefox never had one. OWASP recommends leaving it out or setting it to 0, and relying on a Content-Security-Policy.

How do I add security headers in nginx?

Use add_header in the server block with the always flag, so the header is also sent on error pages: add_header X-Content-Type-Options "nosniff" always;. Note that an add_header inside a location block replaces all the ones inherited from server. The audit returns each line ready to paste.

Why does my site get an F when its certificate is valid?

Most often because http:// serves the page instead of redirecting to HTTPS, or because several failures stack up: no CSP (-20), no HSTS (-20) and no clickjacking protection (-15) already take a site to 45. The checks list shows each deduction.

How is this different from securityheaders.com or the MDN HTTP Observatory?

They are excellent manual tools for one site at a time. The API gives the same kind of checks as JSON with the fixes for nginx, Apache and Cloudflare, in bulk, and can grade headers from servers the internet cannot reach.

Get started

Website Security Audit API

Website security audit: headers, CSP, cookies, SSL/TLS and HTTPS, graded A+ to F with fixes.

  • Web Security
  • HTTP Headers
  • TLS
  • Python
  • DevOps