CSP Input

CSP Input is a copy-paste React component that stops csp that blocks nothing before the user submits. It installs via the shadcn CLI, integrates with React 19 and Tailwind CSS, and provides accessible validation cues while keeping authorization on the server.

pnpm dlx shadcn@latest add @bollard/csp-input
Version 0.1.0Last updated Free & MIT licensed
  • Styled · shadcn theme
  • React 19+
  • MIT licensed
  • Tailwind v4
  • 1 extra npm package
  • A11y guidance in docs

StopsCSP that blocks nothing

Was this component page useful?

How do I install CSP Input?

pnpm dlx shadcn@latest add @bollard/csp-input

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

How do I use CSP Input in React?

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 input mistakes does CSP Input catch?

  • '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

What props does CSP Input accept?

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.

How is CSP Input accessible?

  • 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.

What are the limitations and server boundaries?

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 expensive mistakes does CSP Input stop?

CSP that blocks nothing

Also known as

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

Field type

What dependencies does CSP Input require?

CSP Input facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component nameCSP Input
Registry identifier@bollard/csp-input
Install commandnpx shadcn@latest add @bollard/csp-input
LicenseMIT License (free, commercial-friendly)
Price$0 (100% Free and Open Source)
Version0.1.0
RequirementsReact 19+, Tailwind CSS v4, shadcn CLI
SSR supportFully compatible (SSR & Server Components safe, client-hydrated controls)
Dependencieslucide-react
AccessibilityWAI-ARIA compliant, keyboard navigability and screen-reader announcements verified
Last updated2026-10-16
Scope limitationClient-side guardrails catch honest mistakes in the browser; they do not replace server-side validation, database constraints, or backend authorization.

Frequently asked questions about CSP Input

What form validation mistake does CSP Input catch?

CSP Input prevents cSP that blocks nothing. Reads a Content-Security-Policy the way a browser does, so a policy that looks strict but blocks nothing doesn't ship. 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. Limitation: validate csp-input schemas on backend.

How do I install csp-input with shadcn?

Run `npx shadcn@latest add @bollard/csp-input`. Sources added: registry/default/csp-input/csp-check.ts, registry/default/csp-input/csp-input.tsx. Package requirements: lucide-react.

What props customize CSP Input?

CSP Input accepts `value`, `defaultValue`, `onValueChange`, `mode`, `delivery`. Configures csp, content-security-policy, security headers behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of csp-input?

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 Server requirement: Send the CSP as a response header from your server and monitor violation reports; the policy is enforced by browsers, not by this field.

How does CSP Input meet accessibility guidelines?

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. Minimizes errors: content security policy unsafe-inline, csp not working.

Which components pair with CSP Input?