logredact

package
v1.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package logredact keeps personal data out of process logs.

Container stdout is shipped to centralized log storage with long retention and broad queryability, so log lines are NOT a private scratchpad: an email subject, an external human's address, or a free-text rejection reason in a log line is personal data replicated outside the database's access controls. The policy:

  • Never log message subject lines — log subject_len instead.
  • Never log an EXTERNAL human's full email address — log only its domain (AddressDomain) or, for recipient lists, the count plus the distinct domain set (AddressDomains). e2a AGENT addresses are our own namespace and the primary tracing key, so they stay in full — but only once the address has RESOLVED to an agent row. An unresolved recipient is just an attacker-supplied string (SMTP RCPT runs before any authentication) and is redacted like any external address.
  • Truncate connecting IPs to a network prefix (IPNetwork): /24 for IPv4, /48 for IPv6 — enough for abuse/rate-limit debugging, less identifying.
  • Cap free-text human input and third-party error bodies (Truncate).
  • Redact at the LOG SINK, not at the source. A value that is also stored, served by the API, or emitted in a webhook (e.g. a HITL rejection reason) must stay precise there; only its log copy is reduced.

Only the subject rule is machine-checked, by the tripwire scan in logguard_test.go; the rest is a code-review responsibility.

Every helper here runs on hostile external input on the SMTP hot path and must never panic; malformed input degrades to a safe placeholder.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddressDomain

func AddressDomain(addr string) string

AddressDomain reduces an email address to only its domain, e.g. "alice@example.com" -> "example.com". It tolerates display-name forms ("Alice <alice@example.com>"), angle brackets, and the RFC 5322 comment form ("alice@example.com (Alice Smith)"), lowercases the result, and returns "invalid" for anything whose domain part is not hostname-shaped. It never returns the local part, a display name, or a comment.

func AddressDomains

func AddressDomains(addrs []string) []string

AddressDomains reduces a recipient list to its distinct, sorted domain set, bounded at maxDomains entries (a "+N more" marker replaces the overflow). Use together with the list's length, e.g.:

log.Printf("... to_count=%d to_domains=%v", len(to), logredact.AddressDomains(to))

func IPNetwork

func IPNetwork(ip string) string

IPNetwork truncates an IP address to its network prefix: /24 for IPv4, /48 for IPv6. It accepts bare addresses, "host:port" forms, and bracketed IPv6 literals; anything unparsable (including a non-IP transport address) returns "invalid".

func Truncate

func Truncate(s string, max int) string

Truncate caps s at max runes, appending "…" when anything was cut. It is rune-safe (never splits a UTF-8 sequence) and returns "" for max <= 0.

Types

This section is empty.

Jump to

Keyboard shortcuts

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