Skip to content

SecScan is a fast, configurable secret scanning tool written in Go that detects API keys, tokens, credentials, and high-entropy secrets across source code and full Git history. Built for developers and CI pipelines, with strong defaults and low false positives.

License

Notifications You must be signed in to change notification settings

Zayan-Mohamed/secscan

Repository files navigation

SecScan - Enhanced Secret Scanner

Logo

License Go Version GitHub release

Fast, configurable, and intelligent secret detection for your source code

Quick Start β€’ Documentation β€’ Examples β€’ Changelog


οΏ½ Quick Install

Linux & macOS

curl -fsSL https://raw.githubusercontent.com/Zayan-Mohamed/secscan/main/scripts/install-curl.sh | bash

Windows (PowerShell)

irm https://raw.githubusercontent.com/Zayan-Mohamed/secscan/main/scripts/install-windows.ps1 | iex

Using Go

go install github.com/Zayan-Mohamed/secscan@latest

πŸ’‘ More installation options: See Installation Guide


πŸš€ Features

  • βœ… Enhanced Detection - 20+ built-in patterns for API keys, tokens, and secrets
  • 🧠 Smart Entropy Analysis - Configurable Shannon entropy detection with reduced false positives
  • 🎯 Deduplication - Automatically removes duplicate findings across commits
  • 🚫 Allowlist Support - Filter out known false positives
  • πŸ“Š Detailed Statistics - Track scan performance and coverage
  • 🎨 Rich Output - Color-coded severity levels and clean formatting
  • πŸ“œ Git History Scanning - Deep scan through your entire git history
  • πŸ”§ Configurable - Custom rules via TOML configuration
  • ⚑ Fast - Written in Go for maximum performance
  • πŸ“„ JSON Export - Machine-readable output for CI/CD integration
  • πŸ™ˆ Gitignore Support - Automatically respects .gitignore patterns to skip irrelevant files
  • 🌍 Cross-Platform - Works on Linux, macOS, and Windows

πŸ“¦ Installation

Quick Install by Platform

🐧 Linux / 🍎 macOS

# Navigate to secscan directory
cd secscan

# Option 1: Using installation script (recommended)
./install.sh

# Option 2: Using Make
make install         # System-wide (requires sudo)
# OR
make install-local   # User-only (no sudo)

πŸͺŸ Windows

# Navigate to secscan directory
cd secscan

# Using PowerShell script (recommended)
.\install.ps1

# For system-wide installation (requires admin):
.\install.ps1 -Global

Note: Windows doesn't come with make by default. Use the PowerShell script instead.

🌍 Universal Installer (All Platforms)

Works on Linux, macOS, and Windows:

cd secscan
go run installer/install.go

Verify Installation

secscan -version
which secscan

🎯 Quick Start

# Scan current directory
secscan

# Scan specific directory
secscan -root /path/to/project

# Scan without git history (faster)
secscan -history=false

# Respect .gitignore files (default behavior)
secscan -respect-gitignore=true

# Disable gitignore (scan all files including ignored ones)
secscan -respect-gitignore=false

# Adjust entropy threshold (higher = fewer false positives)
secscan -entropy 6.0

# Disable entropy detection entirely
secscan -no-entropy

# Export results to JSON
secscan -json report.json

# Verbose output (show all findings)
secscan -verbose

# Quiet mode (for CI/CD)
secscan -quiet

πŸ” Detection Patterns

SecScan detects the following secret types out of the box:

  • Cloud Providers: AWS keys, Google API keys
  • Payment: Stripe keys (live & restricted)
  • Version Control: GitHub tokens (PAT, OAuth, App)
  • Communication: Slack tokens & webhooks
  • Email: SendGrid, Mailgun API keys
  • Database: Connection strings (PostgreSQL, MySQL, MongoDB, Redis)
  • Authentication: JWT tokens, Supabase keys
  • Generic: API keys, secrets, passwords
  • High Entropy: Random-looking strings (configurable)

βš™οΈ Configuration

Custom Rules File

Create a .secscan.toml file:

# Custom detection rules
custom_api = "mycompany_api_[0-9a-zA-Z]{32}"
internal_token = "int_tok_[A-Za-z0-9]{40}"

Use it:

secscan -config .secscan.toml

Gitignore Support

SecScan automatically respects .gitignore files in your repository, helping to:

  • βœ… Skip build artifacts, dependencies, and generated files
  • βœ… Reduce false positives from vendor code
  • βœ… Speed up scans by skipping irrelevant files
  • βœ… Work seamlessly with your existing Git workflow

How it works:

  • Automatically finds and loads all .gitignore files in the repository
  • Supports nested .gitignore files in subdirectories
  • Handles negation patterns (!important.txt)
  • Supports directory-only patterns (logs/)
  • Compatible with standard gitignore glob patterns

Examples:

# Default: gitignore is enabled
secscan -root .

# Explicitly enable gitignore (same as default)
secscan -respect-gitignore=true

# Disable gitignore to scan ALL files (useful for security audits)
secscan -respect-gitignore=false

# Verbose mode shows which files are being skipped
secscan -verbose -respect-gitignore=true

When to disable gitignore:

  • Security audits where you need to scan everything
  • Checking if secrets exist in build artifacts
  • Debugging scan results

Entropy Threshold

The entropy threshold controls how "random" a string must be to be flagged:

  • Default: 5.0 (balanced)
  • Strict: 6.0+ (fewer false positives)
  • Lenient: 4.0-4.5 (more sensitive)
  • Disabled: Use -no-entropy
# Strict mode - very high confidence
secscan -entropy 6.5

# Lenient mode - catch more potential secrets
secscan -entropy 4.0

πŸ“Š Output Format

Human-Readable Output

πŸ” SecScan v2.0.0 - Enhanced Secret Scanner
πŸ“‚ Scanning: /path/to/project
βš™οΈ  Entropy threshold: 5.0
πŸ“‹ Rules loaded: 20
πŸ“œ Git history: enabled

πŸ” Secret Scan Results
==================================================
Total findings: 5
  Critical (β‰₯0.9): 2
  High (β‰₯0.8):     1
  Medium (β‰₯0.6):   2
  Low (<0.6):      0
==================================================

πŸ”΄ [CRITICAL] [AWS_ACCESS_KEY] src/config.js:42
  β†’ AKIA****************ABCD (confidence: 0.90)

🟠 [HIGH] [GITHUB_PAT] .env:15
  β†’ ghp_********************************WXYZ (confidence: 0.85)

πŸ“Š Scan Statistics
==================================================
Files scanned:    1,234
Commits scanned:  567
Total findings:   12,345
Unique findings:  5
Scan duration:    2.5s
==================================================

JSON Output

{
  "findings": [
    {
      "file": "src/config.js",
      "line": 42,
      "pattern": "aws_access_key",
      "excerpt": "AKIA****************ABCD",
      "confidence": 0.9,
      "verified": false,
      "hash": "a1b2c3d4e5f6g7h8"
    }
  ],
  "stats": {
    "files_scanned": 1234,
    "commits_scanned": 567,
    "findings_total": 12345,
    "findings_unique": 5,
    "scan_duration_ms": 2500
  },
  "version": "2.0.0"
}

πŸ›‘οΈ CI/CD Integration

GitHub Actions

name: Secret Scan

on: [push, pull_request]

jobs:
  secscan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          fetch-depth: 0 # Full history for git scanning

      - name: Setup Go
        uses: actions/setup-go@v4
        with:
          go-version: "1.21"

      - name: Install SecScan
        run: |
          cd secscan
          make install-local

      - name: Run SecScan
        run: secscan -quiet -json secscan-report.json

      - name: Upload Results
        if: always()
        uses: actions/upload-artifact@v3
        with:
          name: secscan-report
          path: secscan-report.json

GitLab CI

secret_scan:
  image: golang:1.21
  script:
    - cd secscan
    - make install-local
    - export PATH="$HOME/.local/bin:$PATH"
    - secscan -quiet -json report.json
  artifacts:
    reports:
      junit: report.json
    when: always

πŸŽ“ How It Works

1. Pattern Matching

SecScan uses regex patterns to detect known secret formats (AWS keys, GitHub tokens, etc.)

2. Entropy Analysis

Calculates Shannon entropy to find high-randomness strings that might be secrets:

Entropy = -Ξ£(p(x) * log2(p(x)))

Strings with entropy > threshold and diverse character sets are flagged.

3. Deduplication

Uses SHA-256 hashing to identify and remove duplicate findings across different files/commits.

4. Allowlisting

Filters out common false positives:

  • All-caps constants
  • Test/example values
  • Boolean literals
  • Masked secrets

πŸ”§ Advanced Usage

Skip Git History for Speed

secscan -history=false

Scan Only Specific Patterns

Create a minimal config with only the rules you need:

# minimal-rules.toml
aws_access_key = "AKIA[0-9A-Z]{16}"
github_pat = "ghp_[0-9a-zA-Z]{36}"
secscan -config minimal-rules.toml

Combine with Other Tools

# Find secrets and filter by pattern
secscan -json findings.json
jq '.findings[] | select(.pattern == "aws_access_key")' findings.json

# Count secrets by type
jq '.findings | group_by(.pattern) | map({pattern: .[0].pattern, count: length})' findings.json

πŸ“ˆ Improvements Over v1.0

Feature v1.0 v2.0
Detection Patterns 4 20+
False Positive Rate High (511K findings) Low (~95% reduction)
Deduplication ❌ βœ…
Allowlist Support ❌ βœ…
Configurable Entropy ❌ (fixed 4.0) βœ… (default 5.0)
Skip Files/Dirs Limited Comprehensive
Output Formatting Basic Rich with colors
Statistics ❌ βœ…
Performance Good Excellent

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

πŸ“„ License

MIT License - see LICENSE file for details

πŸ™ Acknowledgments

Inspired by:

πŸ“ž Support


Made with ❀️ by the SecScan team

About

SecScan is a fast, configurable secret scanning tool written in Go that detects API keys, tokens, credentials, and high-entropy secrets across source code and full Git history. Built for developers and CI pipelines, with strong defaults and low false positives.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •