Skip to content

Secret Scanning Tools

Suphi Cankurt

Written by Suphi Cankurt

Key Takeaways
  • Gitleaks and TruffleHog are the two leading open-source secret scanners — Gitleaks runs faster as a pre-commit hook, while TruffleHog verifies leaked credentials are still active.
  • GitGuardian detects secrets in real-time across 550+ secret types and automatically checks if leaked credentials have been exposed on public repositories.
  • Pre-commit scanning catches secrets before they enter git history — once a secret is committed, it persists in git history even after the file is deleted.
  • The average enterprise codebase contains 5.5 hardcoded secrets per developer per year, and remediation after commit costs 13x more than pre-commit detection.

Secret scanning tools detect hardcoded credentials, API keys, passwords, and tokens in source code and git history. They prevent the kind of leaks that lead to data breaches, account takeover, and unauthorized access to cloud infrastructure.

Why Secret Scanning Matters

A hardcoded secret in a git repository is a ticking time bomb. Once an AWS key, database password, or API token lands in a commit, it stays in git history permanently. Deleting the file in a later commit does not remove it. Anyone with read access to the repository can extract that secret from the commit log.

According to GitGuardian’s 2024 State of Secrets Sprawl report, the average enterprise codebase contains 5.5 hardcoded secrets per developer per year. Multiply that across a 100-person engineering team and you have 550 exposed credentials annually. Each one is a potential entry point for attackers.

The financial impact is severe. IBM’s 2024 Cost of a Data Breach Report found that compromised credentials are the most common initial attack vector, accounting for 16% of breaches. These breaches take an average of 292 days to identify and contain. Stolen credentials remain the top initial access vector in the 2024 Verizon DBIR as well.

Remediation timing matters more than most teams realize. Catching a secret in a pre-commit hook costs minutes of developer time. Catching the same secret after it reaches a public repository costs incident response, credential rotation, access log auditing, and potentially customer notification. Industry estimates put post-commit remediation at 13x the cost of pre-commit detection.

The bottom line: secret scanning belongs at two points in your workflow. First, as a pre-commit hook that blocks secrets before they enter git history. Second, as a CI/CD pipeline step that catches anything the pre-commit hook missed.


Top Secret Scanning Tools

1. Gitleaks

Gitleaks is the most widely adopted open-source secret scanner with 24,400+ GitHub stars. Written in Go, it runs as a single binary with no external dependencies. Gitleaks uses regex patterns defined in a TOML configuration file to detect 150+ secret types including AWS keys, GitHub tokens, Slack webhooks, and database credentials.

Gitleaks shines as a pre-commit hook. It scans staged changes in milliseconds, blocking secrets before they enter the repository. The tool also scans entire git history, directories, and files. Output formats include JSON, CSV, JUnit, and SARIF (which integrates directly with GitHub Advanced Security alerts).

Since v8.28.0, composite rules let you combine primary and auxiliary detection patterns with proximity constraints. This reduces false positives by flagging secrets only when they appear near related identifiers.

License: MIT (fully free) Best for: Fast pre-commit scanning and GitHub Actions integration.

2. TruffleHog

TruffleHog is the secret scanner that verifies what it finds. Developed by Truffle Security with 24,500+ GitHub stars, it detects and classifies 800+ secret types. The key differentiator is live credential verification: when TruffleHog finds an AWS key, it tests whether that key still works.

TruffleHog scans far beyond git. It covers S3 buckets, GCS, Docker images, Slack workspaces, Jenkins servers, Elasticsearch clusters, Postman workspaces, CircleCI, and Travis CI. For each discovered secret, TruffleHog maps the credential to a specific identity and analyzes permissions for 20+ common credential types.

The --results=verified flag filters output to only confirmed active credentials. This separates emergency incidents (working credentials) from historical noise (revoked credentials) and cuts triage time.

License: AGPL-3.0 (open-source), commercial plans available Best for: Multi-source scanning with credential verification.

3. GitGuardian

GitGuardian is a managed secrets detection platform and the #1 security app on the GitHub Marketplace. It monitors repositories in real-time, detecting 550+ secret types across GitHub, GitLab, Bitbucket, and collaboration tools like Slack, Jira, and Confluence.

GitGuardian validates whether detected secrets are still active, so teams can prioritize live credentials over expired ones. The ggshield CLI tool runs as a pre-commit hook and CI/CD gate. Beyond detection, GitGuardian offers Non-Human Identity (NHI) governance to track machine credentials across the organization, plus honeytoken intrusion detection.

A free plan is available for individual developers. Team and enterprise plans add dashboards, incident management, and policy controls.

License: Freemium (free tier for individuals, commercial for teams) Best for: Teams that want a managed platform with dashboards, collaboration tool scanning, and NHI governance.

4. Detect-Secrets (Yelp)

Detect-Secrets takes a different approach to secret scanning. Instead of flagging every secret in a repository, it maintains a baseline file of known secrets and only blocks new ones. This makes it ideal for enterprise codebases with hundreds of existing secrets where remediating everything upfront is not feasible.

The tool uses a plugin architecture with 27 built-in detectors. It scans git diffs rather than full repositories, keeping overhead minimal for monorepos and large codebases. An audit mode lets you review and label each finding in the baseline.

License: Apache 2.0 (fully free) Best for: Enterprise teams with legacy codebases that need incremental adoption.

5. GitHub Secret Scanning

GitHub Secret Scanning is built into GitHub and requires no separate tool installation. It partners with 200+ service providers (AWS, Google Cloud, Stripe, Twilio) who register their token patterns. When a matching pattern is pushed to a public repository, GitHub can notify the provider to revoke the credential automatically. Push protection blocks commits containing detected secrets before they reach the repository.

The feature is free for public repositories. Private repository scanning requires GitHub Advanced Security.

License: Free (public repos), GitHub Advanced Security (private repos) Best for: GitHub-native teams wanting zero-configuration detection with automatic credential revocation.

6. AWS git-secrets

AWS git-secrets is a lightweight tool focused specifically on preventing AWS credentials from being committed to git repositories. It installs as a git hook and scans commits, commit messages, and merges for AWS access keys, secret keys, and credential file patterns.

The tool is narrower in scope than Gitleaks or TruffleHog. It detects AWS-specific patterns and not much else. For teams running exclusively on AWS that want a minimal pre-commit check, it fills the gap. Most teams pair it with a broader scanner.

License: Apache 2.0 (fully free) Best for: AWS-focused teams wanting a minimal, targeted pre-commit check.

7. Talisman

Talisman is a git hook tool developed by ThoughtWorks that prevents secrets and sensitive information from being pushed to repositories. It inspects outgoing changesets for suspicious content including credentials, SSH keys, authorization tokens, and large binary files.

Talisman supports both pre-commit and pre-push hooks. It can be installed globally across all git repositories on a machine, which simplifies rollout for organizations. A checksum-based ignore mechanism handles false positives.

License: MIT (fully free) Best for: Organizations using ThoughtWorks tooling that want global pre-push hooks across all developer machines.

8. SpectralOps (Check Point)

SpectralOps, acquired by Check Point in 2022, combines secrets detection with Infrastructure-as-Code misconfiguration scanning. The tool ships as a single binary and scans source code, CI/CD pipelines, and build logs for hardcoded credentials and IaC policy violations.

SpectralOps supports custom detectors and integrates with GitHub, GitLab, Bitbucket, and Azure DevOps. After the Check Point acquisition, it has been integrated into the broader Check Point CloudGuard platform.

License: Commercial Best for: Teams that want combined secrets and IaC scanning from a single vendor.


Feature Comparison

FeatureGitleaksTruffleHogGitGuardianDetect-SecretsGitHub Secret Scanninggit-secretsTalismanSpectralOps
LicenseMITAGPL-3.0 / CommercialFreemiumApache 2.0Free (public) / GHASApache 2.0MITCommercial
Secret patterns150+800+550+27 detectors200+ partnersAWS-focusedGeneric patternsCustom + built-in
Credential verificationNoYesYesOptionalPartner revocationNoNoYes
Pre-commit hookYesYesYes (ggshield)YesPush protectionYesYes (+ pre-push)No
Git history scanYesYesYesBaseline diffsNoNoNoYes
Non-git sourcesNoS3, Docker, Slack, CISlack, Jira, ConfluenceNoNoNoNoCI/CD logs
SARIF outputYesNoNoNoNative GitHubNoNoNo
GitHub ActionYesYesYesCommunityNativeNoCommunityYes
Custom rulesTOMLRegex + keywordsYesPlugin-basedLimitedRegexRegexYes

Pre-Commit Hook Setup

A pre-commit hook is the single most effective control for secret prevention. It runs locally on every developer’s machine and blocks commits that contain detected secrets. The secret never reaches the repository, which means it never enters git history and never needs rotation.

Gitleaks pre-commit configuration

Add Gitleaks to your .pre-commit-config.yaml:

repos:
  - repo: https://github.com/gitleaks/gitleaks
    rev: v8.24.2
    hooks:
      - id: gitleaks

Run pre-commit install to activate the hook. Every commit is now scanned. If a secret is detected, the commit is blocked and Gitleaks prints the offending line. Developers can skip the hook for a specific commit with SKIP=gitleaks git commit when they have verified a finding is a false positive.

Detect-Secrets pre-commit configuration

For teams using the baseline approach:

repos:
  - repo: https://github.com/Yelp/detect-secrets
    rev: v1.5.0
    hooks:
      - id: detect-secrets
        args: ['--baseline', '.secrets.baseline']

This scans only staged changes against the baseline. New secrets are blocked. Existing secrets recorded in the baseline are allowed through.


CI/CD Integration

Pre-commit hooks run locally and can be bypassed. A CI/CD scanning step acts as a safety net, catching secrets that slip past local hooks.

GitHub Actions with Gitleaks

name: Secret Scanning
on: [push, pull_request]

jobs:
  gitleaks:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - uses: gitleaks/gitleaks-action@v2
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

The action scans the full git diff for each push or pull request. Findings appear as annotations directly on the pull request.

GitHub Actions with TruffleHog

name: Secret Scanning
on: [push, pull_request]

jobs:
  trufflehog:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
      - name: TruffleHog scan
        uses: trufflesecurity/trufflehog@main
        with:
          extra_args: --results=verified --fail

The --results=verified flag reports only confirmed active credentials. The --fail flag exits with code 183 when secrets are found, failing the CI job.

GitLab CI with GitGuardian

ggshield-scan:
  image: gitguardian/ggshield:latest
  script:
    - ggshield secret scan ci
  variables:
    GITGUARDIAN_API_KEY: $GITGUARDIAN_API_KEY
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event"
    - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH

How to Choose a Secret Scanner

Picking the right secret scanner depends on three factors: where your code lives, how your team works, and what you need beyond detection.

Start with the basics. If you have a git repository and no secret scanning today, install Gitleaks as a pre-commit hook. It takes five minutes, catches the most common secret patterns, and runs fast enough that developers will not notice it. This single step prevents the majority of accidental credential commits.

Add depth in CI/CD. Once pre-commit scanning is in place, add TruffleHog to your CI/CD pipeline. Its credential verification capability confirms which detected secrets are still active, so your security team spends time on real incidents rather than triaging expired credentials. The combination of Gitleaks pre-commit and TruffleHog in CI is the most popular open-source pattern.

Consider a managed platform if you need dashboards and governance. GitGuardian adds incident management, remediation workflows, NHI governance, and collaboration tool scanning. If your security team manages secrets across dozens of repositories and needs centralized visibility, a platform saves operational overhead compared to running CLI tools.

Handle legacy codebases with a baseline approach. If your repository already contains hundreds of secrets and remediating all of them before adopting scanning is not feasible, Detect-Secrets lets you accept existing secrets while blocking new ones. This is the pragmatic choice for brownfield projects.

Use GitHub Secret Scanning if you are all-in on GitHub. For teams that use GitHub exclusively and want zero-configuration scanning, GitHub’s built-in secret scanning with push protection covers the baseline. Pair it with a dedicated tool for broader coverage.

Decision summary

ScenarioRecommended tool
Fast pre-commit blockingGitleaks
Credential verification in CI/CDTruffleHog
Managed platform with dashboardsGitGuardian
Legacy codebase with existing secretsDetect-Secrets
GitHub-only, zero configurationGitHub Secret Scanning
Combined pre-commit + CI/CDGitleaks (pre-commit) + TruffleHog (CI)

For a head-to-head breakdown of the two most popular open-source options, read Gitleaks vs TruffleHog. For the broader DevSecOps tooling space, see DevSecOps Tools or Shift-Left Security.

This guide is part of our DevSecOps & AppSec Programs resource hub.

Frequently Asked Questions

What is the best free secret scanning tool?
Gitleaks is the most popular free secret scanner with over 24,400 GitHub stars. It runs as a pre-commit hook or CI/CD step, scanning for 150+ secret patterns including AWS keys, API tokens, and database credentials. For teams that need credential verification (checking if leaked secrets are still active), TruffleHog is the better choice.
What is the difference between Gitleaks and TruffleHog?
Gitleaks is faster and simpler — it uses regex patterns to detect secrets and works best as a pre-commit hook. TruffleHog goes deeper by verifying whether detected secrets are still active (e.g., testing if an AWS key still works). TruffleHog scans more sources (S3 buckets, Docker images, Slack) but runs slower.
Can GitHub's built-in secret scanning replace dedicated tools?
GitHub Secret Scanning detects secrets from partner patterns (AWS, Azure, Stripe, etc.) pushed to public repositories. It covers fewer patterns than Gitleaks or TruffleHog, does not scan git history retroactively, and requires GitHub Advanced Security for private repos. Dedicated tools offer broader detection, pre-commit blocking, and CI/CD flexibility.
How do I prevent secrets from being committed to git?
Install Gitleaks or Detect-Secrets as a pre-commit hook using the pre-commit framework. This scans staged changes before each commit and blocks any commit containing detected secrets. Add a CI/CD scanning step as a safety net for cases where developers bypass local hooks.
Suphi Cankurt

10+ years in application security. Reviews and compares 170 AppSec tools across 11 categories to help teams pick the right solution. More about me →