Skip to main content

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
  • ๐Ÿ›ก 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

git_shield-1.2.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

git_shield-1.2.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

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

Hashes for git_shield-1.2.0.tar.gz
Algorithm Hash digest
SHA256 731fb1745872e527632872a4f65d8882969065d58a88bcf91d648376b77c6072
MD5 04a4f051f404191bd15deff55cc8e661
BLAKE2b-256 eee341818ed5c852cb4edc6e998eaec10fc08ec00d01577d2456029bb7ab8fca

See more details on using hashes here.

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

Hashes for git_shield-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 253345853806016d2b9ac40318dbee293f4e4ebfa557e729cb998be710d48938
MD5 32ee3a2f61e8756f206f14d07cd5cd57
BLAKE2b-256 705dd3de292b073bca5608bec13e8e08015efc9b6502dd46a1450c8346ac2453

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page