Advanced secret detection for Git repositories
Project description
๐ git-shield
git-shield is a lightweight, secure command-line tool that detects hard-coded secrets, passwords, API keys, and random-looking sensitive data in your Git staged files before you commit.
๐ Prevent accidental leaks ๐ Generate user-friendly reports ๐ช Automate via Git pre-commit hooks ๐ Combines Regex + Shannon Entropy detection for maximum protection ๐ Smart file type detection for comprehensive scanning
โจ Features
-
๐ Smart File Detection: Automatically detects and scans text files including:
- Code files (
.py,.js,.ts,.java,.cpp, etc.) - Configuration files (
.env,.config,.yml,.json, etc.) - Documentation (
.md,.txt,.rst, etc.) - Certificate files (
.pem,.key,.crt, etc.) - And many more supported formats
- Code files (
-
๐ก Comprehensive Secret Detection:
- AWS Access Keys & Secret Keys
- Private/Public Keys (RSA, DSA, EC, SSH)
- API Keys (GitHub, Google, Stripe, Twilio, etc.)
- Database URLs (PostgreSQL, MongoDB, Redis, MySQL)
- OAuth tokens and client secrets
- JWT tokens
- Slack tokens and webhooks
- Environment variables
- Hardcoded credentials in code
- Secrets in comments
-
๐ง Git Hook Management:
- Easy installation/uninstallation of pre-commit hooks
- Automatic scanning before every commit
- Blocks commits when secrets are detected
-
๐ Detailed Reports: File, line number, pattern type, and code context
-
โก Fast and Lightweight: Minimal dependencies, runs locally
-
๐ Security Focused: 100% local operation, no network calls
๐ฆ Installation
Ensure you have Python 3.8+ installed.
# Install via PyPI
pip install git-shield
Alternatively:
git clone https://github.com/yourusername/git-shield.git
cd git-shield
pip install .
โก Quick Start
Basic Usage
Scan staged files in your Git repository:
git-shield scan --staged
Scan specific files:
git-shield scan --files config.env database.yml
Git Hook Setup
Install git-shield as a pre-commit hook (recommended):
git-shield install
This will automatically scan for secrets before every commit and block commits if secrets are found.
Check hook status:
git-shield status
Uninstall the hook if needed:
git-shield uninstall
๐ Command Reference
git-shield scan
Scan files for secrets.
Options:
--staged: Scan all staged files in the current git repository--files: Scan specific files (can specify multiple files)
Examples:
# Scan staged files
git-shield scan --staged
# Scan specific files
git-shield scan --files .env config.py
# Scan multiple specific files
git-shield scan --files file1.txt file2.py file3.yml
git-shield install
Install git-shield as a pre-commit hook.
Example:
git-shield install
git-shield uninstall
Uninstall git-shield pre-commit hook.
Example:
git-shield uninstall
git-shield status
Check the installation status of git-shield hooks.
Example:
git-shield status
๐ Output Examples
โ No Secrets Detected
๐ Scanning 3 file(s) for secrets...
โ
No secrets detected. Safe to commit.
โ Secrets Detected
๐ Scanning 2 file(s) for secrets...
โ Secrets detected:
๐ config.env:5 [Password] -> pass****
Code: password=EXAMPLE_PASSWORD
๐ api.py:12 [API Key] -> AKIA****
Code: aws_access_key = "AKIAEXAMPLEKEY123"
๐ซ Found 2 secret(s). Please remove them before committing.
๐ Supported File Types
git-shield automatically detects and scans text files including:
Code Files:
.py,.js,.ts,.jsx,.tsx,.html,.css,.scss,.sass.java,.cpp,.c,.h,.hpp,.cs,.go,.rs,.swift.kt,.scala,.clj,.hs,.ml,.fs,.vb,.pl,.pm.tcl,.lua,.vim,.tex,.rst,.adoc,.wiki
Configuration Files:
.env,.config,.conf,.ini,.cfg,.properties.json,.xml,.yaml,.yml,.toml
Documentation:
.md,.txt,.log,.csv,.tsv,.tab,.dat,.asc
Certificate Files:
.pem,.key,.crt,.cer,.der,.p12,.pfx.p7b,.p7c,.crl,.csr
Scripts:
.sh,.bash,.zsh,.fish,.ps1,.bat,.cmd
๐ก Detection Patterns
git-shield includes comprehensive patterns for detecting:
- AWS: Access keys, secret keys, session tokens
- GitHub: Personal access tokens, OAuth tokens, app tokens
- Database: PostgreSQL, MongoDB, Redis, MySQL connection strings
- OAuth: Client IDs, client secrets, access tokens
- Slack: Tokens, webhooks
- Stripe: Live/test keys, publishable keys
- Google: API keys, OAuth credentials
- Social Media: Facebook, Twitter tokens
- Communication: Twilio, SendGrid, Mailgun API keys
- Generic: Base64/hex encoded secrets, UUIDs, hardcoded credentials
๐ Security Focus
- 100% Local: No network calls, runs entirely on your machine
- No Data Storage: Does not store or upload your code
- Open Source: MIT Licensed, transparent codebase
- Privacy First: Your secrets never leave your system
โ Exit Codes
| Exit Code | Meaning |
|---|---|
| 0 | No secrets found โ commit allowed |
| 1 | Secrets detected โ commit blocked |
| 2 | Environment/tool errors |
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
๐ License
MIT License โ Free to use, modify, and distribute.
โค๏ธ Support
If you like this project, โญ star the repo and share it!
Author: ๐ค Vamil Porwal
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file git_shield-1.2.0.tar.gz.
File metadata
- Download URL: git_shield-1.2.0.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
731fb1745872e527632872a4f65d8882969065d58a88bcf91d648376b77c6072
|
|
| MD5 |
04a4f051f404191bd15deff55cc8e661
|
|
| BLAKE2b-256 |
eee341818ed5c852cb4edc6e998eaec10fc08ec00d01577d2456029bb7ab8fca
|
File details
Details for the file git_shield-1.2.0-py3-none-any.whl.
File metadata
- Download URL: git_shield-1.2.0-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
253345853806016d2b9ac40318dbee293f4e4ebfa557e729cb998be710d48938
|
|
| MD5 |
32ee3a2f61e8756f206f14d07cd5cd57
|
|
| BLAKE2b-256 |
705dd3de292b073bca5608bec13e8e08015efc9b6502dd46a1450c8346ac2453
|