SafeDebug
A Rust derive macro for std::fmt::Debug that automatically redacts sensitive fields marked with #[facet(sensitive)]. Derive Facet and SafeDebug, then decorate fields with sensitive data with #[facet(sensitive)]. You'll get:
- a full
std::fmt::Debugimplementation-- respects{:?}and{:#?} - automatic redaction of fields you've marked as sensitive
- fallback to full redaction on any failure to find valid structure metadata
- all the benefits of deriving facet and existing in that ecosystem
The benefit of opting into facet here is, for example, the ability to do other things based on the presence of the shape metadata and the sensitivity flag, which you might want when implementing things in a context where this matters
Example
use Facet;
use SafeDebug;
See the ./examples directory for more usage examples.
Installation
Add safe-debug and facet to your crate's dependencies:
Or add manually to your Cargo.toml:
[]
= "0.1"
= "0.31"
Usage
For any struct or enum where you want automatic sensitive field redaction:
- Derive both
FacetandSafeDebug - Mark sensitive fields with
#[facet(sensitive)] - Use
{:?}or{:#?}formatting as normal
The Debug implementation will automatically redact fields marked as sensitive.
Troubleshooting
Error: "the trait bound YourType: Facet is not satisfied"
Remember to derive Facet as well as SafeDebug:
Error: "the trait bound T: std::fmt::Debug is not satisfied"
Make sure all your type parameters implement Debug:
Sensitive data appearing in logs
Make sure you're actually using the Debug trait (via {:?} or {:#?}), not Display or other formatting traits, via {}. This crate only derives Debug, leaving Display for you to control if you need it to print sensitive data for legitmate reasons.
License
This crate uses the same licensing approach as facet itself.
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.