pub struct BasicRedactor { /* private fields */ }Expand description
A ready-to-use redactor covering what actually leaks from a production error message: the user’s home directory, anything that looks like a credential, and email addresses.
This exists because “production adopters MUST supply a real one” is advice
that does not survive contact with a release deadline — a default that is
safe beats a default that is correct only if someone remembers. It is a
starting point, not a compliance boundary: a project handling regulated data
should compose its own Redactor on top.
What it does:
- Replaces the home directory with
~and the username elsewhere in a path with~user, so/home/ada/db/main.dbbecomes~/db/main.db— the structure a maintainer needs, without the identity. Matching ignores case and separator spelling, and respects path boundaries. - Masks the value of a
key = valuepair whose key names a credential (password,token,authorization,x-api-key,AZURE_OPENAI_KEY, …) in whatever form it arrives: quoted or bare, spaced or tight, or introduced by an HTTP auth scheme, where the credential follows the scheme word. A composite value —Some("…"),Credentials("…", "…"),["…", "…"],Secret { inner: "…" }— has every leaf inside it masked, its structure kept. - Masks the same keys inside JSON — including breadcrumb fields and
DomainContextpayloads, where the key is an object member and a per-string scan would never see it. - Masks a credential that arrives with no key at all, recognised by issuer
prefix (
sk-,ghp_,AKIA, …), JWT structure, or PEM block. - Masks anything shaped like an email address, including keys of a map that is keyed by one.
Where precision and safety conflict it over-redacts: a masked diagnostic
field costs a debugging session, a missed credential costs the credential.
Key names that are merely credential-adjacent (grouping_key, auth) are
the exception — they mask only a value that is itself credential-shaped, so
the fields a report is read and fingerprinted by survive.