๐Ÿ” Secure Your Codebase: Discover Exposed Secrets Instantly with Secret-Hunter

Anurag SinghAnurag Singh
6 min read

Accidentally pushed an API key to GitHub? You're not alone โ€” and you're not safe.

Whether it's an OpenAI token, AWS credentials, or a database password, secrets can slip into your codebase faster than you realize. One leaked key can lead to:

  • ๐Ÿšจ Compromised systems

  • ๐Ÿ’ธ Unexpected cloud bills

  • ๐Ÿ” Major security incidents

That's why I built secret-hunter โ€” a zero-config, lightning-fast CLI tool to scan your code for exposed secrets before they go public.

๐Ÿš€ What Is secret-hunter?

secret-hunter is a developer-friendly command-line tool that finds:

  • API Keys: OpenAI, Google, GitHub, Stripe, Slack, Discord, Twitter

  • Cloud credentials: AWS access keys, Azure tokens, Google Cloud keys

  • Database URLs: MongoDB, PostgreSQL, MySQL, Redis connection strings

  • Private keys: SSH keys, RSA keys, JWT secrets

  • Authentication tokens: OAuth tokens, Bearer tokens, webhook secrets

The tool scans your entire codebase in seconds and tells you exactly where potential secrets are hiding.

๐Ÿง  Why I Built This

Most existing tools are either:

  • Too slow โ€” taking minutes to scan what should take seconds

  • Hard to configure โ€” requiring complex YAML files and setup

  • Built only for CI/CD โ€” designed for pipelines, not everyday development

  • Enterprise-focused โ€” built for large teams, not individual developers

I wanted something simple. Something you could run in 5 seconds before every commit. Something that just works without reading documentation.

โšก Features That Actually Matter

Zero Configuration

npx secret-hunter

No config files. No setup. No reading docs. Just run it and get results immediately.

Lightning Fast Performance

  • โšก Scans thousands of files in seconds โ€” not minutes like other tools

  • ๐Ÿ“ Smart ignores โ€” automatically skips node_modules, .git, dist, .next, build, and other irrelevant directories

  • ๐ŸŽฏ Optimized patterns โ€” uses efficient matching without false positives

  • ๐Ÿ” Recursive scanning โ€” goes through your entire project structure

Comprehensive Secret Detection

The tool recognizes over 20 different types of secrets:

API Keys & Tokens:

  • OpenAI API keys (sk-...)

  • Google API keys (AIza...)

  • GitHub tokens (ghp_..., gho_...)

  • Stripe keys (sk_live_..., pk_live_...)

  • Slack tokens (xoxb-..., xoxp-...)

  • Discord bot tokens

  • Twitter API keys

Cloud Provider Credentials:

  • AWS access keys (AKIA...)

  • Azure subscription keys

  • Google Cloud service account keys

  • DigitalOcean tokens

Database Connections:

  • MongoDB connection strings (mongodb://...)

  • PostgreSQL URLs (postgresql://...)

  • MySQL connection strings

  • Redis URLs (redis://...)

Private Keys:

  • SSH private keys (-----BEGIN OPENSSH PRIVATE KEY-----)

  • RSA private keys (-----BEGIN RSA PRIVATE KEY-----)

  • JWT secrets

  • Generic private keys

Developer-Friendly Output

๐Ÿ” Starting secret scan...
Collecting files...
Found 3 files to scan
Scanning for secrets...

Progress: 3/3 files

๐Ÿ” SECRET SCANNER REPORT
==================================================

๐Ÿ“Š SCAN SUMMARY
------------------------------
๐Ÿ“ Total files scanned: 3
๐Ÿšจ Total secrets found: 1
๐Ÿ“„ Files with secrets: 1
๐Ÿ” Secret types found: 1

๐Ÿšจ DETAILED FINDINGS
------------------------------

๐Ÿ“ File 1: D:\All data\test\index.js
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
  1. API Key Pattern
     Line: 4
     Code: const apiKey="AIzaSyA-FAKEKEY1234567890abcdefgHIJKL"

๐Ÿ’ก RECOMMENDATIONS
------------------------------
1. Remove hardcoded secrets from your code
2. Use environment variables (.env files)
3. Add .env to your .gitignore
4. Use secret management tools for production

==================================================
๐Ÿ” Scan completed successfully!

Color-coded, clean, and actionable. You know exactly what to fix and where to find it.

๐Ÿ”ฅ Real-World Use Cases

1. Pre-Commit Safety Check

# Your new workflow
git add .
npx secret-hunter
# Only commit if no secrets found
git commit -m "Clean commit"

2. Code Review Process

Before approving any pull request, run secret-hunter to catch secrets that might have slipped through manual review.

3. Project Auditing

Just inherited a legacy codebase? Run secret-hunter to see what secrets might be lurking in the code.

4. Team Onboarding

Perfect for showing new developers what secrets look like and how to avoid committing them.

5. Open Source Preparation

Before making your private repo public, scan it to ensure no internal secrets are exposed.

๐Ÿ†š How It Compares to Alternatives

ToolSetup RequiredSpeedPrimary Use Case
gitleaksMedium (TOML config)MediumGit history scanning
truffleHogHeavy setupSlowDeep forensic analysis
detect-secretsMedium configMediumPre-commit hooks
secret-hunterNoneFastDaily development

Why Choose secret-hunter?

For gitleaks users: If you want something that works without writing config files and focuses on current code, not git history.

For truffleHog users: If you need speed over deep analysis and want to scan before commits, not after.

For detect-secrets users: If you want zero setup and don't need Python-specific features.

๐Ÿ’ก The Philosophy Behind It

I built this tool with one principle: Security shouldn't slow you down.

Most developers don't need enterprise-grade secret management. They need something that:

  • Works immediately without setup

  • Fits into their existing workflow

  • Catches problems before they become disasters

  • Doesn't require learning new tools

๐Ÿงช Installation & Usage

Quick Start

# Run once without installing
npx secret-hunter

# Install globally for repeated use
npm install -g secret-hunter
secret-hunter

Command Line Options

# Scan specific directory
secret-hunter /path/to/project

# Scan current directory (default)
secret-hunter .

# Get help
secret-hunter --help

Integration Examples

Pre-commit hook:

{
  "husky": {
    "hooks": {
      "pre-commit": "secret-hunter"
    }
  }
}

Package.json script:

{
  "scripts": {
    "security-check": "secret-hunter",
    "pre-commit": "secret-hunter && git add ."
  }
}

๐Ÿ”„ What's Coming Next

Based on user feedback, here's what's planned:

  • โœ… JSON output format for CI/CD pipeline integration

  • โœ… Custom ignore patterns for project-specific needs

  • โœ… Configurable sensitivity levels

  • โœ… Git hook integration for automatic scanning

  • โœ… Plugin system for custom secret patterns

  • โœ… Directory-specific scanning for large monorepos

๐ŸŒ Try It Right Now

Want to see if your current project has any exposed secrets?

npx secret-hunter

Most projects scan in under 10 seconds.

๐Ÿ“Š Performance Benchmarks

Here's how secret-hunter performs on different project sizes:

  • Small project (< 100 files): ~1-2 seconds

  • Medium project (100-1000 files): ~3-5 seconds

  • Large project (1000+ files): ~8-15 seconds

Tested on MacBook Pro M1, results may vary based on your system.

๐Ÿ› ๏ธ Technical Details

What It Scans

  • All text files in your project

  • Common code file extensions (.js, .ts, .py, .go, .rb, .php, etc.)

  • Configuration files (.env, .yml, .json, .xml)

  • Documentation files (.md, .txt)

What It Ignores

  • Binary files

  • node_modules directories

  • .git directories

  • Build output folders (dist, build, .next)

  • Cache directories

  • Log files

Detection Method

Uses pattern matching with carefully crafted regular expressions that balance accuracy with performance. No false positives from comments or documentation.

๐Ÿค Contributing

Found a bug? Want to add support for a new secret type? Contributions are welcome!

Easy ways to contribute:

  • Report bugs or suggest features on GitHub

  • Add new secret patterns

  • Improve documentation

  • Share the tool with other developers

๐Ÿงก Final Thoughts

Every developer will accidentally expose a secret at some point. The question isn't "if" โ€” it's "when."

secret-hunter exists to be your safety net. It's the tool that runs quickly in the background, catching mistakes before they become problems.

I built this because I needed it. If it helps even one developer avoid a security incident, it's accomplished its purpose.

๐ŸŒŸ Get Started

๐Ÿ”— Links:

If you find secret-hunter helpful:

  • โญ Star the repo to help others discover it

  • ๐Ÿ› Report issues to help improve it

  • ๐Ÿ”„ Contribute โ€” PRs are always welcome

  • ๐Ÿ“ข Share with your team

Let's build more secure code, one scan at a time.


Built by Anurag Singh ๐Ÿ‘จโ€๐Ÿ’ป

Making developer security simple, one tool at a time.


0
Subscribe to my newsletter

Read articles from Anurag Singh directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Anurag Singh
Anurag Singh