Skip to main content

BasicRedactor

Struct BasicRedactor 

Source
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.db becomes ~/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 = value pair 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 DomainContext payloads, 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.

Implementations§

Source§

impl BasicRedactor

Source

pub fn new() -> Self

Build a redactor for the current user’s environment.

Source

pub fn home(self, home: impl Into<String>) -> Self

Override the home directory to strip. Mainly for tests and for daemons that run as a service account but report on a user’s data directory.

Trait Implementations§

Source§

impl Default for BasicRedactor

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Redactor for BasicRedactor

Source§

fn redact(&self, input: &str) -> String

Return input with any sensitive substrings replaced.
Source§

fn redact_value_for_key(&self, key: &str, value: &mut Value)

Redact one object member, given the key it is stored under. Read more
Source§

fn redact_key(&self, key: &str) -> String

Redact an object key. Keys are usually field names — structure worth keeping — so the default returns them unchanged. A map keyed by user data is the exception, and the reason this hook exists.
Source§

fn redact_json(&self, value: &mut Value)

Redact every string node within a JSON value, structure preserved. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more