CIDR Input

Reads a CIDR block back as its exact range and size, and warns before a firewall rule opens to the whole internet or overlaps an existing range.

StopsFirewall opened to 0.0.0.0/0

Installation

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

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

Usage

cidr-input-usage.tsx
import { CidrInput } from "@/components/ui/cidr-input"

<CidrInput label="New subnet" defaultValue="10.0.4.1/8" existing={existing} />

What it catches

  • Host bits set in the address, with the network or /32 (/128) reading as fixes
  • 0.0.0.0/0 or ::/0 (open to everyone)
  • Overlap with, or nesting inside, the existing ranges you pass, named
  • A missing prefix length and ambiguous leading zeros

Props

CidrInput props
PropTypeDefault
label

Visible label.

string"CIDR range"
value

Controlled value.

string—
defaultValue

Initial value when uncontrolled.

string""
onValueChange

Called with the text on every change.

(value: string) => void—
existing

Ranges already in use; an overlap with any of them is flagged by name.

ExistingRange[]NONE
delay

Pause in ms before warnings appear while typing. Leaving the field shows them at once.

number500
rangeText

Templates. `{first}`, `{last}`, `{count}`, `{network}`, `{host}`, `{prefix}`, `{label}`, `{cidr}`, `{all}` are filled in.

string"{first} – {last} · {count} {addresses}"
hostBitsText

Warning when host bits are set.

string"Host bits are set. Did you mean the network, or just thi…
leadingZerosText

Warning for leading zeros in an octet.

string"Leading zeros can be read as octal (010 = 8)."
missingPrefixText

Warning when the /prefix is missing.

string"No prefix, so this is a single address."
anywhereText

Warning for 0.0.0.0/0 or ::/0.

string"This is open to the whole internet: every {all} address."
sameText

Message when the range equals an existing one.

string"Same range as {label} ({cidr})."
insideText

Message when the range sits inside an existing one.

string"Inside {label} ({cidr})."
containsText

Message when the range contains an existing one.

string"Contains {label} ({cidr})."

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

Accessibility

  • Visible <label>; aria-invalid and aria-describedby to an aria-live="polite" hint
  • Serious warnings use role="alert"
  • Fix buttons have aria-labels ("Use …") and return focus to the input
  • The bit diagram is aria-hidden; the range is stated in text

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: Validate rules in your cloud or firewall API and review changes to public ranges there.

  • Only compares against the ranges you pass in `existing`
  • It doesn't know whether a wide range is intended for a public service

What it stops

Firewall opened to 0.0.0.0/0

Also known as

cidr · subnet · ip range · security group · allowlist · firewall · vpc · ipv4

Field type

Dependencies

Pairs well with