CSP Input

Reads a Content-Security-Policy the way a browser does, so a policy that looks strict but blocks nothing doesn't ship.

StopsCSP that blocks nothing

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/csp-input.json

The files land in your project. They're yours to edit.

Usage

csp-input-usage.tsx
import { CspInput } from "@/components/ui/csp-input"

<CspInput
  defaultValue={"Content-Security-Policy-Report-Only: default-src 'self'; script-src 'self' 'unsafe-inline' data:; style-src self"}
/>

What it catches

  • 'unsafe-inline' without a nonce or hash, and 'unsafe-eval'
  • Wildcards, data: and https: in script-src
  • Missing default-src, object-src or base-uri
  • Unquoted keywords, missing semicolons and commas that split one header into two policies
  • Allowlisted hosts known to serve JSONP or AngularJS, and report-only mistakes

Props

CspInput props
PropTypeDefault
value

Controlled policy text.

string—
defaultValue

Initial policy when uncontrolled.

string""
onValueChange

Called on every change and fix.

(value: string) => void—
mode

How the policy will be sent. "report-only" blocks nothing and must name a report endpoint.

CspMode"enforce"
delivery

Header or <meta> tag. A meta tag ignores frame-ancestors, report-uri and sandbox.

CspDelivery"header"
onFindingsChange

Called with the findings after each check, so a form can block saving on errors.

(findings: CspFinding[]) => void—
delay

Pause in ms before the check runs while typing. Leaving the field or a fix runs it at once.

number500
messages

Override any visible or announced text.

Partial<CspInputMessages>—

* required. Also accepts the native props of <textarea> (className, aria-*, data-*…), passed through to it.

Accessibility

  • Visible <label>; aria-invalid and aria-describedby to an aria-live="polite" status
  • After a fix, focus moves to the next fix or back to the field
  • Severity uses icons and text, not colour alone

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

This is a UX guard rail. Enforce on the server: Send the CSP as a response header from your server and monitor violation reports; the policy is enforced by browsers, not by this field.

  • Reads the policy text; it does not see your pages or test real script loads
  • The JSONP/AngularJS host list is a snapshot and may be incomplete
  • A clean result doesn't mean the site is free of XSS

What it stops

CSP that blocks nothing

Also known as

csp · content-security-policy · security headers · script-src · nonce · helmet · next.config headers · xss

Field type

Dependencies

Pairs well with