Skip to content

Security headers generator

Free, no sign-up Runs in your browser

Choose your HTTP security headers and copy the config for nginx, Apache, Caddy, Next.js or Express: HSTS, CSP, nosniff, framing, Referrer-Policy and more.

Transport

Content and framing

Paste a policy from the CSP generator. Left empty, no policy is sent apart from frame-ancestors below.

Privacy and features

Features to switch off or limit. Left empty, the header is not sent.

Cross-origin isolation

Use same-origin-allow-popups if the site opens pop-ups for sign-in or payment.

same-origin stops other sites from embedding your files. Use cross-origin for a public CDN.

Only needed for cross-origin isolation (SharedArrayBuffer). It blocks third-party resources that do not opt in.

Your headers

HTTP headers
Strict-Transport-Security: max-age=31536000; includeSubDomains
Content-Security-Policy: frame-ancestors 'self'
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
Referrer-Policy: strict-origin-when-cross-origin
Permissions-Policy: camera=(), microphone=(), geolocation=()
Cross-Origin-Opener-Policy: same-origin
Cross-Origin-Resource-Policy: same-origin
nginx
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header Content-Security-Policy "frame-ancestors 'self'" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Permissions-Policy "camera=(), microphone=(), geolocation=()" always;
add_header Cross-Origin-Opener-Policy "same-origin" always;
add_header Cross-Origin-Resource-Policy "same-origin" always;
Apache (mod_headers)
Header always set Strict-Transport-Security "max-age=31536000; includeSubDomains"
Header always set Content-Security-Policy "frame-ancestors 'self'"
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "SAMEORIGIN"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
Header always set Permissions-Policy "camera=(), microphone=(), geolocation=()"
Header always set Cross-Origin-Opener-Policy "same-origin"
Header always set Cross-Origin-Resource-Policy "same-origin"
Caddy
header {
	Strict-Transport-Security "max-age=31536000; includeSubDomains"
	Content-Security-Policy "frame-ancestors 'self'"
	X-Content-Type-Options "nosniff"
	X-Frame-Options "SAMEORIGIN"
	Referrer-Policy "strict-origin-when-cross-origin"
	Permissions-Policy "camera=(), microphone=(), geolocation=()"
	Cross-Origin-Opener-Policy "same-origin"
	Cross-Origin-Resource-Policy "same-origin"
}
Next.js (next.config)
async headers() {
  return [
    {
      source: '/(.*)',
      headers: [
        { key: "Strict-Transport-Security", value: "max-age=31536000; includeSubDomains" },
        { key: "Content-Security-Policy", value: "frame-ancestors 'self'" },
        { key: "X-Content-Type-Options", value: "nosniff" },
        { key: "X-Frame-Options", value: "SAMEORIGIN" },
        { key: "Referrer-Policy", value: "strict-origin-when-cross-origin" },
        { key: "Permissions-Policy", value: "camera=(), microphone=(), geolocation=()" },
        { key: "Cross-Origin-Opener-Policy", value: "same-origin" },
        { key: "Cross-Origin-Resource-Policy", value: "same-origin" },
      ],
    },
  ];
},
Express middleware
app.use((req, res, next) => {
  res.setHeader("Strict-Transport-Security", "max-age=31536000; includeSubDomains");
  res.setHeader("Content-Security-Policy", "frame-ancestors 'self'");
  res.setHeader("X-Content-Type-Options", "nosniff");
  res.setHeader("X-Frame-Options", "SAMEORIGIN");
  res.setHeader("Referrer-Policy", "strict-origin-when-cross-origin");
  res.setHeader("Permissions-Policy", "camera=(), microphone=(), geolocation=()");
  res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
  res.setHeader("Cross-Origin-Resource-Policy", "same-origin");
  next();
});

In nginx, an add_header inside a location block replaces every add_header inherited from the server block. Put these lines where they apply to all responses, or repeat them.

X-XSS-Protection is left out on purpose. Current browsers have removed the filter it controlled, and in old browsers the filter could be abused to leak data. A Content Security Policy does the job.

Everything you type here stays in your browser. Nothing is sent to HardenKit or to anyone else.

How to use the security headers generator

  1. Go through the groups and switch each header on or off.
  2. Paste a Content Security Policy if you have one, or build it with the CSP generator.
  3. Copy the block for your server or framework.
  4. Deploy, then paste the response headers into the security headers checker.

About this tool

HTTP security headers are instructions a site gives the browser: use HTTPS only, do not guess content types, do not let other sites frame this page, send less in the Referer header, switch off features the site does not use. Each one closes a specific class of attack, and all of them are a line or two of server config.

The generator starts from safe values: a year of HSTS, nosniff, framing limited to the same origin through both X-Frame-Options and the CSP directive frame-ancestors, strict-origin-when-cross-origin, and the camera, microphone and geolocation switched off. The cross-origin headers are worth a second look, because same-origin for Cross-Origin-Resource-Policy stops other sites from embedding your files, which a public asset host does not want.

One header is left out on purpose. X-XSS-Protection controlled an XSS filter that browsers have since removed, and in old browsers the filter could be turned against the page. A Content Security Policy replaces it. Add headers on a staging site first, since HSTS with includeSubDomains and a strict CSP can break things that worked before.

Sources

Questions

Which security headers should every site have?

On an HTTPS site: Strict-Transport-Security, X-Content-Type-Options: nosniff, a rule against framing (frame-ancestors in a CSP, with X-Frame-Options for old browsers), a Referrer-Policy and a Content Security Policy. Permissions-Policy and the cross-origin headers add hardening on top.

Why is X-XSS-Protection not included?

The header is deprecated. Chrome, Edge and Firefox do not have the filter it controlled, and in browsers that did, the filter could be abused to disable scripts selectively or leak data. Current guidance is to leave it out or send the value 0, and to use a Content Security Policy.

Do I need both X-Frame-Options and frame-ancestors?

frame-ancestors in a Content Security Policy is the current standard and overrides X-Frame-Options in browsers that support it. X-Frame-Options still covers very old browsers, so sending both is harmless and common. They should say the same thing.

Why do my headers disappear in some nginx locations?

nginx inherits add_header lines from the outer block only when the inner block has none of its own. One add_header in a location block drops every header set at server level for that location. Repeat the lines, or keep them in a file you include in each block.

Related tools