Commit Secret Guard

Commit Secret Guard is a copy-paste React component that stops api key committed to git 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/commit-secret-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

StopsAPI key committed to git

Was this component page useful?

How do I install Commit Secret Guard?

pnpm dlx shadcn@latest add @bollard/commit-secret-guard

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

How do I use Commit Secret Guard in React?

commit-secret-guard-usage.tsx
import { CommitSecretGuard } from "@/components/ui/commit-secret-guard"

<CommitSecretGuard
  key={String(pushed)}
  diff={DIFF}
  pushed={pushed}
  onResolve={(_, __, fix) => setLog(fix.kind === "replace-line" ? `Patched ${fix.file}:${fix.line}` : fix.kind === "remove-line" ? `Dropped ${fix.file}:${fix.line}` : fix.kind === "command" ? `Ran: ${fix.command}` : "Added to the allowlist.")}
  onCommit={() => new Promise<void>((resolve) => setTimeout(() => (setLog("Committed with no secrets."), resolve()), 700))}
/>

What input mistakes does Commit Secret Guard catch?

  • Provider key formats (AWS, GitHub, Stripe, OpenAI, Slack and others) and private keys
  • Passwords embedded in URLs and hard-coded secrets
  • High-entropy strings that look like tokens
  • .env and key files added to the commit
  • Changes already pushed, with a rotate-now link for the provider

What props does Commit Secret Guard accept?

CommitSecretGuard props
PropTypeDefault
diff* (required)

Unified diff to check (`git diff --cached`, or a PR's .diff). Only added lines are scanned.

string—
pushed

True when these commits are already on a remote (a PR diff, a pre-push hook): every finding then says to rotate.

booleanfalse
fixturePatterns

Globs for test fixtures. Generic and entropy hits there are ignored; live provider keys are still flagged.

string[]DEFAULT_FIXTURE_PATTERNS
value

Controlled resolutions by finding id.

Record<string, SecretResolution>—
defaultValue

Initial resolutions when uncontrolled, e.g. ids your allowlist already holds as "allowed".

Record<string, SecretResolution>{}
onValueChange

Called with all resolutions whenever one changes.

(value: Record<string, SecretResolution>) => void—
onResolve

Called with what to apply when a finding is resolved: a replacement line, a removed line, a git command or an allowlist id.

(finding: SecretFinding, resolution: SecretResolution, fix: SecretFix) => void—
onCommit

Shows the commit button; enabled once every finding is handled. May return a Promise for a pending state.

() => void | Promise<void>—
messages

Any visible string.

Partial<CommitSecretMessages>—

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

How is Commit Secret Guard accessible?

  • Findings are a labelled list that can receive focus
  • Focus moves to the next unresolved finding or the commit button
  • Each finding states its file, line and kind in text
  • Rotate links open in a new tab with rel="noreferrer noopener"

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: Run secret scanning in CI or as a pre-receive hook, and rotate any credential that was pushed.

  • Pattern and entropy based: it can miss custom secret formats and flag random-looking test data
  • Only scans the diff you pass; history and other branches are not checked
  • Marking a false positive is your call; it does not verify the key is inactive

What expensive mistakes does Commit Secret Guard stop?

API key committed to git

Also known as

git · commit · secret scanning · pre-commit · .env · gitleaks · diff · api key

What dependencies does Commit Secret Guard require?

Commit Secret Guard facts & technical specifications

Technical specifications, licensing, and limitations
PropertySpecification
Component nameCommit Secret Guard
Registry identifier@bollard/commit-secret-guard
Install commandnpx shadcn@latest add @bollard/commit-secret-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 Commit Secret Guard

What form validation mistake does Commit Secret Guard catch?

Commit Secret Guard prevents aPI key committed to git. Scans the lines a diff adds for keys, passwords and high-entropy strings, so credentials are noticed before they go into a commit. Catches: Provider key formats (AWS, GitHub, Stripe, OpenAI, Slack and others) and private keys, Passwords embedded in URLs and hard-coded secrets, High-entropy strings that look like tokens, .env and key files added to the commit, Changes already pushed, with a rotate-now link for the provider. Limitation: validate commit-secret-guard schemas on backend.

How do I install commit-secret-guard with shadcn?

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

What props customize Commit Secret Guard?

Commit Secret Guard accepts `diff`, `pushed`, `fixturePatterns`, `value`, `defaultValue`. Configures git, commit, secret scanning behavior. Limitation: invalid prop values fallback to safe default options.

What are the limits of commit-secret-guard?

Pattern and entropy based: it can miss custom secret formats and flag random-looking test data. Only scans the diff you pass; history and other branches are not checked. Marking a false positive is your call; it does not verify the key is inactive Server requirement: Run secret scanning in CI or as a pre-receive hook, and rotate any credential that was pushed.

How does Commit Secret Guard meet accessibility guidelines?

Findings are a labelled list that can receive focus. Focus moves to the next unresolved finding or the commit button. Each finding states its file, line and kind in text. Rotate links open in a new tab with rel="noreferrer noopener". Minimizes errors: committed .env file, aws key pushed to github.

Which components pair with Commit Secret Guard?