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
Rust adyenbeginner-friendlyfeaturedfinancefintechhacktoberfesthigh-performanceopen-sourceorchestrationpaymentpayment-gatewaypayment-integrationpayment-processingpaymentspayments-platformrestful-apirustsdkstripeworks-with-react
fix(ucs): correct Netcetera auth-header injection and suppress its X-Connector-Config (#13673)
Shankar Singh C440d09b19c15
diff --git a/crates/router/src/core/unified_connector_service.rs b/crates/router/src/core/unified_connector_service.rsindex 9cd0d71e8c..4a485418c2 100644--- a/crates/router/src/core/unified_connector_service.rs+++ b/crates/router/src/core/unified_connector_service.rs@@ -1978,6 +1978,9 @@ pub fn build_unified_connector_service_auth_metadata(.change_context(UnifiedConnectorServiceError::FailedToObtainAuthType).attach_printable("Failed to obtain ConnectorAuthType")?;let merchant_id = processor_merchant_id.get_string_repr();+ let connector = Connector::from_str(&connector_name)+ .change_context(UnifiedConnectorServiceError::FailedToObtainAuthType)+ .attach_printable_lazy(|| format!("Invalid connector name: {connector_name}"))?;// Extract connector metadata from MCA for connector-specific configlet merchant_account_metadata = merchant_connector_account.get_metadata();let merchant_account_metadata_value = merchant_account_metadata@@ -1985,7 +1988,7 @@ pub fn build_unified_connector_service_auth_metadata(.and_then(|m| serde_json::to_value(m.clone().expose()).ok());// Build connector-specific config for supported connectorslet connector_config = connector_config::build_connector_config_header(- &connector_name,+ connector,&auth_type,merchant_account_metadata_value.as_ref(),)@@ -2061,17 +2064,47 @@ pub fn build_unified_connector_service_auth_metadata(ConnectorAuthType::CertificateAuth {certificate,private_key,- } => Ok(ConnectorAuthMetadata {- connector_name,- auth_type: consts::UCS_AUTH_MULTI_KEY.to_string(),- api_key: Some(certificate.clone()),- key1: Some(private_key.clone()),- key2: None,- api_secret: None,- auth_key_map: None,- merchant_id: Secret::new(merchant_id.to_string()),- connector_config,- }),+ } => {+ if matches!(connector, Connector::Netcetera) {+ // Netcetera is UCS's one authentication-only, no-key connector: its mTLS cert+ // is presented on the VGS outbound route, not via UCS auth headers, and+ // connector-service explicitly opts it out of the+ // CertificateAuth->ConnectorSpecificConfig conversion (see+ // `ConnectorEnum::Netcetera => Err(...)` in connector-service's+ // router_data.rs), routing it via the `x-auth: no-key` shortcut instead.+ // Sending it as multi-auth-key (like Santander, which does need real cert/key+ // transmitted) makes UCS fail with "Failed to convert legacy auth for+ // connector: netcetera".+ Ok(ConnectorAuthMetadata {+ connector_name,+ auth_type: consts::UCS_AUTH_NO_KEY.to_string(),+ api_key: None,+ key1: None,+ key2: None,+ api_secret: None,+ auth_key_map: None,+ merchant_id: Secret::new(merchant_id.to_string()),+ connector_config: None,+ })+ } else {+ Ok(ConnectorAuthMetadata {+ connector_name,+ auth_type: consts::UCS_AUTH_MULTI_KEY.to_string(),+ api_key: Some(certificate.clone()),+ key1: Some(private_key.clone()),+ // UCS's "multi-auth-key" header parsing unconditionally requires x-key2+ // and x-api-secret to be present. Connectors reaching this branch (e.g.+ // Santander) only supply certificate/private_key, so duplicate+ // private_key here purely to satisfy UCS's presence check; the connector+ // implementation itself never reads key2/api_secret.+ key2: Some(private_key.clone()),+ api_secret: Some(private_key.clone()),+ auth_key_map: None,+ merchant_id: Secret::new(merchant_id.to_string()),+ connector_config,+ })+ }+ }ConnectorAuthType::TemporaryAuth | ConnectorAuthType::NoKey => {Err(UnifiedConnectorServiceError::FailedToObtainAuthType).attach_printable("Unsupported ConnectorAuthType for header injection")diff --git a/crates/router/src/core/unified_connector_service/connector_config.rs b/crates/router/src/core/unified_connector_service/connector_config.rsindex d18100c48c..356c778029 100644--- a/crates/router/src/core/unified_connector_service/connector_config.rs+++ b/crates/router/src/core/unified_connector_service/connector_config.rs@@ -3,7 +3,7 @@//! This module provides functionality to transform connector authentication data//! into connector-specific configuration structures expected by the Unified Connector Service (UCS).-use std::{collections::HashMap, str::FromStr};+use std::collections::HashMap;use common_enums::{connector_enums::Connector, enums::Currency};use common_utils::ext_traits::ValueExt;@@ -1757,20 +1757,24 @@ impl ForeignTryFrom<(Connector, &ConnectorAuthType, Option<&serde_json::Value>)>/// Build the X_CONNECTOR_CONFIG header value for any connectorpub fn build_connector_config_header(- connector_name: &str,+ connector: Connector,auth_type: &ConnectorAuthType,merchant_account_metadata: Option<&serde_json::Value>,) -> RouterResult<Option<String>> {- let connector = Connector::from_str(connector_name)- .change_context(errors::ApiErrorResponse::InternalServerError)- .attach_printable_lazy(|| format!("Invalid connector name: {}", connector_name))?;-let config = ConnectorSpecificConfig::foreign_try_from((connector,auth_type,merchant_account_metadata,))?;+ // Netcetera has no connector-specific config on the wire (connector-service's+ // `ConnectorSpecificConfig` oneof has no `netcetera` case), so sending this header makes+ // UCS hard-error on deserialization instead of falling back to the legacy auth header.+ // Suppress it here so UCS takes the legacy-header path, which does work for Netcetera.+ if matches!(config, ConnectorSpecificConfig::Netcetera) {+ return Ok(None);+ }+let config_json = serde_json::to_value(&config).change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("Failed to serialize connector config to JSON value")?;