redact

package
v0.3.0-beta.25 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package redact provides the process-wide canonical secret redactor.

Index

Constants

View Source
const Marker = "[REDACTED]"

Marker is the canonical replacement for secret material in public text.

Variables

This section is empty.

Functions

func ClaimTokens

func ClaimTokens(value string) string

ClaimTokens removes raw task-claim bearer tokens without applying other redaction rules.

func ClaimTokensJSON

func ClaimTokensJSON(raw json.RawMessage) json.RawMessage

ClaimTokensJSON removes raw claim-token fields and values from a JSON payload. Invalid input is materialized as a JSON string so wire callers never emit malformed JSON.

func ContainsRawClaimToken

func ContainsRawClaimToken(value string) bool

ContainsRawClaimToken reports whether value contains a concrete task-claim bearer token.

func Enabled

func Enabled() bool

Enabled reports the process-snapshotted additive heuristic setting.

func ExactBinaryJSON

func ExactBinaryJSON(raw json.RawMessage) (json.RawMessage, error)

ExactBinaryJSON removes literal secrets and whole JSON strings whose decoded bytes contain a registered secret.

func ExactBinaryString

func ExactBinaryString(value string) string

ExactBinaryString removes literal and reversibly encoded registered secrets from text.

func ExactBytes

func ExactBytes(value []byte) []byte

ExactBytes removes registered secrets from an opaque byte payload.

func ExactJSON

func ExactJSON(raw json.RawMessage) (json.RawMessage, error)

ExactJSON removes canonical and registered secrets from JSON keys and string values.

func ExactString

func ExactString(value string) string

ExactString removes canonical and registered secrets without additive heuristics.

func IsSensitiveKey

func IsSensitiveKey(key string) bool

IsSensitiveKey reports whether a field name belongs to the shared secret taxonomy.

func RegisterDynamicSecret

func RegisterDynamicSecret(value string) func()

RegisterDynamicSecret registers heuristic runtime material and returns an idempotent cleanup.

func RegisterRequiredSecret

func RegisterRequiredSecret(value string) func()

RegisterRequiredSecret registers nonblank caller-classified secret material and returns an idempotent cleanup.

func SnapshotEnabled

func SnapshotEnabled(enabled bool)

SnapshotEnabled freezes the process-wide additive heuristic setting. Later calls cannot change it; configuration changes therefore require a restart.

func String

func String(value string) string

String removes canonical, heuristic, and runtime-registered secret shapes from text.

Types

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine applies exact protections and optional conservative heuristics.

func New

func New(opts Options) *Engine

New constructs an independent redaction engine.

func (*Engine) RedactJSON

func (e *Engine) RedactJSON(raw json.RawMessage, fields []string) json.RawMessage

RedactJSON applies exact protection throughout a JSON document and additive heuristics only within the named free-text fields.

func (*Engine) RedactJSONWithProtectedStrings

func (e *Engine) RedactJSONWithProtectedStrings(
	raw json.RawMessage,
	fields []string,
	protect func(key string, value string) bool,
) json.RawMessage

RedactJSONWithProtectedStrings applies RedactJSON while preserving scalar strings that the caller identifies as public structural handles. The predicate is evaluated only after key-based secret protection, so a sensitive field name can never opt out of redaction.

func (*Engine) RedactJSONWithProtection

func (e *Engine) RedactJSONWithProtection(
	raw json.RawMessage,
	fields []string,
	protectString func(key string, value string) bool,
	protectObject func(key string, value any) bool,
) json.RawMessage

RedactJSONWithProtection extends RedactJSONWithProtectedStrings with a structural-object predicate. The object predicate is consulted only for a sensitive field name; accepted objects are traversed normally instead of being replaced wholesale.

func (*Engine) RedactLogAttrs

func (e *Engine) RedactLogAttrs(attrs []slog.Attr) []slog.Attr

RedactLogAttrs applies field-aware redaction while preserving correlation, numeric, boolean, duration, time, and other structured envelope values.

func (*Engine) RedactString

func (e *Engine) RedactString(value string) string

RedactString removes secret material from free text.

type Options

type Options struct {
	// Disabled turns off additive provider-prefix and entropy heuristics. Exact
	// claim, assignment, reference, and registered-secret protection remains active.
	Disabled bool
}

Options configures one independent redaction engine.

Jump to

Keyboard shortcuts

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