redact

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package redact finds secrets in text and replaces them with markers. It is used by seeders, which report where a secret is but never its value, and by the provider wrapper, which redacts everything sent to a model.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alias added in v0.2.1

func Alias(file, other string)

Alias makes the values remembered for file also apply under other, a second path to the same file (a symbolic link and its target).

func Hash

func Hash(value string) string

Hash returns the 8 hex digit fingerprint used in markers and matches. It is keyed with a random value made when the process starts and kept only in memory, so the same secret gets the same marker within a run, which is all a reader needs to tell two secrets apart, but a marker cannot be checked against guesses offline, nor linked to the same secret in another run or repository.

func IsPlaceholder

func IsPlaceholder(v string) bool

IsPlaceholder is isPlaceholder for seeders that find secret-looking values by structure and need the same notion of "obviously not real".

func KeepLines added in v0.2.0

func KeepLines(text string) string

KeepLines is Apply that keeps every line where it was: a secret that spans lines is replaced by its marker followed by the same number of newlines.

func KeepLinesIn added in v0.2.1

func KeepLinesIn(file, text string) string

KeepLinesIn is KeepLines for the content of file: values remembered for that file are replaced too.

func Marker

func Marker(rule, hash string) string

Marker returns the replacement text for a secret found by rule whose value hashes to hash. Seeders that redact a value they located by structure (a YAML node, an ENV instruction) use it so every redaction in Spackle looks the same and is skipped by a later Apply.

func Mask added in v0.2.0

func Mask(text string) string

Mask is Apply with markers that carry no hash, "[REDACTED:<rule>]". It is for text compared across runs, such as the lines a finding's fingerprint is made from, where the keyed hash would differ every run.

func Remember added in v0.2.1

func Remember(file, value string)

Remember registers a credential value found by structure in file (the path relative to the target root), so MatchesIn, ApplyIn and KeepLinesIn redact it in that file, and every function redacts it everywhere when it is token-like. The value as the check decoded it may not appear byte for byte (a multi-line YAML scalar, a Dockerfile continuation, an escaped quote), so its pieces are kept too. Pieces under 4 bytes are ignored.

func Rules

func Rules() []string

Rules returns the rule names, sorted.

Types

type Match

type Match struct {
	Rule  string // rule name, see Rules
	Start int    // byte offset of the secret in the scanned text
	End   int    // byte offset just past the secret
	Line  int    // 1-based line of Start
	Hash  string // 8 hex digits of a keyed hash of the value, see Hash
}

Match is one secret found in a text. It deliberately has no field for the value: the hash is enough to tell two secrets apart and to recognize the same secret in two places without ever storing it.

func Apply

func Apply(text string) (string, []Match)

Apply replaces each secret in text with "[REDACTED:<rule>:<hash>]" and returns the new text with the matches, whose offsets refer to the input.

func ApplyIn added in v0.2.1

func ApplyIn(file, text string) (string, []Match)

ApplyIn is Apply for the content of file: values remembered for that file are replaced too.

func Matches added in v0.2.0

func Matches(text string) []Match

Matches is Scan for redaction: the matches Apply and KeepLines replace. It also holds the redaction-only rules and values that Scan leaves out as placeholders or low-entropy strings.

func MatchesIn added in v0.2.1

func MatchesIn(file, text string) []Match

MatchesIn is Matches for the content of file, and also finds the values remembered for that file (see Remember).

func Scan

func Scan(text string) []Match

Scan returns the secrets in text, sorted by Start and non-overlapping. When candidates overlap, the one that starts earliest wins, then the longest, then the more specific rule.

Jump to

Keyboard shortcuts

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