CSP Grading, Cross-Origin Isolation and Report-Only Headers

Open Tool Security Headers Builder

CSP Grading, Cross-Origin Isolation and Report-Only Headers

When to use

A scanner reports a missing CSP, and the first reflex is to paste default-src *. The score improves, the protection does not. This builder is for teams that want to move from passing a scan to observing a policy safely in production.

It covers static sites, APIs, admin consoles, storefronts and multi-tenant SaaS. Each preset changes framing, HSTS lifetime and isolation defaults. Start with the closest preset, then tune individual sources.

It does not generate per-request nonces, server-side template code or per-user policies. Those belong in the application framework; a static header block only covers half the job.

Steps

  1. Choose a preset and confirm the HSTS lifetime, framing policy, referrer policy and preload state.
  2. Fill the CSP allowlists. Put script CDNs in script-src, fonts and styles in style-src, images in img-src, and APIs in connect-src.
  3. In the isolation and reporting card, choose CORP and COEP, then enable report-only mode and an HTTPS report URL if needed.
  4. Read the risk checks and A–E grade, fixing unsafe-inline, plaintext origins and missing HSTS first.
  5. Select Nginx, Apache, Next.js or Cloudflare output, copy it, and observe reports on a test host before production.

Screenshots

Default state: presets and allowlists on the left, deployment output on the right

This is the static-site preset. The Nginx block shows complete CSP, HSTS, X-Frame-Options and Permissions-Policy lines.

A real interaction: the storefront preset allows a CDN and image host

After I chose the storefront preset, the CSP gained https://cdn.jsdelivr.net and an image host, and frame-ancestors changed from none to self.

Preview detail: CORP, COEP and Origin-Agent-Cluster together

The last image focuses on the lower half of the output. The three isolation headers sit together so you can confirm they were enabled as a set.

Features in detail

A preset changes policy, not just labels. A static site starts with default-src 'self' and frame-ancestors 'none'. An API uses default-src 'none' and also disables form submission. Admin consoles get two-year HSTS and preload. Storefronts allow common CDNs and image hosts. SaaS enables CORP and COEP by default.

CSP is assembled by directive. base-uri, object-src, frame-ancestors and form-action are fixed first, then script-src, style-src, img-src, font-src, connect-src, media-src, worker-src and manifest-src are added. Origins are de-duplicated; *, plaintext HTTP and unknown values are rejected with a warning.

Strict mode omits unsafe-inline and unsafe-eval and adds script-src-attr 'none' so inline event-handler attributes cannot execute script. Compatibility mode adds both and lowers the grade. The storefront preset allows only the image and API hosts you enter; it no longer appends a blanket https: source. The self-check shows which line reduced the score.

Cross-origin isolation uses three headers: Cross-Origin-Opener-Policy: same-origin, Cross-Origin-Embedder-Policy and Cross-Origin-Resource-Policy. With COEP enabled, third-party images and scripts need CORP or CORS, or they are blocked.

Report mode swaps the header to Content-Security-Policy-Report-Only and appends report-uri and report-to. A valid HTTPS URL also produces Reporting-Endpoints. Report mode records violations; it does not block them.

What you get

The input includes the preset, HSTS lifetime, framing policy, referrer policy, four CSP source fields, CSP mode, sandbox, CORP, COEP, a report URL and five switches.

The output is a server configuration. Nginx uses add_header ... always, Apache uses Header always set, Next.js emits a headers() array, and Cloudflare emits a _headers path-and-header block.

Copy writes the current format to the clipboard. Download names the file by target: .conf for Nginx and Apache, next.config.js for Next.js, and _headers for Cloudflare.

Parameters

ControlTypeDefaultNotes
PresetchipsStatic siteFive options with full defaults
HSTS lifetimeselect1 year0 disables the header
FramingselectDeny allnone or self
Referrer policyselectCross-origin origin onlyThree options
Extra script-srctextemptyComma or space separated
Extra style-srctextemptySame format
Extra img-srctextemptySame format
Extra connect-srctextemptySame format
Inline policyselectStrictStrict or compatibility
SandboxselectnoneTwo sandbox variants
CORPselectsame-originFour options, including off
COEPselectoffrequire-corp or credentialless
Report URLtextemptyMust be an HTTPS URL
Report-onlyswitchoffChanges the header name and adds reporting

Self-check list

  • □ frame-ancestors and X-Frame-Options express the same policy.
  • □ Strict CSP has no unsafe-inline or unsafe-eval.
  • □ HSTS includes includeSubDomains, and preload is paired with a two-year lifetime.
  • □ With COEP enabled, third-party assets provide CORP or CORS.
  • □ The report URL is a full HTTPS URL, and Reporting-Endpoints matches the CSP report-to name.
  • □ Nginx layers do not overwrite the security headers with a later add_header.

FAQ

Question: Can report-only mode be the production configuration? Answer: It reports but does not block. Observe first, then switch to enforcement; otherwise XSS still executes.

Question: Why is there no object-src in the API CSP? Answer: The API preset uses default-src 'none', which already blocks object loading. Static presets still write object-src 'none' explicitly.

Question: Can HSTS be rolled back after two years? Answer: Yes, but browsers remember the old value. Make sure every subdomain has a certificate and accept a period where downgrade is impossible.

Question: Why do images break after enabling COEP? Answer: Add Cross-Origin-Resource-Policy: cross-origin to the image host, or serve CORS headers. Without either, isolation mode rejects the load.

Question: Why do security headers only appear on the home page in Nginx? Answer: add_header in a server or location block replaces the same header from a parent. Put it at a shared level or repeat it in every block.

Limits

The builder does not generate nonces, hashes or server template code. Per-request CSP belongs in the application framework, with the result emitted as a response header.

It does not crawl the real page or collect online reports. Allowlists must come from the browser console and report samples, not guesses.

Cloudflare _headers applies to Pages or Netlify-style static hosting. Workers and Transform Rules use a different syntax.

Design trade-offs

CSP is built from fixed directives and dynamic sources. Sources are parsed, de-duplicated and validated before they are merged by directive. With fewer than twenty sources, generation stays around one millisecond and performs no network request.

I did not add automatic resource discovery. Crawling a live site involves cross-origin requests, login and caching, and produces false positives. The trade-off is explicit sources, so every relaxation is auditable.

Continuous input is coalesced into one frame, and identical signatures skip a redraw. A preset switch writes more than a dozen controls at once but repaints only once, avoiding intermediate flicker. A typical Nginx block contains ten headers and roughly fourteen CSP directives, so the whole string stays small enough to rebuild in a single frame without a worker.

Validation rejects a wildcard origin instead of silently widening the policy. Plain HTTP origins are upgraded to HTTPS, duplicate values are removed, and unknown strings are dropped with a warning. That means the final header can be read as a list of explicit origins, not a mixture of guesses and copied values from an old server block. The cost is a few extra keystrokes; the benefit is a policy that can be reviewed line by line.

Troubleshooting

Symptom: the console says Refused to load the script. The script-src list is missing the real CDN. Read the blocked origin and add it explicitly; do not add https: as a shortcut.

Symptom: the page loads but share-card images disappear. Either img-src lacks the image host, or COEP blocked an image without CORP. Check both img-src and Cross-Origin-Resource-Policy.

Symptom: some subdomains fail after HSTS. includeSubDomains now covers a host without a certificate. Add the certificate, or shorten max-age and send a new header.

Diagnostic order: CSP reports, actual response headers, server inheritance, then policy changes. Do not delete CSP as the first move.

Workflow and acceptance

Roll out in stages: HSTS and nosniff first, then report-only CSP for a week, then enforcement, then COEP and CORP. Each step can be reverted independently.

For team work, keep the header block in version control and review it with deployment scripts. Environments may use different report URLs, but the policy body should stay the same.

Acceptance: curl -I shows CSP, HSTS, X-Frame-Options and Referrer-Policy; strict mode has no unsafe-inline; the report URL receives samples; core images still load with COEP; the grade is A or B.

Version and compliance

This release is 1.1.4 and follows ToolCMS plugin spec 3.19. The page requests no external resources, uploads no configuration and reads no site response. Headers are assembled locally.

Security headers are one layer. Input validation, output encoding, dependency updates and access control still matter. The default license is MIT; adjust it for commercial deployment.

⏫︎