# CSP builder

> Build a Content-Security-Policy and a Next.js headers snippet.

Free Content-Security-Policy generator. Fill in directives or paste a policy, then copy the header and a next.config headers() snippet. Warnings call out wildcards, unsafe-inline, and a missing object-src or frame-ancestors.

- Page: https://benchline.fabwaseem.com/t/csp-generator
- Runs: in the browser. Input stays on the device.
- Price: free, no account
- Input: CSP directive values, or a policy to parse.
- Output: A policy, a header line, a Next.js headers snippet, and warnings.
- Keywords: csp generator, content security policy generator
- Updated: 2026-10-18
- Built by: Waseem Anjum (https://fabwaseem.com)

## How to use it

1. **Start from a preset or paste a policy.** Strict blocks by default. The Next.js preset allows what a typical app needs, and the notes say what is loose.
2. **Edit directives.** Each field is one directive. Leave a field blank to omit it.
3. **Copy the snippet.** The header line and the next.config snippet stay in sync with the fields.

## Use it from an AI agent

MCP tool name: `build_csp`
MCP endpoint: https://benchline.fabwaseem.com/mcp (Streamable HTTP, no key)
HTTP: POST https://benchline.fabwaseem.com/api/v1/tools/csp-generator with the input as the JSON body
This call does not fetch anything. It runs on the arguments you send.

Build a Content-Security-Policy from directives, or lint an existing policy. Returns the header line, a Next.js headers() snippet, and warnings for unsafe sources.

### Input schema

```json
{
  "type": "object",
  "properties": {
    "policy": {
      "description": "An existing Content-Security-Policy value to lint. When set, directive fields are ignored.",
      "type": "string"
    },
    "sources": {
      "type": "object",
      "propertyNames": {
        "type": "string",
        "enum": [
          "default-src",
          "script-src",
          "style-src",
          "img-src",
          "font-src",
          "connect-src",
          "frame-src",
          "frame-ancestors",
          "media-src",
          "object-src",
          "base-uri",
          "form-action",
          "worker-src",
          "manifest-src"
        ]
      },
      "additionalProperties": {
        "type": "string"
      },
      "required": [
        "default-src",
        "script-src",
        "style-src",
        "img-src",
        "font-src",
        "connect-src",
        "frame-src",
        "frame-ancestors",
        "media-src",
        "object-src",
        "base-uri",
        "form-action",
        "worker-src",
        "manifest-src"
      ]
    },
    "upgradeInsecureRequests": {
      "default": true,
      "type": "boolean"
    },
    "blockAllMixedContent": {
      "default": false,
      "type": "boolean"
    }
  },
  "required": [
    "upgradeInsecureRequests",
    "blockAllMixedContent"
  ],
  "additionalProperties": false
}
```

### Example tools/call

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "tools/call",
  "params": {
    "name": "build_csp",
    "arguments": {
      "upgradeInsecureRequests": true,
      "blockAllMixedContent": false
    }
  }
}
```

Setup for Claude, Cursor, and VS Code: https://benchline.fabwaseem.com/mcp/guide

## Questions

### Does this publish the header?

No. It writes the header line and a Next.js config snippet. You add that snippet to the app that serves the page.

### Why warn on unsafe-inline?

It allows inline scripts or styles, which is how many XSS bugs run. A nonce or a hash is tighter for scripts.

### What does object-src 'none' do?

It blocks plugin embeds such as Flash and generic object tags. Most sites can set it and notice nothing.

## Related tools

- [HTTP headers](https://benchline.fabwaseem.com/t/http-headers-checker): Follow redirects and grade the security headers on a public URL.
- [Next.js Dockerfile generator](https://benchline.fabwaseem.com/t/nextjs-dockerfile-generator): Generate a production multi-stage Dockerfile for Next.js, plus .dockerignore and compose.
- [Meta tags inspector](https://benchline.fabwaseem.com/t/meta-tags-inspector): Read title, description, canonical, robots, Open Graph, Twitter, and JSON-LD types from one public URL.
- [robots.txt checker](https://benchline.fabwaseem.com/t/robots-txt-checker): Read allow and disallow rules, sitemap links, and the mistakes that make a robots.txt file lie.
