Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
kingfisher-scanner
Embeddable, synchronous secret detection for Rust 1.99+. The 1.x public Rust API
follows semantic versioning; breaking changes require a new major version.
[]
= "1.2.0"
= "1"
Quick start
Load and compile once, then reuse the scanner. Scanning does not contact providers, validate credentials, revoke credentials, or initialize an async runtime.
use Arc;
use ;
Custom rules and configuration
use Arc;
use ;
let rule = new;
let database = new;
let scanner = with_config;
let findings = scanner.scan_bytes?;
assert_eq!;
assert_eq!;
# Ok::
Use scan_file(path)?, scan_blob(&blob)?, or scan_blob_at_path(&blob, source_path)?
when scanning files or applying path-aware rules. Errors propagate; an empty successful
result means no findings for that call, subject to configured filters and deduplication.
For an optional per-call deadline or cancellation signal, use ScanControl with
scan_bytes_with_control, scan_file_with_control, or scan_blob_at_path_with_control:
#
Interruption returns an error containing ScanAborted::TimedOut or
ScanAborted::Cancelled, without partial results or a dedup-cache entry.
Cancellation tokens remain cancelled; create a fresh token for new work. Checks
run between matching/filtering operations, in native match callbacks, and during
Base64 enumeration. Individual native operations, file reads, decoding and rule
compilation cannot be preempted. Use process isolation when a hard wall-clock
limit is required. Existing scan methods remain unlimited.
Scanner and RulesDatabase are Send + Sync. Share a scanner with Arc across worker
threads. Each thread gets its own native scratch space. In async applications, schedule
CPU-bound scanning on blocking workers. Callbacks into ScannerPool::try_with must not
recursively borrow the same pool on the same thread; this returns an error.
The CLI matcher and rule-filter helpers use the same pool implementation. Existing
pool import paths remain compatible. The pool retains its database until all
thread-local scanners have been dropped, and its callback cannot return a scanner
borrowing that database. Fallible callbacks return a nested Result; handle both
the pool error and the callback error. The compatibility with method panics on
scratch allocation or reentrant borrowing errors; prefer try_with.
Behavior contract
- Defaults: Base64 detection enabled (one decoding layer), redaction disabled, cross-call deduplication disabled, rule-defined entropy thresholds.
enable_dedupsuppresses previously reported content at the same source path. Concurrent first scans may both return findings. This cache grows untilreset_dedup()or scanner drop; leave it disabled for independent requests.- UTF-16/32 content is normalized to UTF-8. Offsets and byte columns refer to the normalized content, with zero-based offsets/columns and one-based lines. Base64 locations cover the encoded region, not the decoded secret's byte position.
redact_secretsreplaces the secret and every returned capture value with[REDACTED]. Fingerprints are computed before redaction. This does not zeroize caller-owned input or turn findings into non-sensitive data.- Results may include invisible component helpers. Filter with
finding.rule().visible()for user-facing reports. - Finding order, numeric fingerprints, native cache formats, and built-in detector contents are not persistent storage contracts. Catalog updates may change findings.
- The detector applies candidate rules, filters, entropy, and component requirements. It is not the CLI's complete repository traversal, reporting, or live validation pipeline.
Optional validation
Validation is disabled by default. Enable all supported validators and revocation:
= { = "1.2.0", = ["validation"] }
validation enables every supported family and its dependencies. Legacy
validation-* feature names remain compatibility aliases that enable the same
complete feature. Enabling validation does not make Scanner perform network
requests automatically.
Validation clients and runtime lifecycles are managed by the embedding application.
Vectorscan is a native dependency. Its build may download a platform archive;
compiling the embedded rule catalog does not download rules. For offline builds,
prepare VECTORSCAN_PREBUILT_DIR or HYPERSCAN_ROOT and set VECTORSCAN_OFFLINE=1.
See the repository's library guide
for versioning, deployment, and migration details.
Scan and validate
Enable validation for the high-level API and all supported families. Keep raw findings until validation
finishes and pass the full result set so hidden supporting credentials are available.
#
# async
For one independent finding, use validator.validate_finding(&finding).await.
For one finding with supporting credentials, use
validate_finding_with_context(&finding, &same_input_findings).
ValidatedFinding pairs the original finding with its outcome, optional reason,
and HTTP status. Its debug output omits credentials; it deliberately does not
implement serialization. into_redacted() redacts secret and capture values.
Validators are cloneable and share their concurrency limit. Defaults use strict
TLS, no redirects, and block internal addresses. Inject an HTTP client with
client(...), trusted endpoint variables with variable(...), and opt into local
services with allow_internal_ips(true). SDK/database/gRPC transports retain their
own clients; the outer deadline applies to all families. See the library guide for
association rules and outcome semantics.
Inspect rules and configured actions
RulesDatabase::rules() exposes the loaded catalog and each rule's serializable
RuleSyntax. Inspection works without the validation feature and makes no
provider requests:
use ;
let database = from_rule_collection?;
for rule in database.rules.iter.filter
let = database.rules.iter.enumerate
.find
.ok_or_else?;
println!;
println!;
println!;
println!;
# Ok::
Add serde_json = "1" when copying this into your project. The compiled regex
has rule comments removed; the historical anchored_regexes() name does not
mean these patterns are endpoint-constrained. Regex matches are candidates and
still pass capture selection, entropy, filters and dependency checks.
RuleSyntax also includes path predicates, pattern requirements, examples,
references and dependency bindings. HTTP/gRPC definitions expose configured
requests and matchers; Betterleaks exposes an expression tree. Typed/raw handlers
show their dispatch type/name rather than their Rust implementation code. Original
Betterleaks expression text may be absent in release builds. Missing actions
serialize as null; configuration presence does not prove an action will succeed.
The packaged inspection example lists summaries, filters by ID prefix or action support, and prints full or selected details:
Use repeated --rules-path PATH to add custom YAML/TOML rules and --no-builtins
to inspect only your custom catalog. Output contains rule configuration, including
custom literals, rather than redacted findings. See --help for all options.
Runnable examples
From the repository checkout:
The packaged scan_content example is also available
in the crate source.
Scan a real file with the built-in catalog, or exercise explicitly enabled local validation:
These examples avoid network validation and print no unredacted secrets.
More complete integrations (all included in the crate source):
| Example | Demonstrates |
|---|---|
inspect_rules |
Catalog summaries, exact definitions, regexes, filters, validation/revocation configurations |
scan_files |
File batches, path-aware detection, JSON Lines reports without credentials |
scan_custom_rules |
Load private YAML/TOML rules and scan a file |
scan_async |
Shared scanner, Tokio blocking workers, bounded concurrency |
http_validation |
Scan and validate against a loopback mock with Validator |
validate_file |
Scan a file with built-ins and validate against actual providers |
The HTTP example uses a local mock with synthetic credentials. It checks active,
rejected, rate-limited, and unexpected-success responses without contacting a provider.
Keep raw findings until validation finishes, then report only selected metadata;
redact_secrets: true before validation replaces the token the validator needs.
Use Validator to dispatch enabled rule families and bind supporting credentials.
It uses the same validation::ValidationEngine as CLI scans and direct validate.
The engine owns protocol dispatch and outcome classification; applications own input
association, concurrency, and reporting. Advanced callers with resolved Liquid globals
can call the engine directly. Its ValidationResult::response_body may contain
credentials and is omitted from Debug output. Prefer the high-level finding API for
ordinary integrations. .retries(n) enables YAML HTTP retries within the total deadline.
.timeout(Duration::ZERO) disables Kingfisher validation timeouts, and
.max_response_bytes(0) disables YAML HTTP, Betterleaks, and gRPC response caps.
Injected HTTP clients retain their own timeout settings; concurrency remains bounded.
Disabled features, missing or ambiguous components, redacted inputs, and timeouts
produce explicit outcomes and credential-free reasons.
See the integration recipes for copyable dependency manifests and instructions for adapting each example.
Credential revocation
With validation, Revoker provides explicit rule-driven revocation without
CLI dependencies:
#
#
Pass required companion variables and endpoint overrides in the map; TOKEN is
reserved for the secret argument. HTTP and multi-step rules are supported, with
AWS and GCP included in validation. The default client uses
strict TLS and disables redirects. Calls have a 10-second total deadline and no
automatic HTTP retries; AWS retains its provider-specific retry policy. Customize with Revoker::with_client and Revoker::timeout.
Callers own authorization and endpoint policy; internal HTTP addresses are allowed.
A timeout may occur after a credential was revoked. Scanning and validation never
invoke revocation. Provider responses and errors may contain secrets.
See examples/revoke.rs for a runnable example.
Shared revocation execution
With validation, validation::revocation exposes the HTTP and multi-step
revocation helpers used by the CLI and Python SDK. These low-level async helpers
require an explicit rule configuration, resolved Liquid globals, client, parser,
timeout and retry count. Callers own authorization, endpoint policy and the total
deadline; use a client with redirects disabled and zero retries for destructive
operations. AWS and GCP helpers are included in the same feature.