Public Env Guard

Public Env Guard is a copy-paste React component that stops helps catch a secret key shipped in the client bundle 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/public-env-guard
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

StopsHelps catch a secret key shipped in the client bundle

Was this component page useful?

How do I install Public Env Guard?

pnpm dlx shadcn@latest add @bollard/public-env-guard

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

How do I use Public Env Guard in React?

public-env-guard-usage.tsx
import { PublicEnvGuard } from "@/components/ui/public-env-guard"

return <PublicEnvGuard framework="next" defaultValue={env} />

What input mistakes does Public Env Guard catch?

  • Public-prefixed variables that reach the browser, per framework
  • Secret key shapes (for example Stripe secret keys) in public variables
  • Supabase service_role JWTs
  • Passwords inside connection URLs
  • Secret-sounding names and high-entropy values, while letting publishable keys through

What props does Public Env Guard accept?

PublicEnvGuard props
PropTypeDefault
value

Controlled .env text.

string—
defaultValue

Initial text when uncontrolled.

string""
onValueChange

Called with the new text on every edit or fix.

(value: string) => void—
framework

Which bundler reads this file. Decides which prefixes are public; "auto" treats every known prefix as public.

EnvFramework"auto"
publicKeys

Keys you've confirmed are meant to be public, so they're never flagged.

string[][]
onMarkPublic

Called when the user marks a flagged key as public.

(key: string) => void—
onMoveToServer

Called after a key is moved off the client, so you can open a rotation task.

(from: string, to: string | null) => void—
label

Visible label; shorthand for `messages.label`.

string—
messages

Every visible string. `{key}`, `{fix}`, `{prefix}`, `{shape}`, `{framework}`, `{count}` are filled in.

Partial<PublicEnvGuardMessages>—

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

How is Public Env Guard accessible?

  • Visible label; textarea has aria-invalid when errors exist and is described by the status
  • Status uses role=status; icons are aria-hidden
  • Focus returns to a nearby control after a fix

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: Scan built bundles in CI for secrets and keep secret keys only in server-side environment variables.

  • Reads the .env text you paste; secrets set elsewhere (CI, hosting dashboard) aren't seen
  • High-entropy detection can flag harmless IDs
  • Renaming doesn't un-leak a key already shipped; rotate it

What expensive mistakes does Public Env Guard stop?

Helps catch a secret key shipped in the client bundle

Also known as

next_public · vite_ · react_app_ · .env · env vars · supabase service_role · api key · client bundle

What dependencies does Public Env Guard require?

Public Env Guard facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component namePublic Env Guard
Registry identifier@bollard/public-env-guard
Install commandnpx shadcn@latest add @bollard/public-env-guard
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 Public Env Guard

What form validation mistake does Public Env Guard catch?

Public Env Guard prevents helps catch a secret key shipped in the client bundle. Reads a .env the way the bundler does and flags secrets in public variables, so a secret key isn't shipped in the client bundle. Catches: Public-prefixed variables that reach the browser, per framework, Secret key shapes (for example Stripe secret keys) in public variables, Supabase service_role JWTs, Passwords inside connection URLs, Secret-sounding names and high-entropy values, while letting publishable keys through. Limitation: validate public-env-guard schemas on backend.

How do I install public-env-guard with shadcn?

Run `npx shadcn@latest add @bollard/public-env-guard`. Sources added: registry/default/public-env-guard/public-env-guard.tsx, registry/default/public-env-guard/scan-public-env.ts. Package requirements: lucide-react.

What props customize Public Env Guard?

Public Env Guard accepts `value`, `defaultValue`, `onValueChange`, `framework`, `publicKeys`. Configures next_public, vite_, react_app_ behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of public-env-guard?

Reads the .env text you paste; secrets set elsewhere (CI, hosting dashboard) aren't seen. High-entropy detection can flag harmless IDs. Renaming doesn't un-leak a key already shipped; rotate it Server requirement: Scan built bundles in CI for secrets and keep secret keys only in server-side environment variables.

How does Public Env Guard meet accessibility guidelines?

Visible label; textarea has aria-invalid when errors exist and is described by the status. Status uses role=status; icons are aria-hidden. Focus returns to a nearby control after a fix. Minimizes errors: next_public secret exposed, api key in frontend.

Which components pair with Public Env Guard?