# IP allowlist

> A CIDR and firewall allowlist editor with IPv4/IPv6 validation, live subnet host counts, wildcard exposure guards, containment checks and bulk paste.

Cloud databases, webhook endpoints and enterprise dashboards all need IP allowlists, yet raw inputs silently accept malformed addresses, hide how wide a /24 or /16 subnet is and let operators accidentally open 0.0.0.0/0 to the entire internet. IpAllowlist validates IPv4, IPv6 and CIDR notation as you type, displays exact live subnet scope ("1 host", "256 IPs", "/48 subnet"), warns immediately on 0.0.0.0/0 or ::/0 wildcard exposure and private RFC 1918 addresses, detects redundant IPv4 rules covered by a broader CIDR block ("Covered by 203.0.113.0/24"), supports one-click Add my IP and parses multi-line or comma-separated CIDR lists with inline # comments.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/ip-allowlist.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): `text-morph`, `number-roll`, `status-button`
- Docs and live preview: https://hairlineui.com/ui/ip-allowlist
- Registry item (source): https://hairlineui.com/r/ip-allowlist.json

## Usage

```tsx
import { IpAllowlist } from "@/components/ip-allowlist";

<IpAllowlist
  value={rules}
  onChange={setRules}
  currentIp={viewerIp}
/>
```

## Database network settings with strict no-wildcard policy

Pass the viewer IP detected on your server and disable wildcard /0 rules for production clusters.

```tsx
"use client";
import { useState } from "react";
import { IpAllowlist, type IpAllowlistEntry } from "@/components/ip-allowlist";

export function ClusterNetworkPolicy({ initial, viewerIp }: { initial: IpAllowlistEntry[]; viewerIp?: string }) {
  const [rules, setRules] = useState<IpAllowlistEntry[]>(initial);

  return (
    <IpAllowlist
      value={rules}
      onChange={setRules}
      currentIp={viewerIp}
      allowWildcard={false}
      maxEntries={25}
    />
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value / defaultValue / onChange` | `IpAllowlistEntry[] / IpAllowlistEntry[] / (v) => void` | – | Controlled or uncontrolled list of { id, cidr, label?, expiresAt? }. |
| `currentIp` | `string` | – | Optional caller IP address enabling the one-click Add my IP action. |
| `allowWildcard / maxEntries` | `boolean / number` | `true / —` | Allow or block 0.0.0.0/0 and ::/0 rules, and optionally cap total rule count. |
| `parseIpCidr / ipv4CidrContains / parseBulkIpList` | `exported utility functions` | – | Validate CIDRs, test IPv4 subnet containment and parse bulk pasted lists outside the component. |

## States

- **live scope badge**: Typing a valid IP or CIDR updates an inline chip showing IP version and exact host count.
- **wildcard open**: Active 0.0.0.0/0 or ::/0 rules display an amber exposure warning banner across the top of the panel.
- **redundant rule**: An IPv4 host or subnet contained inside a broader existing CIDR displays a sky Covered by badge.
- **bulk paste import**: Pasting multiple lines imports all valid non-duplicate CIDRs, preserves # comment labels and confirms with an emerald Imported pill.

## What it handles

A firewall allowlist editor has to prevent typos, make subnet blast radius obvious before saving and support pasting dozens of CI ranges cleanly.

- **Strict IPv4, IPv6 and CIDR validation**: Normalises bare IPs to /32 or /128, rejects out-of-range octets and prefixes and recoils gently on invalid or duplicate entries.
- **Live subnet host-count readout**: Computes exact IPv4 address counts ("1 host", "256 IPs", "65,536 IPs") and IPv6 prefix scopes right inside the composer as you type.
- **Wildcard /0 exposure guard**: Surfaces an unmistakable amber warning banner whenever 0.0.0.0/0 or ::/0 is active, or blocks wildcard rules completely with allowWildcard={false}.
- **32-bit IPv4 subnet containment checks**: Flags narrower IPv4 rules that are already covered by a broader CIDR block in the list ("Covered by 203.0.113.0/24").
- **One-click Add my IP and bulk paste**: Pass currentIp to add the caller device in one click, or paste newline/comma-separated CIDR lists with # comments to batch import.
- **Exported network helpers**: Exports parseIpCidr(), ipv4CidrContains() and parseBulkIpList() for shared server/client validation.

## Replaces

custom IP regex input, CIDR host calculator, wildcard exposure banner, subnet containment checker

## Where it fits

- **Cloud databases and VPC firewalls**: Let engineers manage IPv4 and IPv6 egress blocks with immediate subnet size readouts and redundant-rule detection.
- **Enterprise API key restrictions**: Pair with API keys and Env editor to lock production credentials to known office VPNs and CI runners.
- **Webhook ingress allowlists**: Paste a provider published multi-line CIDR list with # comments straight into the composer to import all ranges at once.
- **Compliance and zero-trust settings**: Set allowWildcard={false} to block 0.0.0.0/0 and ::/0 rules at the UI boundary before submission.

## Notes

- Bare IPv4 addresses normalise cleanly to /32 and bare IPv6 addresses to /128 so duplicate rules like 1.2.3.4 and 1.2.3.4/32 are caught consistently.
- All IPv4 subnet containment math runs on unsigned 32-bit integers with zero external dependencies.
- Under prefers-reduced-motion: reduce, validation recoil is skipped while error text and focus remain unchanged.

License: MIT (https://hairlineui.com/license#components)
