redact

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 4, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const RedactedPlaceholder = "REDACTED"

RedactedPlaceholder is the replacement text used for redacted secrets.

Variables

This section is empty.

Functions

func Bytes

func Bytes(b []byte) []byte

Bytes is a convenience wrapper around String for []byte content.

func ConfigurePII added in v0.5.1

func ConfigurePII(cfg PIIConfig)

ConfigurePII sets the global PII redaction configuration. Pre-compiles patterns so the hot path (String → detectPII) does no compilation. Call once at startup after loading settings. Thread-safe.

func JSONLContent

func JSONLContent(content string) (string, error)

JSONLContent parses each line as JSON to determine which string values need redaction, then performs targeted replacements on the raw JSON bytes. Lines with no secrets are returned unchanged, preserving original formatting.

For multi-line JSON content (e.g., pretty-printed single JSON objects like OpenCode export), the function first attempts to parse the entire content as a single JSON value. This ensures field-aware redaction (which skips ID fields) is used instead of falling back to entropy-based detection on raw text lines, which would corrupt high-entropy identifiers.

func String

func String(s string) string

String replaces secrets and PII in s using layered detection: 1. Entropy-based: high-entropy alphanumeric sequences (threshold 4.5) 2. Pattern-based: betterleaks regex rules (260+ known secret formats) 3. Credentialed URIs: URLs containing userinfo passwords 4. Database connection strings: JDBC, keyword DSNs, and semicolon strings 5. Bounded credential key/value pairs: DB_PASSWORD=... 6. PII detection: email, phone, address patterns (only when configured via ConfigurePII) A string is redacted if ANY method flags it.

Types

type PIICategory added in v0.5.1

type PIICategory string

PIICategory identifies a category of personally identifiable information.

const (
	PIIEmail   PIICategory = "email"
	PIIPhone   PIICategory = "phone"
	PIIAddress PIICategory = "address"
)

type PIIConfig added in v0.5.1

type PIIConfig struct {
	// Enabled globally enables/disables PII redaction.
	// When false, no PII patterns are checked (secrets still redacted).
	Enabled bool

	// Categories maps each PII category to whether it is enabled.
	// Missing keys default to false (disabled).
	Categories map[PIICategory]bool

	// CustomPatterns allows teams to define additional regex patterns.
	// Each key is a label used in the replacement token (uppercased),
	// and each value is a regex pattern string.
	// Example: {"employee_id": `EMP-\d{6}`} produces [REDACTED_EMPLOYEE_ID].
	CustomPatterns map[string]string
	// contains filtered or unexported fields
}

PIIConfig controls which PII categories are detected and redacted.

type RedactedBytes added in v0.5.5

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

RedactedBytes represents transcript data that has been through secret redaction. Consumers that require pre-redacted input (e.g., compact.Compact, checkpoint stores) accept this type to enforce the contract at compile time.

Produced by JSONLBytes (primary constructor) or trusted wrappers for data previously persisted by checkpoint writers.

func AlreadyRedacted added in v0.5.5

func AlreadyRedacted(data []byte) RedactedBytes

AlreadyRedacted wraps transcript bytes known to already be redacted by a prior write path. Use this ONLY for trusted sources such as persisted checkpoint transcripts or controlled test fixtures. For fresh transcript input, use JSONLBytes.

func JSONLBytes

func JSONLBytes(b []byte) (RedactedBytes, error)

JSONLBytes redacts secrets in JSONL-formatted byte content and returns the result as RedactedBytes, certifying the output has been through redaction.

func (RedactedBytes) Bytes added in v0.5.5

func (r RedactedBytes) Bytes() []byte

Bytes returns the underlying byte slice.

func (RedactedBytes) Len added in v0.5.5

func (r RedactedBytes) Len() int

Len returns the number of bytes in the redacted payload.

Jump to

Keyboard shortcuts

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