Secret Paste Guard

Spots API keys, tokens and private keys as they're pasted or typed into a field and offers one-tap Redact before they're sent.

StopsHelps catch an API key pasted into a chat

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/secret-paste-guard.json

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

Usage

secret-paste-guard-usage.tsx
import { SecretPasteGuard, type SecretMatch } from "@/components/ui/secret-paste-guard"

<SecretPasteGuard value={message} onValueChange={setMessage} onDetect={setOpen}>
  <textarea
    aria-label="Message to support"
    rows={4}
    value={message}
    onChange={(event) => {
      setMessage(event.target.value)
      setSent(false)
    }}
    className="block w-full resize-none rounded-md border bg-transparent px-3 py-2 font-mono text-sm shadow-xs outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 dark:bg-input/30"
  />
</SecretPasteGuard>

What it catches

  • Known formats: private key blocks, AWS access keys, GitHub tokens, Stripe live/restricted keys, Slack, OpenAI, Anthropic and Google API keys, JWTs
  • Long mixed-case-and-digit strings with high Shannon entropy (marked as a guess)
  • Typed and pasted text alike
  • URL paths are not mistaken for secrets, but tokens in query strings can be

Props

SecretPasteGuard props
PropTypeDefault
value* (required)

The field's value. The guard scans it whether it was typed or pasted.

string—
onValueChange* (required)

Called with the redacted text when the user chooses Redact.

(value: string) => void—
children* (required)

Your input, textarea or chat box, controlled by the same value.

React.ReactNode—
onDetect

Notified whenever the set of unresolved secrets changes, e.g. to hold a Send button.

(matches: SecretMatch[]) => void—
redactLabel

Label of the button that replaces every secret with its last 4 characters.

string"Redact"
keepLabel

Label of the button that dismisses the warning for these values.

string"Keep"

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

Accessibility

  • Warning renders in a polite live region
  • Redact and Keep are labelled buttons
  • After either choice, focus returns to the wrapped field

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: Scan again server-side before storing or forwarding text, and redact secrets from logs, analytics and error reports.

  • Pattern and entropy based: new or unusual formats are missed, and random IDs can be flagged
  • Scans in the browser only; it does not stop a submit, so a user can Keep and send
  • onDetect receives the matched text, so never log or send those matches as-is

What it stops

Helps catch an API key pasted into a chat

Also known as

api key · token · jwt · secret · redact · support chat · paste · credentials

Field type

Dependencies

Pairs well with