Overview
Security rules protect your website and users from common attacks, data breaches, and vulnerabilities. Proper security also builds trust and is a ranking factor for search engines.HTTPS Enforcement
Rule: security/https
What it checks:
- Site served over HTTPS (not HTTP)
- Valid SSL/TLS certificate
- No mixed content (HTTP resources on HTTPS pages)
- HTTPS redirect from HTTP
Enable HTTPS
Enable HTTPS
Steps:
-
Get an SSL certificate:
- Free: Let’s Encrypt
- Paid: DigiCert, Sectigo, GlobalSign
- Automatic: Cloudflare, Netlify, Vercel (free)
- Install certificate on server:
- Fix mixed content:
Security Headers
Rule: security/headers
What it checks:
- Content-Security-Policy (CSP)
- Strict-Transport-Security (HSTS)
- X-Frame-Options
- X-Content-Type-Options
- Referrer-Policy
- Permissions-Policy
Content-Security-Policy (CSP)
CSP Configuration
CSP Configuration
What it prevents:CSP Directives:
Testing CSP:Start with report-only mode:Monitor reports, fix violations, then enforce.
- Cross-Site Scripting (XSS) attacks
- Data injection attacks
- Unauthorized script execution
| Directive | Purpose | Example |
|---|---|---|
default-src | Fallback for all resources | 'self' |
script-src | JavaScript sources | 'self' https://cdn.com |
style-src | CSS sources | 'self' 'unsafe-inline' |
img-src | Image sources | 'self' https: data: |
font-src | Font sources | 'self' https://fonts.gstatic.com |
connect-src | AJAX/fetch/WebSocket | 'self' https://api.example.com |
frame-ancestors | Who can embed page | 'none' or 'self' |
Strict-Transport-Security (HSTS)
HSTS Configuration
HSTS Configuration
What it prevents:Parameters:
- Downgrade attacks (forcing HTTP)
- SSL stripping
- Cookie hijacking
max-age=31536000: 1 year (in seconds)includeSubDomains: Apply to all subdomainspreload: Submit to HSTS preload list
X-Frame-Options
X-Frame-Options Configuration
X-Frame-Options Configuration
What it prevents:Options:
- Clickjacking attacks
- UI redressing
- Iframe embedding attacks
DENY: Cannot be framed by anyoneSAMEORIGIN: Can only be framed by same domainALLOW-FROM uri: Deprecated, use CSPframe-ancestorsinstead
X-Content-Type-Options
X-Content-Type-Options Configuration
X-Content-Type-Options Configuration
What it prevents:This forces browsers to respect the
- MIME type sniffing attacks
- Script execution from non-script files
Content-Type header and prevents executing scripts from files with incorrect MIME types.Referrer-Policy
Referrer-Policy Configuration
Referrer-Policy Configuration
What it controls:Options:
- How much referrer information is sent with requests
- Privacy and security of outbound links
no-referrer: Never send referrersame-origin: Send referrer to same origin onlystrict-origin: Send origin only on HTTPS → HTTPSstrict-origin-when-cross-origin: Full URL for same-origin, origin only for cross-origin (recommended)
Complete Security Headers Example
Cookie Security
Rule: security/cookies
What it checks:
- Secure flag on cookies (HTTPS only)
- HttpOnly flag (prevents JavaScript access)
- SameSite attribute (CSRF protection)
Secure Cookie Configuration
Secure Cookie Configuration
Sensitive Data Exposure
Rule: security/secrets
What it checks:
- No API keys in HTML/JavaScript
- No credentials in source code
- No leaked secrets in error messages
Prevent Secret Leaks
Prevent Secret Leaks
Common leaks:Use environment variables:Add to .gitignore:
Testing Security
Security Headers
Test your site’s security headers and get a grade
Mozilla Observatory
Comprehensive security scan including TLS, headers, and more
SSL Labs
Deep analysis of SSL/TLS configuration
CSP Evaluator
Test and validate your Content Security Policy
Security Checklist
Enable HTTPS
- Get SSL certificate (Let’s Encrypt is free)
- Redirect HTTP → HTTPS
- Fix mixed content warnings
Add Security Headers
- Strict-Transport-Security (HSTS)
- Content-Security-Policy (CSP)
- X-Frame-Options
- X-Content-Type-Options
- Referrer-Policy
Secure Cookies
- Set Secure flag (HTTPS only)
- Set HttpOnly flag (prevent XSS)
- Set SameSite attribute (prevent CSRF)
Protect Secrets
- Never commit secrets to git
- Use environment variables
- Keep API keys on backend only
- Rotate credentials regularly
Related Pages
Performance Rules
Page speed, compression, and optimization
Accessibility Rules
WCAG compliance and inclusive design
Running Audits
Learn how to run security audits
Interpreting Results
Understand security scores and fix vulnerabilities