redact

package
v0.1.3 Latest Latest
Warning

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

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

Documentation

Overview

Package redact applies the workspace's redaction policy to operator-visible text and structured values.

Nothing is compiled in. What counts as a secret is a property of a workspace, not of this binary: four separate hardcoded pattern lists previously drifted apart and were wrong in both directions, over-redacting ordinary prose and missing credentials none of them happened to name. The policy comes from [privacy] in mivia.toml, recommended values ship in mivia.toml.example, and a workspace that configures nothing redacts nothing.

That fails open by design. See .agents/rules/10-security-privacy.md.

Index

Constants

View Source
const DefaultPlaceholder = "[redacted]"

DefaultPlaceholder is substituted for a match when the policy names none.

Variables

This section is empty.

Functions

func JSONValue

func JSONValue(v any) any

JSONValue applies the process-wide policy.

func SetPolicy

func SetPolicy(p *Policy)

SetPolicy installs the process-wide policy. Call once, after config load.

func Text

func Text(s string) string

Text applies the process-wide policy.

Types

type Policy

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

Policy is a compiled redaction policy. The zero value and a nil *Policy redact nothing, so a path that runs before SetPolicy - tests, `mivia version`, any tool constructed directly - is unredacted rather than falling back to a compiled list.

func Compile

func Compile(patterns, keyNames []string, placeholder string) (*Policy, error)

Compile builds a policy from configuration.

An invalid pattern is an error naming the offending expression, never a silently dropped rule: a policy that quietly omits half its patterns is worse than one that refuses to start, because the operator believes they are covered.

func Current

func Current() *Policy

Current returns the installed policy, or nil when none is set.

func (*Policy) JSONValue

func (p *Policy) JSONValue(v any) any

JSONValue walks a decoded JSON value, replacing any value whose key matches the policy's key names and applying Text to the remaining string leaves. Strings are immutable, so leaves are replaced by their parent and the possibly-new value is returned.

func (*Policy) Text

func (p *Policy) Text(s string) string

Text replaces every pattern match with the placeholder.

The placeholder is substituted verbatim (ReplaceAllLiteralString), never through regexp template expansion: the placeholder is operator-chosen text, and Go's Expand semantics would silently corrupt it - $0 re-emits the matched secret itself (the redaction echoing the exact text it exists to hide), while $1/${name} expand to empty or absent groups. JSONValue's key-elision path inserts the same placeholder literally, so both paths must agree on a literal placeholder.

Jump to

Keyboard shortcuts

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