Skip to content

Open source, composable payments platform | PCI compliant | SaaS and Self-host options | Enables connectivity to multiple payment, payout, fraud, vault and tokenization providers | Uplifts authorization with intelligent routing and revenue recovery | Reduce payment processing costs with cost observability | Reduces payment ops with reconciliation

fix(pii): mask email fields that reach logs as plain strings (#14074)

Tushar Shukla849a813a71c9
diff --git a/crates/api_models/src/disputes.rs b/crates/api_models/src/disputes.rs
index 023b53bd76..3f84f78651 100644
--- a/crates/api_models/src/disputes.rs
+++ b/crates/api_models/src/disputes.rs
@@ -1,7 +1,10 @@
use std::collections::HashMap;
-use common_utils::types::{StringMinorUnit, TimeRange};
-use hyperswitch_masking::{Deserialize, Serialize};
+use common_utils::{
+ pii::EmailStrategy,
+ types::{StringMinorUnit, TimeRange},
+};
+use hyperswitch_masking::{Deserialize, Secret, Serialize};
use serde::de::Error;
use smithy::SmithyModel;
use time::PrimitiveDateTime;
@@ -195,7 +198,8 @@ pub struct SubmitEvidenceRequest {
/// File Id of customer communication
pub customer_communication: Option<String>,
/// Customer email address
- pub customer_email_address: Option<String>,
+ #[schema(value_type = Option<String>)]
+ pub customer_email_address: Option<Secret<String, EmailStrategy>>,
/// Customer name
pub customer_name: Option<String>,
/// IP address of the customer
diff --git a/crates/api_models/src/open_router.rs b/crates/api_models/src/open_router.rs
index 83f79cbbd4..43122d6c25 100644
--- a/crates/api_models/src/open_router.rs
+++ b/crates/api_models/src/open_router.rs
@@ -1,6 +1,6 @@
use std::{collections::HashMap, fmt::Debug};
-use common_utils::{errors, id_type, types::MinorUnit};
+use common_utils::{errors, id_type, pii::EmailStrategy, types::MinorUnit};
pub use euclid::{
dssa::types::EuclidAnalysable,
frontend::{
@@ -8,6 +8,7 @@ pub use euclid::{
dir::{DirKeyKind, EuclidDirFilter},
},
};
+use hyperswitch_masking::Secret;
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
@@ -568,7 +569,7 @@ pub struct MerchantTokenRequest {
/// Display only, so the dashboard can name the user rather than show a profile id.
/// Authorization comes from the grant and permissions, never from this.
#[serde(skip_serializing_if = "Option::is_none")]
- pub email: Option<String>,
+ pub email: Option<Secret<String, EmailStrategy>>,
}
/// Account hierarchy pushed to the Decision Engine. A DE scope is a Hyperswitch profile; the
diff --git a/crates/hyperswitch_connectors/src/connectors/adyen/transformers.rs b/crates/hyperswitch_connectors/src/connectors/adyen/transformers.rs
index 973083f162..d95c5b54cf 100644
--- a/crates/hyperswitch_connectors/src/connectors/adyen/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/adyen/transformers.rs
@@ -284,9 +284,9 @@ pub struct RiskData {
#[serde(rename = "riskdata.deliveryMethod")]
delivery_method: Option<String>,
#[serde(rename = "riskdata.emailName")]
- email_name: Option<String>,
+ email_name: Option<Secret<String>>,
#[serde(rename = "riskdata.emailDomain")]
- email_domain: Option<String>,
+ email_domain: Option<Secret<String>>,
#[serde(rename = "riskdata.lastOrderDate")]
last_order_date: Option<String>,
#[serde(rename = "riskdata.merchantReference")]
@@ -3006,8 +3006,8 @@ pub fn get_risk_data(metadata: serde_json::Value) -> Option<RiskData> {
affiliate_channel,
avg_order_value,
delivery_method,
- email_name,
- email_domain,
+ email_name: email_name.map(Secret::new),
+ email_domain: email_domain.map(Secret::new),
last_order_date,
merchant_reference,
payment_method,
@@ -5587,7 +5587,7 @@ pub struct AdyenAdditionalDataWH {
/// [only for cards] This is only available for Visa and Mastercard
pub refusal_code_raw: Option<String>,
#[serde(rename = "shopperEmail")]
- pub shopper_email: Option<String>,
+ pub shopper_email: Option<Secret<String, common_utils::pii::EmailStrategy>>,
#[serde(rename = "shopperReference")]
pub shopper_reference: Option<String>,
pub expiry_date: Option<Secret<String>>,
diff --git a/crates/hyperswitch_connectors/src/connectors/calida/transformers.rs b/crates/hyperswitch_connectors/src/connectors/calida/transformers.rs
index e91943c134..58a21d3627 100644
--- a/crates/hyperswitch_connectors/src/connectors/calida/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/calida/transformers.rs
@@ -213,7 +213,7 @@ pub struct CalidaSyncResponse {
pub payment_method_type: Option<String>,
pub shop_name: Option<String>,
pub sender_name: Option<String>,
- pub sender_email: Option<String>,
+ pub sender_email: Option<Secret<String, common_utils::pii::EmailStrategy>>,
pub description: Option<String>,
pub amount: FloatMajorUnit,
pub currency: enums::Currency,
diff --git a/crates/hyperswitch_connectors/src/connectors/chargebee/transformers.rs b/crates/hyperswitch_connectors/src/connectors/chargebee/transformers.rs
index 68c81de0dd..9074027e65 100644
--- a/crates/hyperswitch_connectors/src/connectors/chargebee/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/chargebee/transformers.rs
@@ -1488,10 +1488,7 @@ convert_connector_response_to_domain_response!(
.name
.as_ref()
.map(|name| name.clone().expose()),
- customer_response
- .email
- .as_ref()
- .map(|email| email.clone().expose().expose()),
+ customer_response.email.clone(),
customer_response.billing_address.clone(),
),
)),
diff --git a/crates/hyperswitch_connectors/src/connectors/netcetera/netcetera_types.rs b/crates/hyperswitch_connectors/src/connectors/netcetera/netcetera_types.rs
index 78395d7281..c4dfada640 100644
--- a/crates/hyperswitch_connectors/src/connectors/netcetera/netcetera_types.rs
+++ b/crates/hyperswitch_connectors/src/connectors/netcetera/netcetera_types.rs
@@ -1,6 +1,9 @@
use std::collections::HashMap;
-use common_utils::{pii::Email, types::SemanticVersion};
+use common_utils::{
+ pii::{Email, EmailStrategy},
+ types::SemanticVersion,
+};
use hyperswitch_domain_models::router_request_types::{
authentication::MessageCategory, BrowserInformation,
};
@@ -1081,7 +1084,7 @@ pub struct MerchantRiskIndicator {
delivery_timeframe: Option<String>,
/// For electronic delivery, the email address to which the merchandise was delivered.
- delivery_email_address: Option<String>,
+ delivery_email_address: Option<hyperswitch_masking::Secret<String, EmailStrategy>>,
/// Indicates whether the cardholder is reordering previously purchased merchandise.
///
@@ -1324,7 +1327,7 @@ pub struct SellerInfo {
/// Business or contact email address of the Seller. The value length is maximum 254 characters. Accepted values
/// shall meet requirements of Section 3.4 of IETF RFC 5322. This field is optional.
- seller_email: Option<String>,
+ seller_email: Option<hyperswitch_masking::Secret<String, EmailStrategy>>,
/// Business or contact phone number of the Seller. Country Code and Subscriber sections of the number represented
/// by the following named fields:
diff --git a/crates/hyperswitch_connectors/src/connectors/stripe/transformers.rs b/crates/hyperswitch_connectors/src/connectors/stripe/transformers.rs
index d53433e133..03b830f520 100644
--- a/crates/hyperswitch_connectors/src/connectors/stripe/transformers.rs
+++ b/crates/hyperswitch_connectors/src/connectors/stripe/transformers.rs
@@ -5455,9 +5455,7 @@ impl TryFrom<&SubmitEvidenceRouterData> for Evidence {
cancellation_rebuttal: submit_evidence_request_data.cancellation_rebuttal,
customer_communication: submit_evidence_request_data
.customer_communication_provider_file_id,
- customer_email_address: submit_evidence_request_data
- .customer_email_address
- .map(Secret::new),
+ customer_email_address: submit_evidence_request_data.customer_email_address,
customer_name: submit_evidence_request_data.customer_name.map(Secret::new),
customer_purchase_ip: submit_evidence_request_data
.customer_purchase_ip
diff --git a/crates/hyperswitch_domain_models/src/router_request_types.rs b/crates/hyperswitch_domain_models/src/router_request_types.rs
index 04c5c69f97..c167754d21 100644
--- a/crates/hyperswitch_domain_models/src/router_request_types.rs
+++ b/crates/hyperswitch_domain_models/src/router_request_types.rs
@@ -1693,7 +1693,7 @@ pub struct SubmitEvidenceRequestData {
pub customer_communication: Option<Vec<u8>>,
pub customer_communication_file_type: Option<String>,
pub customer_communication_provider_file_id: Option<String>,
- pub customer_email_address: Option<String>,
+ pub customer_email_address: Option<Secret<String, pii::EmailStrategy>>,
pub customer_name: Option<String>,
pub customer_purchase_ip: Option<String>,
//customer signature
diff --git a/crates/hyperswitch_domain_models/src/router_response_types.rs b/crates/hyperswitch_domain_models/src/router_response_types.rs
index 023fc1754b..bef7253888 100644
--- a/crates/hyperswitch_domain_models/src/router_response_types.rs
+++ b/crates/hyperswitch_domain_models/src/router_response_types.rs
@@ -31,7 +31,7 @@ pub struct RefundsResponseData {
pub struct ConnectorCustomerResponseData {
pub connector_customer_id: String,
pub name: Option<String>,
- pub email: Option<String>,
+ pub email: Option<pii::Email>,
pub billing_address: Option<AddressDetails>,
}
@@ -42,7 +42,7 @@ impl ConnectorCustomerResponseData {
pub fn new(
connector_customer_id: String,
name: Option<String>,
- email: Option<String>,
+ email: Option<pii::Email>,
billing_address: Option<AddressDetails>,
) -> Self {
Self {
@@ -954,3 +954,36 @@ impl Default for VaultResponseData {
}
}
}
+
+#[cfg(test)]
+mod pii_masking_tests {
+ use super::ConnectorCustomerResponseData;
+
+ /// Connectors parse the customer email into a masked `Email`; this domain
+ /// type used to strip it back to a plain `String`, so the address reached
+ /// any log that serializes the struct via `masked_serialize`.
+ #[test]
+ fn connector_customer_email_is_masked_for_logging() {
+ let email = common_utils::pii::Email::try_from("[email protected]".to_string())
+ .expect("valid email");
+ let data = ConnectorCustomerResponseData::new(
+ "cus_1".to_string(),
+ Some("Jane Doe".to_string()),
+ Some(email),
+ None,
+ );
+
+ let masked = hyperswitch_masking::masked_serialize(&data)
+ .expect("masked serialization")
+ .to_string();
+
+ assert!(
+ !masked.contains("[email protected]"),
+ "email leaked into the log view: {masked}"
+ );
+ assert!(
+ masked.contains("@example.com"),
+ "EmailStrategy should retain the domain, got: {masked}"
+ );
+ }
+}
diff --git a/crates/router/src/core/routing.rs b/crates/router/src/core/routing.rs
index 132b1f138a..50a1f8123b 100644
--- a/crates/router/src/core/routing.rs
+++ b/crates/router/src/core/routing.rs
@@ -87,15 +87,9 @@ async fn decision_engine_token_request(
// a failure here costs a name in the dashboard and nothing else.
let email = match state.global_store.find_user_by_user_id(&user.user_id).await {
Ok(found) => {
- // `Email` wraps a `Secret`, so it takes both traits to reach the string.
- use hyperswitch_masking::{ExposeInterface, PeekInterface};
- Some(
- domain::UserFromStorage::from(found)
- .get_email()
- .expose()
- .peek()
- .to_string(),
- )
+ // `Email` wraps the masked secret we want, so one unwrap reaches it.
+ use hyperswitch_masking::ExposeInterface;
+ Some(domain::UserFromStorage::from(found).get_email().expose())
}
Err(error) => {
router_env::logger::warn!(