Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# leakguard hooks for the pre-commit framework (https://pre-commit.com).
# Consumers add this to their .pre-commit-config.yaml:
#
# repos:
# - repo: https://github.com/sakebomb/leakguard
# rev: v1.1.0
# hooks:
# - id: leakguard
# - id: leakguard-commit-msg # optional: also scan commit messages
#
# language: script runs leakguard.py directly (stdlib only, no install step). The gate
# scans the staged diff itself, so filenames are not passed to it.
- id: leakguard
name: leakguard (identity + secret leak gate)
description: Block LAN identity, internal topology, secrets, and sensitive files from entering git history.
entry: leakguard.py hook
language: script
pass_filenames: false
stages: [pre-commit]
- id: leakguard-commit-msg
name: leakguard commit-message scan
description: Block secrets or machine identity pasted into the commit message body.
entry: leakguard.py commit-msg
language: script
stages: [commit-msg]
64 changes: 55 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ are all recoverable from data that can never be edited out.

## Install

`leakguard` is two dependency-free files (`leakguard.py` + `map_render.py`). Clone or copy them,
then put it on your PATH:
`leakguard` is three dependency-free files (`leakguard.py` + `detectors.py` + `map_render.py`).
Clone or copy them, then put it on your PATH:

```sh
git clone https://github.com/sakebomb/leakguard
Expand All @@ -27,13 +27,29 @@ alias leakguard='python3 /path/to/leakguard/leakguard.py'

Requires only Python 3 and git.

## What it detects

`hook`/`ci` **block** a commit on: machine identity (LAN commit identity, mDNS `.local`/`.lan`/
`.internal` hosts, Tailscale tailnet names), internal topology (private IPs, home paths), **30+
provider secrets** (AWS, GitHub/GitLab PATs, Stripe, npm/PyPI, OpenAI/Anthropic, Slack, SendGrid,
Google, DigitalOcean, PEM private keys), embedded credentials in `scheme://…:pass@host` URLs, and
sensitive files (`id_rsa`, `*.pfx`/`*.p12`/`*.jks`, `.npmrc`, `.aws/credentials`, `kubeconfig`,
`.env` — sample files allowed). It also enforces a large-file tripwire and scans commit messages.

High-precision by design: a keyword pre-filter, an allowlist layer, and a placeholder-value
denylist keep false positives low, and findings are **masked** — the raw secret is never printed.
Noisier signals (entropy, generic `key=value`, JWTs, ambiguous filenames like `*.pem`) surface as
`audit` **warnings**, not blocking checks. Suppress one line inline with a `leakguard:allow` comment.

## Defense

```sh
leakguard audit # what does THIS repo's config + history leak?
leakguard harden # set safe git config + print agent-attribution guidance
leakguard hook # pre-commit gate (blocks LAN identity + internal leaks in staged diff)
leakguard ci --base main # CI gate (used by the GitHub Action)
leakguard audit # what does THIS repo leak? secrets, identity, + .gitignore gaps
leakguard harden # set safe git config + install the hooks
leakguard hook # pre-commit gate (blocks identity + secrets in the staged diff)
leakguard commit-msg FILE # commit-msg gate (blocks secrets pasted into the message)
leakguard ci --base main # CI gate (used by the GitHub Action)
leakguard baseline # accept a repo's existing leaks; then block only NEW ones
```

Install the pre-commit hook globally so it runs in every repo:
Expand All @@ -47,6 +63,34 @@ git config --global core.hooksPath ~/.git-hooks

Bypass a false positive once: `LEAKGUARD_ALLOW=1 git commit ...`

### Install via the pre-commit framework

If you use [pre-commit](https://pre-commit.com), add to `.pre-commit-config.yaml`:

```yaml
repos:
- repo: https://github.com/sakebomb/leakguard
rev: v1.1.0
hooks:
- id: leakguard # scans the staged diff
- id: leakguard-commit-msg # optional: scans the commit message
```

Then `pre-commit install --hook-type pre-commit --hook-type commit-msg`. No install step (stdlib only).

### Adopt on a repo that already leaks

For a legacy repo that already contains leaks, `baseline` records the current **committed** findings
(HEAD only, as hashes — the file never stores a raw secret) into `.leakguard-baseline.json`; commit
it, and the gate then suppresses those known findings and blocks only **new** ones.
`leakguard baseline --report` lists what was accepted, **secrets-to-rotate first** — baselining
silences the alert, it does not make a committed secret safe.

The large-file tripwire defaults to 500 KB (`LEAKGUARD_MAX_KB` to tune). Known limitations, by
design: git-LFS pointer files hide the real object size; `10.244.0.0/16` and `10.96.0.0/12` are
treated as benign k8s defaults; and `commit-msg` fails open on an unreadable message file (a
transient FS error must not block every commit), while `hook`/`ci` fail closed.

### GitHub Action

Block leaky commits on every PR. Copy `.github/workflows/example.yml` into your repo as
Expand Down Expand Up @@ -98,9 +142,11 @@ Archive dataset on BigQuery.

## Scope

Detection is deterministic (regex), the defense path makes no network calls, and there are no
dependencies. It is a guardrail, not a guarantee: it catches the common shapes, not every possible
leak. Review diffs before pushing to public repos.
Detection is deterministic (regex + filename globs), the defense path makes no network calls, and
there are no dependencies beyond python3 + git. Secret rules are ported near-verbatim from gitleaks;
the tool never verifies a credential against its provider (that would need network — out of scope by
design). It is a guardrail, not a guarantee: it catches the common shapes, not every possible leak.
Review diffs before pushing to public repos.

## License

Expand Down
Loading
Loading