A robust Node.js CLI tool that prevents accidental commits of sensitive environment files and credentials by automatically blocking Git commits when dangerous files are staged.
- Comprehensive Protection: Detects
.env*files, SSL certificates, private keys, and other sensitive files - Smart Pattern Matching: Recognizes various sensitive file patterns including:
- Environment files (
.env,.env.local,.env.production, etc.) - SSL certificates (
.pem,.crt,.key) - SSH keys (
id_rsa,id_rsa.pub) - Service account files (
credentials.json,firebase*.json) - And many more security-sensitive patterns
- Environment files (
- Zero Configuration: Works out of the box with sensible defaults
- Clear Visual Warnings: Colorful terminal output with detailed file listings
- Git Integration: Seamlessly integrates with Git pre-commit hooks
- Husky Compatible: Perfect companion for Husky-based workflows
npm install --save-dev staging-checknpm install -g staging-check# Using npx
npx staging-check
# Or using npm
npm exec staging-check-
Install the package:
npm install --save-dev staging-check
-
Test it works:
npx staging-check # Or npm exec staging-check
-
Add to your package.json scripts (optional):
{ "scripts": { "check-env": "staging-check", "precommit": "staging-check" } }
npm install --save-dev husky staging-check
npx husky install
npx husky add .husky/pre-commit "npx staging-check"
chmod +x .husky/pre-commitAdd this to package.json:
{
"scripts": {
"prepare": "husky install"
}
}touch .git/hooks/pre-commit
chmod +x .git/hooks/pre-commitInside .git/hooks/pre-commit:
#!/bin/sh
npx staging-check
# or
# npm exec staging-checkstaging-check
npx staging-check
npm exec staging-checkCI/CD example:
- name: Check for sensitive files
run: |
npx staging-checkIn package.json:
{
"scripts": {
"precommit": "staging-check",
"test": "staging-check && jest",
"build": "staging-check && webpack"
}
}- Scans staged files
- Detects sensitive patterns
- Blocks commits and shows a warning
- Allows commit if safe
| Pattern | Description |
|---|---|
.env* |
Environment files |
*.pem, *.crt |
SSL certificates |
*.key |
Private keys |
id_rsa* |
SSH keys |
*credentials*.json |
Service credentials |
firebase*.json |
Firebase configs |
secrets* |
Secrets |
*.p12 |
PKCS#12 certs |
*.keystore |
Java keystores |
$ git commit -m "Add new feature"
# (no output, commit passes)$ git commit -m "Update config"
⛔ Potential Security Risk: Sensitive files are staged!
- .env
- secrets.json
- ssl/private.key
❗ Please unstage or remove these files before committing.- Ensure you're in a git repo
chmod +xon pre-commit hooks- Check Node.js version ≥ 14
- Still stuck? See Issues
staging-check/
├── index.js
├── package.json
├── README.md
├── LICENSE
├── .env.example
├── .gitignore
└── hooks/
└── pre-commit
git clone https://github.com/Rajeev-Foryou/env-check.git
cd staging-check
npm install
npm link
staging-check
node index.jsMIT — see the LICENSE file.
- Prevents credential leaks
- Protects private keys and API tokens
- Blocks service accounts
- Helps with compliance
- Saves teams from dangerous commits
Made with ❤️ for secure development workflows
Repository: ["https://github.com/Rajeev-Foryou/env-check.git"]