secrets-scanner
A high-performance Rust library and CLI for detecting leaked secrets in source code, configuration files, and pipelines.

Features
- Fast multi-stage scanning: Uses a
memchr prefilter, case-insensitive Aho-Corasick matching, entropy gating, and Rust regex validation to minimize CPU overhead.
- Gitleaks-compatible TOML rules: Loads rules from a gitleaks-style TOML configuration. Supports custom rules via
--rules or SECRETS_SCANNER_RULES.
- Manifest-driven bundled rules: Combines local, gitleaks, and kingfisher rulesets at compile time, validated and deduped by priority.
- Safe-by-default scanning: Redacts matched secrets, rejects symlinks, uses bounded file reads, and automatically skips binary files.
- Git-aware scanning: Scan git-tracked files (
--git-tracked), changed files (--changed-files / --base), full history patches (--git-history, finds secrets committed then removed), staged index blobs (--staged), or untracked files (--include-untracked). Explicit git modes fail closed on git error (opt back in with --git-fallback=walk).
- CI-friendly output: Exports to text, JSON, JSONL, and SARIF formats. Supports suppressions, baselines, and scan scope limits.
- CLI and automation: Complete CLI toolset with completions, GitHub Action, pre-commit hook, Docker image, and Homebrew cask packaging.
- Rust, Node.js, and WASM libraries: Use the Rust crate directly, install the native Node.js binding package
@whit3rabbit/rsecrets-scanner, or use the browser/edge WASM package @whit3rabbit/rsecrets-scanner-wasm.
- Optional runtime updates: Download and update rule configurations dynamically to the OS user-data directory via the
--features updater build.
- Developer tooling: Includes built-in rule validation, merge check validation, duplicate-rule detectors, benchmarks, and fuzz targets.
Quick Start
1. Install
macOS / Linux (Shell)
curl -fsSL https://raw.githubusercontent.com/whit3rabbit/secrets-scanner/main/install.sh | bash
macOS (Homebrew Cask)
brew install --cask whit3rabbit/tap/secrets-scanner
Windows (PowerShell)
irm https://raw.githubusercontent.com/whit3rabbit/secrets-scanner/main/install.ps1 | iex
(For other installation methods like Homebrew Cask or Cargo, see Installation Options below).
2. Run a Scan
Once installed and in your PATH, run secrets-scanner directly:
# Scan the current directory
secrets-scanner scan .
# Scan specific paths
secrets-scanner scan src/ config/ .env
# Output as JSON
secrets-scanner scan --format json . > findings.json
# Output as SARIF for GitHub Code Scanning
secrets-scanner scan --format sarif . > results.sarif
3. Use as a Library
Add the crate to your Cargo.toml:
[dependencies]
secrets-scanner = "0.1.0"
Scanner::new() loads rules in priority order (SECRETS_SCANNER_RULES env → cached
in user-data → bundled fallback). Every snippet below is a complete body for a
function returning Result<_, Box<dyn std::error::Error>>.
Scan a directory tree (parallel)
use secrets_scanner::Scanner;
let scanner = Scanner::new()?;
for f in scanner.scan_path("./src") {
println!("{}:{} [{}] {}", f.file, f.line, f.rule_id, f.matched);
}
Redact secrets from in-memory content
use secrets_scanner::Scanner;
let scanner = Scanner::new()?;
let out = scanner.scan_and_redact_content("config.env", "STRIPE_KEY=sk_live_51abc...");
if out.has_findings() {
println!("{}", out.redacted); // safe to log/forward
}
Filter untrusted LLM / proxy traffic (hardened)
scan_proxy is fail-closed: oversized input returns ProxyError::InputTooLarge,
and a non-hardened config returns ProxyError::NotHardened. ScanConfig::proxy()
enforces redaction, disables allow-markers, and caps findings/matched length.
use secrets_scanner::{ScanConfig, Scanner};
let scanner = Scanner::from_bundled()?.with_config(ScanConfig::proxy());
let out = scanner.scan_proxy(payload)?; // payload: &[u8]
// Forward out.redacted instead of the raw input.
Load your own rules
from_file / from_toml fail loudly (ScannerError::InvalidRules) on a duplicate
id or uncompilable regex, rather than silently scanning with fewer rules.
use secrets_scanner::{Scanner, ScannerError};
let toml = r#"
[[rules]]
id = "acme-api-key"
regex = 'ACME_[A-Za-z0-9]{32}'
keywords = ["acme_"]
entropy = 3.5
"#;
match Scanner::from_toml(toml) {
Ok(scanner) => { scanner.scan_path("./src"); }
Err(ScannerError::InvalidRules(issues)) => issues.iter().for_each(|i| eprintln!("{i}")),
Err(e) => return Err(e.into()),
}
Tune scan behavior