Expand description
Deterministic secret detection and redaction core.
This crate is the canonical implementation that every language binding
translates to (decision-adopt-rust-core-monorepo). It uses std but is
side-effect free by policy:
- no runtime network access,
- no filesystem access,
- no process-environment lookup,
- no telemetry or logging sinks,
- no secret storage,
- no user interface.
The crate-level lints below make the policy visible at compile time, and
scripts/check-rust-workspace.py rejects dependencies that would breach it.
Ranges reported by this crate use UTF-8 byte offsets; each binding converts
them to its documented native unit (decision-define-runtime-bindings).
§Pipeline contract
run_detector_pipeline runs every detector in a DetectorRegistry
in registration order, validates each Candidate, resolves overlapping
candidates with the documented precedence (resolved-action severity,
specificity, confidence, narrower span, registration order, emission
order), and numbers the
disjoint survivors by input offset. scan then evaluates a Policy
once per finding. Identical input and configuration always produce
identical findings and ids.
Every failure is a SecretScanError with a fixed code and message and
no payload; no public value carries an input fragment or a matched value.
redact then applies Finding actions to the input in one ordered
pass, replacing redact/block ranges with placeholders from a
PlaceholderFormatter and validating that formatter’s output.
scan_and_redact runs both and returns a ScanResult.
scan, redact, and scan_and_redact apply a default
WholeInputLimits before doing any work — DEFAULT_MAX_INPUT_BYTES
and DEFAULT_MAX_FINDINGS — and fail with
SecretScanErrorCode::InputLimitExceeded or
SecretScanErrorCode::FindingLimitExceeded rather than truncating.
scan_with_limits, redact_with_limits, and
scan_and_redact_with_limits accept an explicit WholeInputLimits
instead (decision-bound-whole-input-operations-by-default).
§Public surface
That table is the whole surface — it lists every name this crate root
exports, and [workspace.metadata.redact-secret] core-public-api in the
workspace manifest repeats it so a name cannot join or leave without a
reviewed manifest change. Everything else is private. In particular, the
built-in detector set of each profile is reached only through
DetectorRegistry::with_built_in (full) and
DetectorRegistry::with_common_built_in (common), and the retention
tuning the incremental session depends on is derived through
IncrementalLimits::minimum_buffered_bytes rather than exposed as a
constant, so both can change without breaking a caller.
decision-define-detector-profile-and-pack-contract fixes which built-in
detectors each Profile holds and its compatibility class.
§Examples
The minimal path redacts with the supported defaults (full profile,
DefaultPolicy, default_placeholder_formatter, default
WholeInputLimits) in one call:
let result = redact_secret::sanitize("API_KEY=ghp_SYNTHETICREVOKED00000000000000000000")?;
assert_eq!(result.text(), "API_KEY=<SECRET_1>");Custom detectors, PII activation, a custom policy or formatter, explicit
limits, and registry reuse use the advanced path, scan_and_redact:
use redact_secret::{
DefaultPolicy, DetectorRegistry, default_placeholder_formatter, scan_and_redact,
};
let registry = DetectorRegistry::with_built_in([])?;
let input = "API_KEY=ghp_SYNTHETICREVOKED00000000000000000000\nplain text";
let result = scan_and_redact(input, ®istry, &DefaultPolicy, &default_placeholder_formatter)?;
assert_eq!(result.text(), "API_KEY=<SECRET_1>\nplain text");
// Ranges index the original input, in UTF-8 bytes.
let range = result.findings()[0].range();
assert_eq!(&input[range.start()..range.end()], "ghp_SYNTHETICREVOKED00000000000000000000");§Incremental sanitization contract
IncrementalSanitizer runs the same built-in detectors, default
policy, and redaction over text supplied in chunks. It is a bounded,
four-state session (accepting, finalized, aborted, failed) that
emits only text whose detection window is closed, never rescans
finalized input, and accepts input independently of how a caller
partitions it into chunks. See the module documentation for the full
contract.
The Rust core and the top-level conformance corpus are the canonical source
of behavior. Bindings translate host values and range units without
reimplementing detection (decision-govern-cross-language-conformance).
Modules§
- composition
- Static custom composition (issue #1253,
decision-define-the-configuration-capability-ceiling-runtime-ownership-and-surface-support).
Structs§
- Action
Comparison - The result of
compare_action_policies. - Action
Counts - How many findings a policy assigned to each action.
- Action
Decision - One policy’s decision for one finding.
- Action
Policy - A parsed, validated, immutable action policy.
- Action
Policy Error - A rejected action policy document, returned by
load_action_policy. - Artifact
Manifest - What one artifact contains and supports, generated from its real
composition (
artifact-manifest/v1). - Built
InRegistry - A built-in-only detector registry that is
Send + Sync, so one value can be shared by reference or through anArcacross threads (issue #1178). - Byte
Range - A non-empty half-open range
[start, end)of UTF-8 byte offsets. - Candidate
- A detector’s private proposal: classification and range only.
- Compared
Finding - One finalized finding and every compared policy’s decision for it.
- Compared
Side - One compared policy: its revision binding and its action totals.
- Config
Diagnostic - One safe finding about a configuration input (
config-diagnostics/v1). - Config
Request - What to resolve: explicit runtime input over the artifact’s defaults.
- Config
Resolution - The result of
resolve_config(config-resolution/v1): the snapshot when the input is valid, and every safe diagnostic either way. - Config
Snapshot - The resolved, effective configuration (
config-snapshot/v1): immutable data. It is not a handle and cannot scan. - Configuration
Comparison - The result of
compare_configurations. - Configuration
Difference - One difference between the base side and another.
- Configuration
Differences - The differences of one side against the base side, on this input only.
- Configuration
Result - One side of a
ConfigurationComparison. - Configuration
Side - One configuration taking part in a comparison: a registry (or the reason it could not be built), the policy evaluated over its findings, its limits and the identity digests of the configuration it was built from.
- Default
Policy - The default
Policy: deterministic, infallible, and independent ofPolicyContext. - Detected
Finding - A finding after overlap resolution and before policy evaluation.
- Detection
Config Error - Why a detector selection was rejected: a fixed class and, for a problem in one id, that id’s zero-based position in its array.
- Detection
Identity - The detection configuration the single pass ran under, identified apart from every policy.
- Detection
Selection - Which of an artifact’s included built-in detectors are enabled
(
detectionofruntime-config/v1). - Detector
Context - Read-only information a detector receives alongside the input.
- Detector
Failure - Opaque failure reported by a
Detector. - Detector
Registry - An ordered, duplicate-free set of detectors.
- Finding
- The public, immutable result of scanning: safe metadata plus the action.
- Formatter
Failure - Opaque failure reported by a
PlaceholderFormatter. - Incremental
Limits - Explicit, positive byte limits every incremental session requires. There are no environment-derived or silent defaults.
- Incremental
Policy Context - Position information an incremental policy receives.
- Incremental
Sanitizer - A bounded, side-effect-free incremental sanitizer session over built-in detectors. Custom detectors are not accepted: each has no retention declaration, so the session cannot bound what it must hold open.
- PiiSelection
- A canonical, closed PII selector set for the loaded artifact.
- Placeholder
Context - Position information a placeholder formatter receives.
- Policy
Context - Position information a whole-input policy receives.
- Policy
Failure - Opaque failure reported by a
Policy. - Registered
Detector - A detector together with the id captured at registration time.
- Ruleset
Error - A rejected ruleset, returned by
load_ruleset. - Sample
Rule Hits - How often each rule of one policy was the deciding rule across a set of sample findings.
- Scan
Result - Sanitized text paired with the findings that produced it.
- Secret
Scan Error - A sanitized scan error. It holds nothing but its code.
- Whole
Input Limits - Explicit byte and finding-count bounds a whole-input operation checks before doing detection work.
Enums§
- Action
- The enforcement decision a policy attaches to a finding.
- Action
Policy Error Class - The fixed rejection class of a rejected action policy document.
- Artifact
Kind - The kind of artifact a manifest describes: the build target class.
- Artifact
Manifest Error - Why a manifest could not be generated or did not match its artifact.
- Compared
Policy - One policy taking part in a comparison.
- Confidence
- How strongly a detector believes a candidate is a credential.
- Config
Severity - How serious a
ConfigDiagnosticis. - Correspondence
- How sure the pairing of an entry’s findings is.
- Decision
Basis - Why a policy chose an action for one finding.
- Difference
Kind - How one entry of a difference list relates the two sides.
- Obfuscation
- Whether a finding’s reported range shows evidence of invisible-character obfuscation.
- Policy
Binding - What identifies a compared policy: the revision binding.
- Profile
- A named, reviewed built-in detector composition
(
decision-define-detector-profile-and-pack-contract). - Ruleset
Error Class - The public, fixed rejection class of a rejected ruleset (issue #495,
decision-define-declarative-detector-ruleset-contract’s “Closed validator enum” and “Fail-closed loading rule” sections). - Secret
Scan Error Code - Fixed public error codes.
- Session
State - The terminally distinct lifecycle states of an
IncrementalSanitizer. - Side
Status - Whether a side produced findings.
- Specificity
- The evidence class a detector claims for a candidate. This is the first key of overlap resolution.
Constants§
- DEFAULT_
MAX_ FINDINGS - The default
max_findings: 50,000. Sized so every legitimate workload and every fixture in the conformance corpus stays well under it, while still being a real, reachable ceiling for a deliberately dense-packed adversarial input well before that input reachesDEFAULT_MAX_INPUT_BYTES— a second, independent bound, not a restatement of the byte bound (decision-bound-whole-input-operations-by-default). - DEFAULT_
MAX_ INPUT_ BYTES - The default
max_input_bytes: 64 MiB, the same boundcrates/secret-scan-clialready declares for a whole file or a streamed total input, so the product has one whole-input bound rather than two. - MAX_
ACTION_ POLICY_ BYTES - The largest action policy document, in bytes. A longer document is rejected
with
ActionPolicyErrorClass::ActionPolicyTooLargebefore any byte of it is parsed. A host that reads a file bounds its read by this value plus one. - MAX_
COMPARED_ POLICIES - The most policies one comparison accepts (a baseline and three candidates).
- MAX_
IDENTIFIER_ LENGTH - Maximum length in bytes of a public identifier (
type, detector id, finding id). - MAX_
PLACEHOLDER_ LENGTH - Maximum length in bytes of a placeholder a
PlaceholderFormattermay return. - RANGE_
UNIT - The string-index unit used by every range this crate reports.
- VERSION
- The shared product version. Every crate, binding, and package in the
workspace reports the same version (
decision-release-bindings-in-lockstep).
Traits§
- Detector
- An independent detection unit.
- Incremental
Policy - Maps a finalized finding to an
Actionwithin an incremental session. - Placeholder
Formatter - Produces the replacement text for a replaced finding.
- Policy
- Maps finalized safe metadata to an
Action.
Functions§
- compare_
action_ policies - Runs detection once over
inputand evaluates every policy inpolicieson the same finalized findings, under the defaultWholeInputLimits. - compare_
action_ policies_ with_ limits - Same as
compare_action_policies, againstlimitsinstead of the defaultWholeInputLimits. - compare_
configurations - Runs one independent detection pass per side over
inputand relates every side to the first. See the module documentation (configuration_compare). - default_
placeholder_ formatter - The default formatter:
<SECRET_N>,None-based among replaced findings. - describe_
config - Describes the configuration a registry is fixed to: its enabled built-in detectors, PII selection and the artifact’s defaults for everything a call supplies. Input-free: it reads no scan input, builds nothing and does not change the registry.
- is_
identifier - Returns
truewhenvaluematches^[a-z][a-z0-9]*([._-][a-z0-9]+)*$and is at mostMAX_IDENTIFIER_LENGTHbytes. - load_
action_ policy - Parses
bytesas an action policy document (actionPolicyRevision: 1) and returns the whole validatedActionPolicy, or rejects the whole document. - load_
ruleset - Parses
bytesas a declarative ruleset and returns one registrableDetectorper validateddetector:block, in the ruleset’s own declaration order (decision-define-declarative-detector-ruleset-contract). - redact
- Reconstructs
inputin one ordered pass:warnandallowfindings pass their span through unchanged;redactandblockfindings have their span replaced byformatter’s output. - redact_
with_ limits - Same as
redact, againstlimitsinstead of the defaultWholeInputLimits. - resolve_
config - Resolves explicit runtime input over
manifest’s build defaults into an immutableConfigSnapshot, with no hidden concatenation and no silent fallback. - run_
detector_ pipeline - Runs every registered detector over
input, validates each candidate, resolves overlaps with the documented precedence, and returns the surviving findings ordered by input offset with idsfinding-1,finding-2, and so on. - sanitize
- Redacts
inputwith the supported defaults, in one call. - sanitize_
with_ profile - Same as
sanitize, for the built-in detectors ofprofile. - scan
- Runs the detector pipeline and evaluates
policyonce per finding. - scan_
and_ redact - Scans
inputand redacts it in one call, returning the sanitized text and the findings that produced it. - scan_
and_ redact_ with_ limits - Same as
scan_and_redact, againstlimitsinstead of the defaultWholeInputLimits. - scan_
with_ limits - Same as
scan, againstlimitsinstead of the defaultWholeInputLimits. - shannon_
entropy - Returns Shannon entropy in bits per Unicode scalar value (
char). - typed_
placeholder_ formatter - A formatter that names the finding type:
<TYPE_NAME_N>, upper-cased with.and-mapped to_.
Type Aliases§
- Incremental
Result - The sanitized text and final findings produced by one
appendorfinalizecall.