Small tools. Better flow.

CSP builder

Build a Content-Security-Policy from allowed sources.

Usage guide

Your input stays in this browser.

Input & options

Text 1 MB

View code examples ↓

Result

Your result will appear here.

Code examples

Starting points for your own code. Run them in the environment shown below.

Node.js 22+ · ES module (.mjs)

Current inputs apply only to fields used by the example. Selected files are not embedded.

const directives = {
  "default-src": ["'self'"],
  "script-src": ["'self'", "https://cdn.example.com"],
  "object-src": ["'none'"],
  "base-uri": ["'self'"],
  "frame-ancestors": ["'none'"],
};
const policy = Object.entries(directives)
  .map(([name, values]) => name + " " + values.join(" "))
  .join("; ");
console.log("Content-Security-Policy: " + policy);

Put it to work

Build a Content-Security-Policy from allowed sources.

Details that matter

Format and meaning

Enter space-separated sources. Test with Report-Only on your actual page first.

Supported scope and limits

Text 1 MB

Split inputs that exceed the limit. If a format or algorithm is unsupported, choose a tool that matches your requirements instead of silently changing the format.