CORS Origin Input

Checks a CORS allow-list for origins that never match or open the API to every site, and tests an origin against it.

StopsCORS allow-list never matches

Installation

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

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

Usage

cors-origin-input-usage.tsx
import { CorsOriginInput } from "@/components/ui/cors-origin-input"

<CorsOriginInput
  credentials
  production
  defaultValue={["https://app.acme.com/", "admin.acme.com", "*", "http://localhost:3000", "https://acme.com"]}
/>

What it catches

  • * combined with credentials, and the null origin
  • Trailing slashes or paths, which never match an Origin header
  • Missing scheme and explicit default ports
  • http:// or localhost origins in production
  • Near misses when testing an origin against the list

Props

CorsOriginInput props
PropTypeDefault
value

Allowed origins (controlled).

string[]—
defaultValue

Allowed origins when uncontrolled.

string[][]
onValueChange

Called with the origin list whenever it changes.

(origins: string[]) => void—
credentials

Credentials are allowed for this API. Makes * and *. errors.

booleanfalse
production

This list is for production. Flags http and localhost.

booleanfalse
label

Visible label for the allow-list.

string"Allowed origins"
placeholder

Placeholder for the add-origin field.

string"https://app.example.com"
messages

Text per issue.

Partial<Record<OriginIssueKind, string>>—
useLabel

Fix button labels. `{fix}` is filled in.

string"Use {fix}"
removeLabel

Accessible label prefix for remove buttons.

string"Remove"
fixAllLabel

`{count}` is filled in.

string"Fix {count}"
testLabel

Label for the origin tester.

string"Test an origin"
testPlaceholder

Placeholder for the origin tester.

string"https://www.example.com"
testMessages

Tester results. `{origin}` and `{entry}` are filled in.

Partial<Record<OriginTestCode, string>>—
credentialsOnLabel

Context shown beside the label.

string"credentials: true"
credentialsOffLabel

Text shown when credentials are not allowed.

string"no credentials"
productionLabel

Text marking the production environment.

string"prod"
errorLabel

Read to screen readers after an entry that has an error or a warning.

string"error"
warningLabel

Word read for warning-level issues.

string"warning"

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

Accessibility

  • Labelled add field; origins are a labelled list with remove buttons named per origin
  • aria-invalid and aria-describedby to an aria-live="polite" issues region
  • Severity is stated in text (", error" / ", warning"), not just colour
  • Enter adds an origin; focus moves sensibly after removals and fixes

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: Enforce CORS in the server or gateway with exact origin matching, and authenticate API requests independently of CORS.

  • Checks the list text; your server's CORS middleware may normalise or match differently
  • CORS controls browsers only; it is not access control for the API

What it stops

CORS allow-list never matches

Also known as

cors · allowed origins · access-control-allow-origin · api config · express cors · preflight · credentials

Field type

Dependencies

Pairs well with