Documentation
¶
Overview ¶
Package redact holds a per-run, append-only registry of secret values and masks them, and their predictable encoded variants, out of text before it is printed, logged, or written to a report.
One Registry is created per run. Add is called whenever a secret value becomes known (a captured header, a --variable, a field marked to be redacted); it never forgets a value, so a secret captured early in a run stays masked even after a later capture overwrites the name that held it. Redact and RedactBytes replace the raw value, and for each value its base64 (standard and URL-safe, padded and unpadded), URL-escaped (query and path), and JSON-escaped (with and without HTML escaping) forms, with Mask. Every occurrence of every pattern is found and overlapping or adjacent occurrences are masked as one, so no part of a secret survives even when secrets overlap or contain each other.
A Registry is safe for concurrent use: Add, Redact and the other methods may be called from multiple goroutines at once.
Index ¶
Constants ¶
const Mask = "***"
Mask replaces every matched occurrence of a registered secret.
const MinLength = 4
MinLength is the rune length below which Add reports a newly registered value as short, so the caller can warn that a short secret is prone to matching text it was never meant to redact. Short secrets are still redacted; the warning is the caller's responsibility.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry is a per-run, append-only store of secret values to mask out of text. See the package doc for what is matched and the concurrency guarantee. The zero value is not guaranteed usable; use New.
func (*Registry) Add ¶
Add registers value under name. The empty string is never registered (Redact never masks ""), and re-registering a value already known to the registry is a no-op. Every other value, once added, stays masked for the life of the Registry, even after name is given a different value.
short reports whether value was newly registered and is shorter than MinLength runes; the caller may want to warn about that, since short secrets are prone to matching unrelated text. value is redacted either way.
func (*Registry) Redact ¶
Redact returns s with every occurrence of every registered secret value, and its encoded variants, replaced by Mask. s is returned unchanged, and without allocating, if nothing matches.
func (*Registry) RedactBytes ¶
RedactBytes is Redact for a byte slice.
func (*Registry) RedactWith ¶
RedactWith is Redact over the secrets of r and of extra together, in one pass, so that overlapping secrets of the two registries are masked as one. extra may be nil.