Definition
Security headers are HTTP response headers that provide an additional layer of security by instructing the browser on how to behave when interacting with a website. They help protect against common web threats like cross-site scripting (XSS), clickjacking, and data sniffing.How It Works
- X-Content-Type-Options: Prevents MIME type sniffing by enforcing the declared content type.
- X-Frame-Options: Stops the page from being framed, protecting against clickjacking.
- Strict-Transport-Security (HSTS): Forces browsers to use HTTPS, preventing man-in-the-middle attacks.
- Referrer-Policy: Controls the amount of referrer information sent when navigating from the website.
- Permissions-Policy: Manages the use of browser features like geolocation, camera, and microphone.
- X-XSS-Protection: (Deprecated) Was used to enable the browser's built-in XSS protection.
- Content-Security-Policy (CSP): Restricts resources the browser can load, mitigating XSS and data injection attacks.
Key Characteristics
- Enforced by Browsers: Security headers are directives communicated from server to client and enforced by the browser.
- Variety of Protections: They cover different aspects of security, from content type validation to resource loading restrictions.
- Configurable: Headers can be tailored to suit the specific security needs of the application.
Comparison
| Header | Purpose | Current Status |
|---|---|---|
| X-Content-Type-Options | Prevents MIME type sniffing | Active |
| X-Frame-Options | Defends against clickjacking | Active |
| HSTS | Enforces HTTPS | Active |
| Referrer-Policy | Controls referrer information | Active |
| Permissions-Policy | Manages browser feature permissions | Active |
| X-XSS-Protection | Legacy XSS protection | Deprecated |
| CSP | Mitigates XSS and data injection | Active |
Real-World Example
The CVE-2019-11043 vulnerability in PHP-FPM was mitigated using CSP and HSTS headers to prevent exploitation by ensuring secure resource loading and forcing HTTPS.Detection & Prevention
- Test using
httpxor browser DevTools to verify active headers. - Use OWASP ZAP or Burp Suite for comprehensive security header analysis.
- Regularly review and update headers according to security best practices.
Common Misconceptions
- Security Headers Replace Firewalls: They complement, not replace, other security measures.
- HSTS is Optional: Lack of HSTS can lead to vulnerabilities in HTTPS implementation.
- CORS and Security Headers are the Same: CORS handles resource sharing, not threats directly.