A+ Security Score ReadyNext.js 15+ · Nginx · CloudflareOWASP Top 10 Aligned🔒 100% Client-Side

Security Headers & CSP Generator

Generate Content-Security-Policy (CSP), HSTS, X-Frame-Options and Permissions-Policy security headers for Next.js 15+, Nginx, Cloudflare and Apache web servers, and armor your site against XSS and clickjacking at an A+ level.

Guide to HTTP Security Headers, Content Security Policy (CSP) and OWASP Security

In modern web applications, security is not limited to backend code quality. HTTP Security Headers, which work at the browser level, are the first line of defense that brings Cross-Site Scripting (XSS), clickjacking, man-in-the-middle (MITM) attacks and data leaks down to zero. This tool generates headers that deliver an A+ Security Score in one click for Next.js 15+, Nginx, Cloudflare and Apache.

1. Critical HTTP Security Headers and What They Do

The 6 core headers every modern site should have, according to Mozilla Observatory, SecurityHeaders.com and OWASP security criteria:

HeaderRecommended ValueThreat It PreventsSecurity Score Impact
Content-Security-Policy (CSP)default-src 'self'; script-src 'self'...XSS (Cross-Site Scripting), data theft, unauthorized code injection.+30 Points (Most Critical)
Strict-Transport-Security (HSTS)max-age=63072000; includeSubDomains; preloadMITM (man-in-the-middle), SSL stripping, insecure HTTP connections.+25 Points
X-Frame-OptionsDENY (or SAMEORIGIN)Clickjacking (embedding the site in a hidden iframe to trick users into clicking buttons).+15 Points
X-Content-Type-OptionsnosniffMIME-type sniffing (malicious scripts disguised as images or text being executed).+10 Points
Referrer-Policystrict-origin-when-cross-originSensitive URL parameters and session tokens leaking to external sites.+10 Points
Permissions-Policycamera=(), microphone=(), geolocation=()Unauthorized access to the user's hardware sensors (camera, microphone, location).+10 Points

2. Next.js 15+ next.config.mjs or Middleware Integration

In Next.js projects, adding the headers to next.config.mjs is the most performant approach. The server attaches the response headers to every request:

// next.config.mjs /** @type {import('next').NextConfig} */ const nextConfig = { async headers() { return [ { source: '/(.*)', headers: [ { key: 'Content-Security-Policy', value: "default-src 'self'; script-src 'self' 'unsafe-inline' https://apis.google.com; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self' data:;", }, { key: 'Strict-Transport-Security', value: 'max-age=63072000; includeSubDomains; preload', }, { key: 'X-Frame-Options', value: 'DENY', }, { key: 'X-Content-Type-Options', value: 'nosniff', }, { key: 'Referrer-Policy', value: 'strict-origin-when-cross-origin', }, { key: 'Permissions-Policy', value: 'camera=(), microphone=(), geolocation=()', }, ], }, ] }, } export default nextConfig

3. Production Configuration for the Nginx Web Server

If you use an Nginx reverse proxy on Linux or Docker, you can place these directives in /etc/nginx/conf.d/security.conf:

# Nginx Security Headers add_header X-Frame-Options "DENY" always; add_header X-Content-Type-Options "nosniff" always; add_header Referrer-Policy "strict-origin-when-cross-origin" always; add_header Strict-Transport-Security "max-age=63072000; includeSubDomains; preload" always; add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always; add_header Content-Security-Policy "default-src 'self'; img-src 'self' data: https:; script-src 'self' 'unsafe-inline';" always;

Frequently Asked Questions (FAQ)

HTTP security headers give the browser strict security directives, preventing Cross-Site Scripting (XSS), clickjacking, MITM attacks and data leaks at the browser layer.
Use the async headers() function in next.config.mjs at the root of your Next.js project to add security headers to every route.
It is a global security list that guarantees browsers never connect to your site over unencrypted HTTP. Sites are approved through hstspreload.org.
If it is not configured properly, it can block external scripts or fonts. The Google Analytics, Google Fonts and Clerk presets in this tool make integration seamless.
A strict default CSP blocks external resources. However, when you select third-party services such as Google Analytics, Google Fonts or Clerk Auth in the presets section of this tool, the required domains (e.g. https://www.googletagmanager.com) are added to the directives automatically.
The HSTS header only takes effect after a user has visited your site over HTTPS once. Once you register on the preload list (hstspreload.org), Chrome, Firefox and Safari treat your site as HTTPS-only out of the box; even if the user types "http://", the browser redirects to HTTPS before making any network request.
Yes. Google treats a secure web experience (HTTPS, no-sniffing, XSS protection) as a direct ranking signal. In addition, websites with security breaches are penalized by Google with a "This site may not be secure" warning.