envaudit
Lint your environment & secret hygiene before it leaks.
envaudit is a small, zero-dependency CLI that audits a project's .env
files for the mistakes that actually cause credential leaks:
- Is the
.env file actually covered by .gitignore?
- Has it already been committed to git, ignore rule or not?
- Are its file permissions too open (readable by other users)?
- Do its values look like real secrets, or are they placeholders?
It's built to be dropped into a pre-commit hook or CI pipeline and fail
fast, with no config required to get useful output.
Install
go install github.com/sapiuwu/envaudit/cmd/envaudit@latest
Or clone and build locally:
git clone https://github.com/sapiuwu/envaudit
cd envaudit
go build -o envaudit ./cmd/envaudit
Usage
envaudit scan # scan the current directory
envaudit scan ./backend # scan a specific path
envaudit scan --format json # machine-readable output
envaudit scan --no-strict # always exit 0 (report only)
envaudit init # generate .envaudit.yml
Example output
$ envaudit scan
envaudit v0.1.0 — scanning .
[CRITICAL] .env file is tracked by git — run `git rm --cached .env` and rotate any secrets inside it
[HIGH] .env:9 AWS_ACCESS_KEY_ID looks like a real AWS Access Key ID (matches known pattern: AWS Access Key ID)
[HIGH] .env:11 ETH_PRIVATE_KEY looks like a real Ethereum/EVM Private Key (matches known pattern: Ethereum/EVM Private Key)
[MEDIUM] .env file is writable by group members (mode -rw-rw-r--) — recommend chmod 600
Summary: 1 critical, 2 high, 1 medium, 0 low — 1 file(s) scanned
Exit code is non-zero whenever the highest finding meets or exceeds the
configured severity_exit_code (default: high) — so envaudit scan can
be dropped straight into CI or a pre-commit hook:
#!/bin/sh
# .git/hooks/pre-commit
envaudit scan || exit 1
Why not just use gitleaks / trufflehog?
Those tools do deep, whole-repo secret scanning and are great at it.
envaudit is narrower on purpose: it focuses specifically on .env
hygiene — the gitignore/permissions/placeholder-vs-real-secret triage
that happens before a secret ever gets scanned by something bigger. It's
meant to be the fast, zero-config check that catches the most common
mistake (a .env that was never gitignored, or already got committed)
before you reach for a heavier tool.
Configuration
Run envaudit init to generate .envaudit.yml:
rules:
entropy_threshold: 4.0
ignore_patterns:
- "*.env.example"
- "*.env.sample"
- "*.env.template"
custom_secret_patterns:
- name: internal_service_token
regex: "^svc_[a-zA-Z0-9]{32}$"
severity_exit_code: high
| Key |
Description |
Default |
entropy_threshold |
Shannon entropy (bits/char) above which a value is considered random enough to be a real secret |
4.0 |
ignore_patterns |
Filename globs to skip entirely |
*.env.example, *.env.sample, *.env.template |
custom_secret_patterns |
Extra regex rules, checked alongside the built-ins |
none |
severity_exit_code |
Minimum severity (low/medium/high/critical) that causes a non-zero exit |
high |
How value classification works
For each KEY=VALUE pair in a .env file:
- Placeholder check — common stand-ins (
changeme, your_api_key_here,
<insert-key>, empty strings, ${VAR}-style templates) are ignored.
- Known pattern match — the value is checked against built-in regexes
for AWS keys, Stripe keys, GitHub tokens, JWTs, EVM private keys,
database connection strings, and more. A match is high confidence
regardless of entropy.
- Entropy + key-name heuristic — otherwise, the value's Shannon
entropy is measured. High entropy in a key named
*_SECRET, *_TOKEN,
*_PASSWORD, etc. is flagged with a severity that scales with
confidence.
This keeps false positives low — a placeholder like changeme is never
flagged, but a stray real key almost always is.
GitHub Action
envaudit ships as a Docker-based GitHub Action. Add this to
.github/workflows/envaudit.yml in any repo you want scanned:
name: envaudit
on: [push, pull_request]
jobs:
scan:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: sapiuwu/envaudit@v1
with:
path: "." # optional, default "."
strict: "true" # optional, default "true"
config: ".envaudit.yml" # optional
See examples/consumer-workflow.yml.
| Input |
Description |
Default |
path |
Directory to scan |
. |
config |
Path to config file |
.envaudit.yml |
strict |
Fail the step on findings ≥ configured severity |
true |
| Output |
Description |
findings-count |
Total findings across all severities |
highest-severity |
ok, low, medium, high, or critical |
exit-code |
The exit code envaudit produced |
The action also writes a summary to the workflow run's Summary tab.
Testing
go test ./... -v -cover
go vet ./...
gofmt -l .
This repo's own .github/workflows/ci.yml runs the full test suite and
also dogfoods the action against itself on every push and PR.
Roadmap
-
envaudit install-hook — one-command pre-commit hook installer
- Baseline/allowlist file for accepted false positives
- Publish to the GitHub Actions Marketplace
- Homebrew tap
Contributing
Issues and PRs welcome — especially new secret patterns
(internal/rules/patterns.go) for services not yet covered.
License
MIT — see LICENSE.