Sensitive Data Guard — catching secrets and customer data before they leak
Most data leaks don’t happen because someone decided to leak a secret. They happen in boring moments — a token pasted into a config, a private IP left in a blog draft, a customer name buried in a doc, or a commit made with --no-verify before anyone notices. Once it’s in git history or shared in a chat, cleanup gets a lot more expensive than prevention.
That’s the problem sensitive-data-guard is built to solve.
It’s a local guardrail for catching customer-specific sensitive information before it leaves your machine — into a git commit, a doc, an exported repo, or an AI chat tool. It combines machine-wide git hooks, a standalone scanner, and an agent skill so the same detection logic shows up in different workflows.
License note:
sensitive-data-guardis proprietary and licensed, not sold. It can be cloned, installed, and used for personal or internal non-commercial purposes, but reproduction, distribution, sale, sublicensing, derivative works, and commercial use require the licensor’s prior written consent. Check the repo’s LICENSE for the exact terms.
The core idea
The tool is built around a simple observation: regex-based hooks are good at catching mechanical patterns like tokens and keys, but bad at catching semantic leaks like a customer name in prose. On the other hand, an AI skill can reason about context, but you don’t want to rely on a human remembering to invoke it every time.
sensitive-data-guard covers both sides:
- Mechanical detection — git hooks and
sdg-scancatch known patterns fast and consistently. - Semantic review — the agent skill handles the fuzzy cases where you actually need to read the content.
Nothing calls home or uploads anything. The hooks and scanner run locally, and the skill runs inside your own agent session.
What gets installed
Running ./install.sh sets up four main pieces:
1. Machine-wide git hooks
The hooks are installed into core.hooksPath, so they apply to every repo on the machine — not just the one you installed from.
| Hook | Scope | On a finding |
|---|---|---|
pre-commit |
staged diff | blocks the commit; offers to redact in place |
prepare-commit-msg |
commit message | aborts the commit; offers to redact the message |
post-commit |
commit just created | warns loudly (can’t un-commit) and suggests git reset |
pre-push |
commits about to be pushed, plus target remote | blocks the push |
This covers gaps a plain staged-diff hook misses: secrets committed before the guard was installed, commits made with --no-verify, secrets pasted into commit messages, and clean-looking branches being pushed to the wrong remote for the first time.
2. sdg-scan
sdg-scan is the same detection engine exposed as a standalone command. It’s useful for scopes git hooks can’t see: an entire repo history, a folder being exported/zipped, or CI.
3. Agent skill
The sensitive-data-guard skill is installed to a canonical ~/.agent/skills/sensitive-data-guard path and symlinked into supported tools where needed. It can be used for on-demand scans, check-before-commit reviews, and repo/folder anonymization workflows.
4. Cursor rule
The repo also includes a Cursor rule (cursor-rule/sensitive-data-guard.mdc) so the behavior can stay in context automatically. You can install it globally through Cursor settings or per-project via ./install.sh --cursor-rule <path-to-repo>.
What it detects
The mechanical scanner covers a lot of common leak patterns.
Secrets and credentials
- Private key material (
BEGIN ... PRIVATE KEY ... END) - AWS access keys and secret access keys
- JWTs (including Azure AD access tokens)
- GitHub, GitLab, Slack, Stripe, SendGrid, Google API, GCP OAuth, npm, and PyPI tokens
- Azure storage account keys and SAS signatures
- JFrog API keys and access tokens
- Kubernetes EKS bearer tokens and kubeconfig key/cert blobs
- Generic credential assignments like
api_key = "...",password: ..., and similar patterns - Connection strings with inline credentials (
postgres://user:pw@host,redis://:pw@host, etc.)
It also tries to be smart about false positives — for example, leaving HCL/Terraform references and ARM listKeys(...) expressions alone instead of flagging code that merely references secrets.
Credential-bearing filenames
Some files are dangerous because of what they are, even if the diff has no obvious added secret line. The guard flags names like id_rsa, *.pem, *.key, *.p12, .env*, .netrc, .npmrc, .kube/config, .docker/config.json, kubeconfig, secrets.*, and similar paths.
Infra details and identity leaks
- Public and private IPv4 addresses (with sensible exclusions like loopback,
0.0.0.0, link-local, and RFC 5737 documentation ranges) - Non-allowlisted email addresses
- AWS account IDs inside ARNs
- Customer names from your local denylist
Things regex can’t fully solve
A customer company name in prose has no fixed pattern. Internal hostnames or tenant names can also be context-dependent. That’s where the skill’s semantic read matters — it actually looks at content instead of only grepping for shapes.
How the hooks behave in practice
The hook flow is designed to be useful without being noisy in the wrong way.
When findings are detected, the report is grouped by file and line, with a category and a masked preview. It never prints the raw secret value back out, because dumping the secret into terminal output or chat logs would be its own leak.
A typical report looks like this:
sensitive-data-guard: 2 finding(s) across 1 file(s) require attention.
src/config.py
:1 credential-assignment key="DB_PASSWORD" s3cr****
:4 email key="EMAIL" ops@****
sensitive-data-guard: files that must be fixed (1):
src/config.py [credential-assignment,email] 2 finding(s) at line 1, line 4
For pre-commit and prepare-commit-msg, the hook can offer to redact values in place and re-stage the file, or let you fix it manually. In non-interactive environments (CI, some GUI clients), it defaults to manual behavior.
post-commit is especially useful because --no-verify skips pre-commit and commit-msg, but not post-commit. It can’t undo the commit, but it can warn you immediately and tell you how to recover.
pre-push scans the commits bound for the remote and also checks where you’re pushing. That catches two nasty cases: secrets already committed in history, and pushing to an unexpected remote.
Redaction behavior
One nice design choice is that redaction uses predictable placeholders. That means a follow-up scan comes back clean instead of re-flagging its own output.
Examples include:
| Category | Placeholder |
|---|---|
| Private key block | <REDACTED_PRIVATE_KEY_MATERIAL> |
| AWS access key | <REDACTED_AWS_ACCESS_KEY> |
| JWT | <REDACTED_JWT> |
| GitHub token | <REDACTED_GITHUB_TOKEN> |
| Slack webhook | <REDACTED_SLACK_WEBHOOK> |
| Azure storage key | <REDACTED_AZURE_STORAGE_KEY> |
| Connection string password | <REDACTED_URL_CREDENTIAL> |
| Public IPv4 | 203.0.113.10 |
| Private IPv4 | 10.0.0.1 |
| Non-allowlisted email | user@example.com |
| Denylisted customer name | <REDACTED_CUSTOMER_NAME> |
For generic credential assignments, it keeps the key name and replaces only the value with REDACTED. For connection strings, it keeps the scheme/user/host so the line still makes sense.
Some findings can’t be safely “rewritten” in place. A credential-bearing file like .env or id_rsa has no useful text redaction path — the fix is to remove it and gitignore it, or move it to a proper secret store. Ansible Vault headers are also reported but not auto-redacted, because replacing ciphertext with a placeholder would leave you with garbage.
Scanning beyond the staged diff with sdg-scan
Hooks are great for the commit/push flow, but they don’t answer questions like “is this repo clean anywhere in its history?” or “is this folder safe to zip and share?”
That’s where sdg-scan comes in.
sdg-scan # every blob ever committed to this repo
sdg-scan --reflog # include objects only reachable from reflog
sdg-scan --history # patch-based: which commit introduced each finding
sdg-scan --range v1.0..HEAD # scan an explicit range
sdg-scan --path ~/my-export # scan a folder being exported/published
sdg-scan --staged # scan staged diff, report only
sdg-scan --ci # non-interactive, exits 1, GitHub Actions annotations
A few details I like here:
- The default scan looks at unique blobs, not every patch in history. That makes it scale better and also means it can catch secrets in files that were deleted long ago.
--reflogmatters because a secret that’s been reset away may still be recoverable from the object store until GC.--pathworks on arbitrary folders, not just git repos. Inside a repo it respects.gitignore; outside it falls back to a directory walk and skips common build/dependency dirs.--cimakes it usable as an enforcement layer in pipelines.
The scanner never edits anything. If something is already committed, rewriting the working tree doesn’t fix history. The right order is: rotate the credential first, then decide whether history needs to be rewritten.
The skill and semantic review
The mechanical scanner is only half the story. The skill is where the semantic review happens.
It’s useful when you want to ask things like:
- “Is this safe to commit?”
- “Check this doc before I share it”
- “Scan this repo and anonymize it before exporting”
- “Does this contain customer info?”
The skill has two modes:
- Check mode — report findings, redact mechanical categories, and confirm before changing semantic hits like customer names in prose.
- Repo/folder anonymize mode — scan the whole tree and anonymize both mechanical and semantic findings in place, using a consistent mapping per entity, then report a summary.
That distinction is important. In a normal pre-commit check, you probably want confirmation before renaming a customer in prose. In an explicit “anonymize this repo before export” flow, the request itself is the confirmation.
The skill also knows to look for credential-bearing filenames, not just secret-looking content. That’s a subtle but important catch — a diff that adds id_rsa or .env may not contain an obvious “secret string” line at all.
Suppressing false positives
No guard is useful if people turn it off the first time it gets noisy. sensitive-data-guard gives a few escape hatches, in order of preference:
- Inline ignore — add
# sdg:ignoreor# sdg:ignore github-tokenon a specific line. - Path ignore — put globs in
.sdgignoreat the repo root or in~/.claude/sensitive-data-guard-ignore. --no-verify— the blunt instrument. It bypasses hooks for that commit/push, butpost-commitwill still call out what happened.
The first two are much better because they’re narrow and auditable.
Customization knobs
The hooks are configurable through environment variables, which makes it easy to tune behavior without editing installed files.
A few useful ones:
| Variable | Default | Effect |
|---|---|---|
SDG_CUSTOMER_LIST_FILE |
~/.claude/sensitive-data-guard-customers.txt |
Customer/company denylist |
SDG_IGNORE_FILE |
~/.claude/sensitive-data-guard-ignore |
Machine-wide path ignores |
SDG_ENTROPY |
off | Enable high-entropy string detection |
SDG_ALLOWED_PUSH_REMOTES |
origin |
Remotes that don’t prompt |
SDG_PUSH_SCAN |
new |
all scans every reachable commit, none skips content scanning |
SDG_MAX_PUSH_COMMITS |
2000 |
Per-push scan cap |
SDG_POST_COMMIT |
1 |
Disable post-commit hook when set to 0 |
SDG_CHECK_MESSAGE |
1 |
Disable commit-message hook when set to 0 |
There are also knobs for parallel scan behavior, redaction size limits, and hook install location. If you change detection rules, you need to keep detection and redaction symmetrical — otherwise the tool will re-flag its own placeholders.
Where it fits
I like this kind of tool because it sits in the right place: close to the developer workflow, local by default, and strict where it needs to be.
The hook layer catches the obvious mistakes early. sdg-scan covers history, exports, and CI. The skill handles the gray areas where a regex can’t understand what “customer-specific” actually means. Together, they make “check before you share” a lot less dependent on memory.
If you’ve ever had to clean up a leaked token, scrub git history, or manually anonymize a repo before handing it off, you’ll immediately see the value here.
If you want to dig deeper, the repo is here: sensitive-data-guard. Just make sure to review the license terms before using it beyond personal/internal non-commercial scenarios.
Enjoy!