Skip to content
detect-secrets

detect-secrets

Category: Secrets
License: Free (Open-Source, Apache-2.0)
Suphi Cankurt
Suphi Cankurt
+7 Years in AppSec
Updated February 12, 2026
8 min read
Key Takeaways
  • detect-secrets uses a baseline approach that accepts existing secrets while blocking new ones from entering version control.
  • Plugin-based architecture with 27 built-in detectors and support for custom regex-based detection plugins.
  • Scans only git diffs rather than full repositories, making it efficient for monorepos and large codebases.
  • Open-source under Apache-2.0 with 4,300 GitHub stars, developed and maintained by Yelp's security team.

detect-secrets is Yelp’s enterprise-friendly secret scanner that uses a baseline approach to prevent new credential leaks. According to OWASP’s Secrets Management Cheat Sheet, preventing secrets from entering version control is a foundational security practice.

Unlike scanners that report all secrets, detect-secrets accepts existing secrets in a baseline file while blocking any new ones from being committed.

This pragmatic approach makes detect-secrets ideal for brownfield projects and large organizations that need immediate protection without requiring massive remediation efforts upfront.

Yelp/detect-secrets README Quickstart section showing the three bash commands developers run to create and rescan a baseline file

I pair detect-secrets with pre-commit on any repo that accepts third-party contributions. Its baseline file lets me mark known-safe strings as reviewed so the scan stays quiet day to day. It does not verify secrets against live services the way TruffleHog does, but it is faster, has fewer runtime dependencies, and covers a broader pattern library out of the box.

What is detect-secrets?

detect-secrets scans git repositories and files to identify hardcoded credentials, API keys, and other secrets. The tool’s distinguishing feature is its baseline system: you create a baseline file containing hashes of all current secrets, then detect-secrets allows those secrets to pass while flagging anything new.

The scanner works by analyzing git diffs rather than scanning entire repositories on each run. This differential approach minimizes overhead and provides fast feedback in pre-commit hooks and CI pipelines.

You see only what changed, not repeated warnings about historical issues.

detect-secrets uses a plugin architecture for secret detection. Each plugin targets specific secret patternsβ€”AWS keys, private keys, Slack tokens, etc. You can enable built-in plugins or write custom regex-based detectors for proprietary credentials.

Baseline Management
Accept existing secrets in a baseline file while blocking new ones, enabling immediate protection without full historical remediation
Differential Scanning
Scan git diffs instead of entire repositories to minimize overhead and provide fast feedback on changes
Plugin Architecture
Extensible detection system with built-in plugins for common secrets plus custom regex support for proprietary credentials

Why secret detection in source code matters

Leaked credentials in source repositories are one of the most exploited initial-access patterns. GitHub’s secret scanning regularly catches AWS keys, Slack tokens, and API credentials in public commits within seconds of push, and historical scans against the public commit graph routinely surface millions of valid secrets per year. Once a credential lands in git history, rotation is the only fix β€” removal from a single commit does not erase it from clones, forks, or mirrors.

The practical problem is brownfield: most established codebases already contain old credentials buried in commit history. Asking a team to remediate every historical secret before turning on a scanner stalls adoption indefinitely. detect-secrets solves this with a baseline file that accepts what is already there and blocks anything new β€” protection starts on day one, remediation runs on the team’s own schedule. Pre-commit hooks block leaks before they reach version control, which is the only place a scanner can actually prevent rather than merely detect.

Key features

FeatureDetails
Built-in detectors27 plugins covering AWS, GitHub, GitLab, Slack, Stripe, Twilio, Discord, and more
Detection strategiesRegex-based rules, Base64/Hex entropy analysis, keyword matching
Entropy thresholdsBase64 default 4.5, Hex default 3.0 (configurable 0.0–8.0)
CLI commandsscan, audit, detect-secrets-hook
Output formatJSON baseline file (.secrets.baseline)
Installationpip, Homebrew, or from source
LicenseApache-2.0
VerificationOptional network verification via --only-verified flag

Baseline creation and auditing

The baseline file (.secrets.baseline) is a JSON document with hashes of every detected secret. When you re-scan, detect-secrets compares new findings against this baseline.

Secrets already recorded pass through; new ones trigger failures. You commit this file to version control alongside your code.

The audit command supports diffing two baselines and generating statistical reports. You can label each finding, and those labels persist across re-scans β€” useful for tracking which secrets your team has reviewed versus which still need remediation.

27 built-in detectors

detect-secrets ships 27 built-in detectors across three detection strategies: regex-based rules for structured secrets like AWS keys and GitHub tokens, entropy detection for random-looking strings using Base64 and Hex analysis, and keyword detection that flags variable names tied to hardcoded credentials.

detect-secrets 27 built-in detectors grouped into 6 categories: cloud providers (AWS, Azure, IBM, Softlayer β€” 6 detectors), code platforms (GitHub, GitLab, npm, PyPI β€” 4 detectors), communication (Slack, Discord, Telegram, Mailchimp, SendGrid, Twilio β€” 6 detectors), payment/SaaS (Stripe, Square, Artifactory, OpenAI β€” 4 detectors), general credentials (RSA/DSA/EC/PGP keys, basic auth, JWT, keyword β€” 4 detectors), and entropy analysis (Base64 and Hex high-entropy strings β€” 3 detectors)
CategoryDetectors
Cloud providersAWSKeyDetector, AzureStorageKeyDetector, IbmCloudIamDetector, IbmCosHmacDetector, CloudantDetector, SoftlayerDetector
Code platformsGitHubTokenDetector, GitLabTokenDetector, NpmDetector, PypiTokenDetector
CommunicationSlackDetector, DiscordBotTokenDetector, TelegramBotTokenDetector, MailchimpDetector, SendGridDetector, TwilioKeyDetector
Payment/SaaSStripeDetector, SquareOAuthDetector, ArtifactoryDetector, OpenAIDetector
GeneralPrivateKeyDetector, BasicAuthDetector, JwtTokenDetector, KeywordDetector, IPPublicDetector
EntropyBase64HighEntropyString, HexHighEntropyString

Pre-commit hook integration

Install detect-secrets as a pre-commit hook to scan staged changes before commits go through. If a developer tries to commit new secrets, the hook blocks the commit and shows the offending content.

Real VS Code terminal output from a failed pre-commit run where the detect-secrets hook blocked a commit β€” the header shows 'Detect secrets........Failed', hook id: detect-secrets, exit code: 1, then 'ERROR: Potential secrets about to be committed to git repo!' with Secret Type: Secret Keyword and Location: src/python/hello.py:1, followed by mitigation guidance pointing developers to the #security channel or to mark false positives with an inline `pragma: allowlist secret` comment

Only changes that match the baseline or contain no secrets can be committed.

The hook runs in seconds because it scans only staged changes, not the entire repository.

Inline allowlisting

Inline allowlisting lets developers suppress false positives directly in code with pragma comments. Add # pragma: allowlist secret to the end of a line, or // pragma: allowlist nextline secret before a line, to exclude specific findings.

You can also exclude files, lines, or secret values globally using --exclude-files, --exclude-lines, and --exclude-secrets regex flags.

Optional secret verification

detect-secrets can optionally verify discovered secrets by making network requests to the associated services. The --only-verified flag limits output to secrets confirmed as live credentials.

This is off by default to avoid unexpected network traffic.

CI/CD integration

Run detect-secrets in CI pipelines to enforce secret policies on pull requests. The tool exits with a non-zero status code when new secrets are found, failing the build and preventing merges.

Configure CI to scan only the PR diff (fast) or the entire branch (comprehensive). Most teams scan diffs for quick feedback.

How detect-secrets works

detect-secrets is plugin-driven source code static analysis with rule-based pattern matching for CWE-798 (hardcoded credentials). On the first run, the scan command walks the repository, hashes every match from each enabled detector, and writes the result to .secrets.baseline as JSON. Each detector is a small Python class β€” AWSKeyDetector, GitHubTokenDetector, KeywordDetector, Base64HighEntropyString, and 23 others β€” that returns a list of (line, secret) pairs.

On every subsequent run, detect-secrets compares fresh findings against the baseline by hash. Secrets already recorded pass; new ones fail the scan. The pre-commit hook narrows that comparison to staged diff lines so the check runs in well under a second on a typical commit. Two helpers round out the workflow: audit walks the baseline interactively so you can label each finding as true or false positive, and --only-verified calls the underlying API for AWS/GitHub/Slack to confirm a secret is live before flagging it. The whole pipeline is git-diff first, full-repo never β€” which is why it scales on monorepos where Gitleaks or TruffleHog full scans become slow.

Getting started

1
Install β€” Run pip install detect-secrets or brew install detect-secrets. For word list support, use pip install detect-secrets[word_list].
2

Create a baseline β€” Run detect-secrets scan > .secrets.baseline in your repository root. This generates a JSON file with hashes of all detected secrets.

detect-secrets scan command creating a .secrets.baseline JSON file with hashed findings and plugin metadata
3
Add the pre-commit hook β€” Add detect-secrets to .pre-commit-config.yaml with args: ['--baseline', '.secrets.baseline']. New commits with secrets will be blocked.
4
Audit your baseline β€” Run detect-secrets audit .secrets.baseline to review each finding. Label secrets as true or false positives to build an audit trail.

detect-secrets alternatives

Teams comparing secrets scanners to detect-secrets usually evaluate:

  • Gitleaks β€” Go-based regex scanner with first-class git history support; preferred when you need to audit historical commits or when shell-shaped CI integration matters more than baseline-driven workflows.
  • TruffleHog β€” entropy-plus-verification scanner that actively probes detected credentials against vendor APIs to confirm they are live; chosen when low false-positive rate beats raw scan throughput.
  • GitHub secret scanning β€” built-in scanner for repositories on GitHub; a fit when you already pay for GitHub Advanced Security and want vendor partner verification across 200+ providers.
  • GitGuardian β€” commercial secrets-detection-as-a-service with continuous monitoring across GitHub, GitLab, and Slack; chosen when you need a managed remediation workflow rather than a CLI.

For a wider feature comparison, the SAST tools hub and the Gitleaks vs TruffleHog guide cover overlapping ground.

detect-secrets pricing and licensing

detect-secrets is fully free and open source under the Apache 2.0 license. There is no paid tier, no SaaS upsell, and no enterprise add-on: install with pip install detect-secrets, run scans locally or in CI, and ship without a vendor relationship. The project lives at github.com/Yelp/detect-secrets and continues to receive maintenance from Yelp’s security engineering team and external contributors.

Because the tool is library-shaped rather than service-shaped, you wire it into your own pipeline: pre-commit hooks, GitHub Actions, GitLab CI, or whatever runner you already use. The included .secrets.baseline workflow lets large legacy codebases adopt scanning without flagging every historical false positive on day one.

detect-secrets in practice: examples

Three workflows cover most real adoptions:

Initial baseline on an existing repo. Run detect-secrets scan > .secrets.baseline from the repo root, then commit the file. The first run accepts every existing finding; from this point forward only new secrets break the build. I usually pair this with detect-secrets audit .secrets.baseline immediately after, walking each finding to mark it true or false positive. The audit labels persist across re-scans, so the baseline doubles as a tracking spreadsheet for remediation work.

CI scan that fails on a new finding. Add detect-secrets-hook --baseline .secrets.baseline $(git diff --name-only HEAD~1) to the CI pipeline. On a PR that introduces a new AWS key, the hook exits non-zero and the build fails before merge. Existing baseline secrets pass through silently β€” no false-positive flood from the historical state.

Audit-baseline triage. When the team is ready to clean up the baseline, detect-secrets audit --diff old.baseline new.baseline shows exactly what changed between two points in time. This is how I track remediation progress quarter over quarter without rebuilding the baseline from scratch.

When to use detect-secrets

detect-secrets fits best in enterprise environments with legacy codebases that already contain secrets. The baseline approach lets you prevent new leaks immediately while remediating old ones on your own schedule.

It’s a good pick if your team needs an audit trail of reviewed secrets, works in a regulated environment, or runs large monorepos where scanning speed matters.

For broader scanning beyond git repositories (Slack, S3, Docker images), look at TruffleHog. For simpler git-only scanning without baseline management, Gitleaks is a lighter option.

Best for
Enterprise teams with existing codebases that need to prevent new secret leaks immediately while remediating historical issues on a managed timeline.

Frequently Asked Questions

What is detect-secrets?
detect-secrets is Yelp’s open-source secret scanning tool that uses a baseline file to distinguish between existing secrets (accepted) and new secrets (blocked). This enterprise-friendly approach prevents new secret leaks while allowing teams to remediate historical issues on their own timeline.
How does the baseline work?
The baseline is a JSON file containing hashes of all secrets found in your repository at a specific point in time. When detect-secrets runs, it compares current scans against the baseline. Secrets already in the baseline are allowed; new secrets trigger failures. This lets you adopt the tool without fixing every historical secret first.
Why choose detect-secrets over Gitleaks or TruffleHog?
detect-secrets excels in enterprise environments with legacy codebases containing many existing secrets. The baseline approach lets you prevent new leaks immediately while gradually remediating old ones. Gitleaks and TruffleHog report all secrets, requiring upfront fixes or extensive allowlist configuration.
Is detect-secrets actively maintained?
Yes, detect-secrets is maintained by Yelp and continues to receive updates. As an established tool used in production at Yelp, it focuses on stability and reliability rather than frequent feature additions.