redact

package
v1.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

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

View Source
const Mask = "***"

Mask replaces every matched occurrence of a registered secret.

View Source
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 New

func New() *Registry

New returns an empty Registry ready for concurrent use.

func (*Registry) Add

func (r *Registry) Add(name, value string) (short bool)

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) Len

func (r *Registry) Len() int

Len returns the number of distinct raw secret values registered so far.

func (*Registry) Redact

func (r *Registry) Redact(s string) string

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

func (r *Registry) RedactBytes(b []byte) []byte

RedactBytes is Redact for a byte slice.

func (*Registry) RedactWith

func (r *Registry) RedactWith(s string, extra *Registry) string

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.

func (*Registry) Values

func (r *Registry) Values() []string

Values returns a sorted copy of every distinct raw secret value registered so far. It is meant for run-level sinks (reports, logs) written once the run has finished.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL