Skip to content
Home SAST Tools detect-secrets
detect-secrets

detect-secrets

Category: SAST
License: Free (Open-Source, Apache-2.0)
Suphi Cankurt
Suphi Cankurt
AppSec Enthusiast
Updated February 12, 2026
4 min read
0 Comments

detect-secrets is Yelp’s enterprise-friendly secret scanner that uses a baseline approach to prevent new credential leaks. 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.

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

Key features

Feature Details
Built-in detectors 27 plugins covering AWS, GitHub, GitLab, Slack, Stripe, Twilio, Discord, and more
Detection strategies Regex-based rules, Base64/Hex entropy analysis, keyword matching
Entropy thresholds Base64 default 4.5, Hex default 3.0 (configurable 0.0–8.0)
CLI commands scan, audit, detect-secrets-hook
Output format JSON baseline file (.secrets.baseline)
Installation pip, Homebrew, or from source
License Apache-2.0
Verification Optional 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.

Category Detectors
Cloud providers AWSKeyDetector, AzureStorageKeyDetector, IbmCloudIamDetector, IbmCosHmacDetector, CloudantDetector, SoftlayerDetector
Code platforms GitHubTokenDetector, GitLabTokenDetector, NpmDetector, PypiTokenDetector
Communication SlackDetector, DiscordBotTokenDetector, TelegramBotTokenDetector, MailchimpDetector, SendGridDetector, TwilioKeyDetector
Payment/SaaS StripeDetector, SquareOAuthDetector, ArtifactoryDetector, OpenAIDetector
General PrivateKeyDetector, BasicAuthDetector, JwtTokenDetector, KeywordDetector, IPPublicDetector
Entropy Base64HighEntropyString, 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. 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.

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.
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.

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.

Complement with SCA

Pair static analysis with dependency scanning for broader coverage.

See all SCA tools

Comments

Powered by Giscus — comments are stored in GitHub Discussions.