redact

package
v0.7.6 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 20 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 Args

func Args(args []string) []string

Args redacts argument values while preserving sensitive flag context and argument boundaries.

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 ContainsRegisteredSecret

func ContainsRegisteredSecret(value string) bool

ContainsRegisteredSecret reports whether value contains runtime-registered secret material.

func CrossScopeJSON

func CrossScopeJSON(raw json.RawMessage) json.RawMessage

CrossScopeJSON redacts every string of a JSON document read across a workspace or profile boundary. Structural identifiers (`*_id`, hashes, cursors) stay readable; sensitive field names are blanked wholesale.

func CrossScopeString

func CrossScopeString(value string) string

CrossScopeString redacts free text read across a workspace or profile boundary.

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 SecretFingerprint

func SecretFingerprint() [sha256.Size]byte

SecretFingerprint identifies the current continuous registrations without exposing their values.

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

func (e *Engine) RedactJSONEverywhere(raw json.RawMessage) json.RawMessage

RedactJSONEverywhere applies exact protection and the additive heuristics to every string in a JSON document, keeping only structural identifier fields.

func (*Engine) RedactJSONWithProtectedStrings

func (e *Engine) RedactJSONWithProtectedStrings(
	raw json.RawMessage,
	fields []string,
	protect func(path []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. Paths contain object keys; array elements inherit the enclosing field's path.

func (*Engine) RedactJSONWithProtection

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

RedactJSONWithProtection extends RedactJSONWithProtectedStrings with a structural predicate. It is consulted only for a sensitive field name, with that field's path; an accepted value is traversed normally instead of being replaced wholesale, so its strings still get exact secret redaction.

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.

type SecretSnapshot

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

SecretSnapshot pairs the registered secrets with their reversible encodings, derived once per change because redaction reads them for every string.

func RegisteredSecretSnapshot

func RegisteredSecretSnapshot() *SecretSnapshot

RegisteredSecretSnapshot captures one immutable set of registered secrets for redaction.

func (*SecretSnapshot) ExactBinaryJSON

func (s *SecretSnapshot) ExactBinaryJSON(raw json.RawMessage) (json.RawMessage, error)

ExactBinaryJSON redacts keys and string values against this fixed secret set.

func (*SecretSnapshot) ExactBinaryString

func (s *SecretSnapshot) ExactBinaryString(value string) string

ExactBinaryString redacts text against this fixed secret set.

func (*SecretSnapshot) MaterialFingerprint

func (s *SecretSnapshot) MaterialFingerprint() [sha256.Size]byte

MaterialFingerprint identifies the same redaction inputs across repeated registrations. The fingerprint is for in-process cache keys and must never be exposed or logged.

func (*SecretSnapshot) NeedsBinaryJSONRedaction

func (s *SecretSnapshot) NeedsBinaryJSONRedaction(raw json.RawMessage) (bool, error)

NeedsBinaryJSONRedaction reports whether any JSON string requires redaction under this snapshot.

Jump to

Keyboard shortcuts

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