Skip to content
SIEMBench
100% Client-Side Tool • Inputs Never Sent to Our Servers

HTTP Security Headers & CSP Generator

Build a Content Security Policy with live grading, choose the other security headers, and copy configuration that is ready for your server.

Presets

default-src Fallback for fetch directives that are not set
script-src Scripts
style-src Stylesheets
img-src Images
font-src Fonts
connect-src Fetch, XHR, WebSocket and beacons
frame-ancestors Who may embed this page
base-uri Allowed base element URLs
form-action Where forms may submit
object-src Plugins and embedded objects

AYour policy, 100 of 100
  • Infoscript-src

    Replace {RANDOM_NONCE} with a new random value on every response. A fixed nonce gives no protection.

Ready-to-deploy output

One header per line, as a browser receives them.

How to use this tool in a SOC investigation

  1. Copy the affected site's Content-Security-Policy header and paste it under Audit an existing policy.
  2. Review the findings from the most severe to see whether injected script could have run.
  3. Build a corrected policy and export it for the team that owns the server.

Example: A site under investigation for a card skimmer sends default-src 'self'; script-src 'self' 'unsafe-inline' https:. The audit grades it F with two Critical findings, because injected inline scripts and scripts from any HTTPS host are both allowed.

Frequently asked questions

What is the safest way to introduce a CSP on an existing site?

Start with Content-Security-Policy-Report-Only and a reporting endpoint. Collect violations for long enough to cover every page and user journey, fix or allow the legitimate ones, and then enforce. You can keep sending a stricter report-only policy next to the enforced one to prepare the next step.

Can I use a nonce on a static site?

Not with files alone. A nonce must be unpredictable and different on every response, so something has to generate it and insert it into both the header and the HTML, such as an edge function or a server. A nonce hard-coded into a static file can be copied by an attacker. Use hashes of your inline scripts, or move them to files and allow self.

Should I add the HSTS preload directive?

Only after HTTPS works on the domain and every subdomain, including internal ones, and you are ready to keep it that way. Preloading is built into browsers and removal takes months to reach users. Ordinary HSTS with a long max-age protects returning visitors without that commitment.

Are the policies I paste sent anywhere?

No. Grading, building and exporting run 100% client-side in your browser, with no network requests. The tool does not contact the site a policy belongs to, so you can audit internal applications without exposing their hostnames to us.

How CSP limits cross-site scripting

Cross-site scripting (XSS) happens when an attacker gets their own script into your page. Output encoding and safe templates are the primary defense. A Content Security Policy is the second layer. It tells the browser which scripts are yours, so that an injected one is refused even when the first defense fails.

There are two ways to say which scripts are yours. An allowlist names hosts, as in script-src 'self' https://cdn.example.com. It is easy to write but often weak, because a large host may serve something that an attacker can use, such as a JSONP endpoint or an old library. A strict policy marks individual scripts with a random nonce or a hash and adds 'strict-dynamic', which lets those scripts load others. Host names then stop mattering.

Content-Security-Policy: script-src 'nonce-R4nd0mPerResponse' 'strict-dynamic'; object-src 'none'; base-uri 'none'

The companion directives close common bypasses. object-src 'none' blocks plugin content. base-uri 'none' stops an injected base element from redirecting relative script URLs. form-action limits where an injected form can send data.

How CSP prevents clickjacking

In a clickjacking attack, another site loads your page in an invisible frame and tricks the user into clicking it. frame-ancestors lists who may frame the page, and 'none' forbids everyone. Two details catch people out. It does not fall back to default-src, so leaving it out means no protection. It also has no effect in a meta element, so it has to be sent as a header.

What the linter looks for

SeverityExamples
CriticalScripts unrestricted, 'unsafe-inline' without a nonce or hash, * or https: for scripts
High'unsafe-eval', no object-src 'none', data: scripts, unquoted keywords
MediumNo frame-ancestors or base-uri, http: sources, short nonces, unknown directives
LowNo form-action or default-src, wildcard images

The grade is a summary to compare drafts. It cannot tell whether the policy suits your site, and a high grade on a policy that breaks checkout is no success. Read the findings and test in a browser.

Enforced and report-only policies

Content-Security-Policy blocks violations. Content-Security-Policy-Report-Only blocks nothing and reports what would have been blocked. Both can be sent on the same response and are evaluated independently, which makes it possible to enforce one policy while testing a stricter one.

Reports go to the URL in report-uri, or to an endpoint named by report-to and defined in the Reporting-Endpoints header. Sending both covers more browsers, and the Report-Only preset does so. Expect noise: browser extensions inject scripts and cause violations that have nothing to do with your code. upgrade-insecure-requests and sandbox are ignored in a report-only policy. Remember that reports contain page URLs, so treat the endpoint's data accordingly.

Using Google Analytics and AdSense

Google states that it supports only a strict, nonce-based policy for AdSense and not an allowlist, because its ad domains change. The preset follows that published policy. It includes 'unsafe-eval', which costs points in the grade. Every script tag needs the nonce, including the ad code, so a purely static site cannot use it without an edge function.

HSTS and preload pitfalls

Strict-Transport-Security tells a browser to use only HTTPS for your host for max-age seconds. It defeats downgrade attacks after the first visit, and it removes the option to click through certificate warnings. That last property is also the risk: if your certificate fails, users cannot get in.

How Nginx and Apache inherit headers

In Nginx, add_header directives are inherited from the level above only if the current level defines none of its own. Adding a single cache header in a location block silently removes every security header there. Put the shared headers in a file and include it in each block that adds its own, or use add_header_inherit merge; in version 1.29.3 or later. The always parameter matters too. Without it, headers are added only to a fixed list of success and redirect codes, so error pages are unprotected.

In Apache, mod_headers keeps two tables, onsuccess (the default) and always. Header always set also covers errors and internal redirects such as custom error documents. The tables are separate, so a header set by your application in one and by Apache in the other can be sent twice. If that happens, add Header onsuccess unset for that name before the always line.

Escaping differs by server

The exports escape each value for their target. Nginx expands $name inside quotes and offers no escape, so a literal dollar sign is written with a geo variable. Apache treats % as a format specifier, so it is doubled. Cloudflare Pages limits each line of _headers to 2,000 characters, and neither Cloudflare Pages nor Netlify applies the file to responses from functions. Express output creates a fresh nonce for each request.

The other headers

After deploying, request a normal page, a redirect, an error page and a static file, and confirm the headers on each. Content delivery networks and application frameworks can add, remove or duplicate headers along the way.

Why is 'unsafe-inline' rated Critical in one policy and Info in another?

On its own it lets injected inline scripts run, which defeats the main purpose of CSP. When the same directive has a nonce or a hash, or 'strict-dynamic', browsers that support those ignore 'unsafe-inline'. It then remains only as a fallback for very old browsers.

Do I still need X-Frame-Options if I have frame-ancestors?

Browsers that support CSP use frame-ancestors from an enforced policy and ignore X-Frame-Options. Sending both is harmless and covers old clients, as long as they agree: DENY matches 'none', and SAMEORIGIN matches 'self'. X-Frame-Options cannot list several allowed sites, so use frame-ancestors for that.