redact

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package redact provides a string type for secrets that refuses to reveal itself in logs, errors, JSON/YAML, or fmt output. Wrap every credential field in Secret so an accidental %v, slog attribute, or config dump prints the placeholder instead of the secret. Call Reveal only at the exact point the secret is used.

Index

Constants

View Source
const Placeholder = "[REDACTED]"

Placeholder is what a redacted secret renders as in any output.

Variables

This section is empty.

Functions

This section is empty.

Types

type Secret

type Secret string

Secret is a string whose value never appears in formatted output.

func (Secret) Format added in v0.1.10

func (s Secret) Format(f fmt.State, verb rune)

Format implements fmt.Formatter so every verb renders the placeholder. Without it, a mismatched verb such as %d takes fmt's bad-verb path, which deliberately suppresses String (to avoid recursing while erroring) and prints the raw underlying value — so one wrong verb in an error wrap printed the secret. Found by FuzzSecretNeverLeaks.

The residual gap: %p applied to a Secret value (not a *Secret) is special-cased by fmt before any interface lookup, still reaches the bad-verb path, and no method can intercept it. vet is silent too, because a Formatter is assumed to handle any verb.

func (Secret) GoString

func (s Secret) GoString() string

func (Secret) IsZero

func (s Secret) IsZero() bool

IsZero reports whether the secret is empty.

func (Secret) LogValue

func (s Secret) LogValue() slog.Value

LogValue implements slog.LogValuer so structured logs never capture the secret.

func (Secret) MarshalJSON

func (s Secret) MarshalJSON() ([]byte, error)

MarshalJSON ensures JSON encoders emit the placeholder.

func (Secret) MarshalText

func (s Secret) MarshalText() ([]byte, error)

MarshalText covers fmt and any encoding that honors encoding.TextMarshaler.

func (Secret) MarshalYAML

func (s Secret) MarshalYAML() (any, error)

MarshalYAML ensures yaml.v3 encoders emit the placeholder.

func (Secret) Reveal

func (s Secret) Reveal() string

Reveal returns the underlying secret value. Call only where the secret is actually used (auth, signing); never pass the result to logging or error wrapping.

func (Secret) String

func (s Secret) String() string

Jump to

Keyboard shortcuts

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