Redaction utility for sensitive data in error messages, debug logs, etc.
Usage
Wrap values in [Redacted] to prevent them from being printed directly.
use Redacted;
use SimpleRedactor;
let secret = new;
assert_eq!;
assert_eq!;
Deserialization
Often, you won't create [Redacted] instances manually. Instead, you might deserialize them
from a configuration structure:
use Redacted;
let redis_config: RedisConfig = from_str.unwrap;
// If you did eg. `dbg!(redis_config)`...
assert_eq!;
Serialization
Values wrapped in a [Redacted] cannot be serialized with [serde]. This is to prevent
accidentally serializing either the redacted or the unredacted form when you don't expect it.
You can use the #[serde(serialize_with)] attribute to serialize a [Redacted] field.
apollo-redaction comes with serialization helpers:
- [
ser::unredacted] - serializes the unredacted representation - [
ser::display_redacted] - serializes the redacted [Display] representation
Strategies
A strategy must be provided as a type parameter. For example:
use Redacted;
use UrlHostRedactor;
use EmailRedactor;
// when deserializing a field...
// when constructing a value manually...
let email = new;
| Strategy | Sample input | Sample output |
|---|---|---|
[SimpleRedactor] |
any | [REDACTED] |
FullRedactor |
secret |
****** |
PasswordRedactor |
any | ******** |
IpRedactor |
192.168.1.100 |
192.168.*.* |
UrlHostRedactor |
https://username:passwd@mytelemetryhost.com/v1/traces |
****/v1/traces |
UrlPasswordRedactor |
https://alice:s3cr3t@proxy.example.com/ |
https://alice:***@proxy.example.com/ |
EmailRedactor |
janedoe@gmail.com |
j***e@gmail.com |
First4Redactor |
sk_live_abc123 |
sk_l**** |
Last4Redactor |
4242424242424242 |
************4242 |
CardRedactor |
4242-4242-4242-4242 |
****-****-****-4242 |
FixedRedactor<N> |
password123 (N=4) |
pass******* |
Feature flags
schemarsenables a transparent [schemars::JsonSchema] implementation forRedacted<T>whenTimplementsschemars::JsonSchema.