Wrap all sensitive data fields in Secret<> types to prevent accidental exposure through logs, debug output, serialization, or error messages. This includes authentication tokens, API keys, PII data, payment information, and any credentials.
Fields that should be wrapped in Secret<>:
Example implementation:
// Instead of:
pub struct PaymentData {
pub bank_number: Option<String>,
pub client_secret: Option<String>,
pub token: String,
}
// Use:
pub struct PaymentData {
pub bank_number: Option<Secret<String>>,
pub client_secret: Option<Secret<String>>,
pub token: Secret<String>,
}
For highly sensitive data like KMS-encrypted tokens, consider additional encryption layers beyond the Secret<> wrapper. The Secret<> type prevents accidental logging and provides controlled access through methods like expose()
or peek()
, ensuring sensitive data is only accessed intentionally.
Enter the URL of a public GitHub repository