Security headers
HTTP security headers are declarative defenses: the server tells the browser how to behave to mitigate XSS, clickjacking, HTTP downgrade, MIME sniffing, information leakage and origin isolation. Their absence isn’t a flaw by itself, but it enables or worsens other vulnerabilities, so they’re a mandatory part of any audit. The invariant they uphold is that the browser only does what the policy allows: with no policy, the browser assumes the most permissive behavior.
Threat model
Section titled “Threat model”Without the right headers, a reflected XSS exploits frictionlessly, a
page can be framed (clickjacking), traffic downgrades to HTTP
(MITM/SSL stripping), tokens leak via Referer, and uploaded content is interpreted as
executable (upload). Headers don’t create the vulnerability, but
their absence is the difference between a theoretical flaw and an exploitable one.
Catalog (what each one stops and recommended value)
Section titled “Catalog (what each one stops and recommended value)”Content-Security-Policy (CSP)
Section titled “Content-Security-Policy (CSP)”Controls where resources load from and which scripts run: defense in depth against XSS
and exfiltration. Prefer nonce/hash + strict-dynamic (see XSS);
avoid unsafe-inline/unsafe-eval, which nullify it.
Content-Security-Policy: default-src 'self'; script-src 'nonce-RAND' 'strict-dynamic'; object-src 'none'; base-uri 'none'; frame-ancestors 'none'Strict-Transport-Security (HSTS)
Section titled “Strict-Transport-Security (HSTS)”Forces HTTPS in the browser, prevents downgrade and SSL stripping. The preload
directive alone does not protect the first visit: that only happens once the domain is
submitted to hstspreload.org, accepted and shipped in browsers’ preload lists; otherwise the
policy is learned from the first HTTPS response.
Strict-Transport-Security: max-age=63072000; includeSubDomains; preloadAnti-clickjacking
Section titled “Anti-clickjacking”CSP frame-ancestors (modern) and X-Frame-Options (compatibility). Detail in
clickjacking.
Content-Security-Policy: frame-ancestors 'none'X-Frame-Options: DENYX-Content-Type-Options
Section titled “X-Content-Type-Options”Prevents MIME sniffing (the browser guessing the type and running as script something uploaded as an image).
X-Content-Type-Options: nosniffReferrer-Policy
Section titled “Referrer-Policy”Limits URL (and in-URL token) leakage via the Referer header.
Referrer-Policy: strict-origin-when-cross-originPermissions-Policy
Section titled “Permissions-Policy”Restricts powerful browser APIs (camera, mic, geolocation, USB…).
Permissions-Policy: geolocation=(), camera=(), microphone=(), payment=()Origin isolation (COOP / COEP / CORP)
Section titled “Origin isolation (COOP / COEP / CORP)”Protect against cross-origin and side-channel attacks (Spectre) and enable high-precision
APIs like SharedArrayBuffer.
Cross-Origin-Opener-Policy: same-originCross-Origin-Embedder-Policy: require-corpCross-Origin-Resource-Policy: same-originCookies (flags and prefixes)
Section titled “Cookies (flags and prefixes)”The session transport is a “security header” too. SameSite mitigates
CSRF; HttpOnly prevents theft via XSS; the browser enforces the
prefixes.
Set-Cookie: sid=...; HttpOnly; Secure; SameSite=LaxSet-Cookie: __Host-sid=...; Secure; Path=/Set-Cookie: __Secure-sid=...; Secure__Host- requires Secure, Path=/ and no Domain attribute, binding the cookie to
that exact host, so only __Host- stops a subdomain (or a
takeover) from setting cookies for the parent host. __Secure-
only requires Secure and still permits Domain=, so a controlled subdomain can set a
__Secure- cookie for the parent domain.
Others
Section titled “Others”Cache-Control: no-store on pages with sensitive data; Clear-Site-Data: "*" on logout.
Red Team
Section titled “Red Team”Assess what’s missing and leverage it: no CSP → trivial XSS; no frame-ancestors →
clickjacking; no HSTS → downgrade/MITM; lax Referer → token leakage; no nosniff → XSS
via uploaded content; cookie without HttpOnly → session theft from XSS. The flow is: map
the present headers, cross them with candidate vulnerabilities, and use the absence as a
multiplier in the report.
# Dump a route's security headerscurl -sD - -o /dev/null https://victim.tld/ \ | grep -iE 'content-security-policy|strict-transport|x-frame|x-content-type|referrer-policy|permissions-policy'Tools: securityheaders.com, Mozilla Observatory, CSP Evaluator (to spot weak
CSPs with unsafe-inline), nuclei and Burp.
Blue Team
Section titled “Blue Team”Recommended set (summary)
Section titled “Recommended set (summary)”Apply all of the above site-wide (not just the home page); CSP first in
Content-Security-Policy-Report-Only to measure before enforcing; __Host- for session
cookies; no-store on sensitive data.
Detection
Section titled “Detection”Periodic header scanning across all hosts; alert if missing in production or if a CSP
includes unsafe-inline/unsafe-eval. Collect violations via report-to/report-uri.
Telemetry and sources
Section titled “Telemetry and sources”Header scanners in CI/CD, CSP reports (report-to), WAF/edge config, and host inventory
(including forgotten subdomains).
Response
Section titled “Response”Centralize the headers in a middleware/edge to avoid uncovered routes; if a CSP caused false
negatives, harden it (remove unsafe-*, move to nonce).
CVEs and real-world cases
Section titled “CVEs and real-world cases”- Usually not a CVE: they’re configuration. Their absence has turned theoretical XSS/clickjacking into exploitable in countless audits and bug-bounty programs, and is a common observation in compliance reports (PCI DSS, ENS).
- A badly built CSP (with
unsafe-inlineor a wildcard domain hosting uploadable content) is as ineffective as having none: it shows up constantly as a CSP bypass.
Product advisories in NVD (https://nvd.nist.gov/vuln/search) and GitHub Advisories (https://github.com/advisories).
Testing checklist
Section titled “Testing checklist”- CSP present and robust (no
unsafe-inline), evaluated with CSP Evaluator. - HSTS (ideally with
preload),X-Content-Type-Options: nosniff. -
frame-ancestors/X-Frame-Options. -
Referrer-PolicyandPermissions-Policy. - Cookie flags and prefixes (
HttpOnly/Secure/SameSite/__Host-). -
Cache-Control: no-storeon pages with sensitive data. - Headers present on all hosts, not just the home page.