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: Fix some resource access scoping (#14975)
Anurag Thakur4e6a36b4a62d
diff --git a/crates/router/src/core/customers.rs b/crates/router/src/core/customers.rsindex 35fd5aa7b4..e7f4a76788 100644--- a/crates/router/src/core/customers.rs+++ b/crates/router/src/core/customers.rs@@ -623,8 +623,9 @@ pub async fn retrieve_customer(let db = state.store.as_ref();let response = db- .find_customer_by_global_id(+ .find_customer_by_global_id_merchant_id(&id,+ provider.get_account().get_id(),provider.get_key_store(),provider.get_account().storage_scheme,)@@ -819,8 +820,9 @@ impl CustomerDeleteBridge for id_type::GlobalCustomerId {) -> errors::CustomerResponse<customers::CustomerDeleteResponse> {let provider = platform.get_provider();let customer_orig = db- .find_customer_by_global_id(+ .find_customer_by_global_id_merchant_id(self,+ provider.get_account().get_id(),provider.get_key_store(),provider.get_account().storage_scheme,)@@ -1408,8 +1410,9 @@ impl VerifyIdForUpdateCustomer<'_> {db: &dyn StorageInterface,) -> Result<domain::Customer, error_stack::Report<errors::CustomersErrorResponse>> {let customer = db- .find_customer_by_global_id(+ .find_customer_by_global_id_merchant_id(self.id,+ self.merchant_account.get_id(),self.key_store,self.merchant_account.storage_scheme,)diff --git a/crates/router/src/core/payment_link.rs b/crates/router/src/core/payment_link.rsindex d589922a3e..e8a671992e 100644--- a/crates/router/src/core/payment_link.rs+++ b/crates/router/src/core/payment_link.rs@@ -53,6 +53,7 @@ fn get_redirection_log_endpoint(base_url: &str) -> RouterResult<url::Url> {pub async fn retrieve_payment_link(state: SessionState,+ requestor_processor_merchant_id: &common_utils::id_type::MerchantId,payment_link_id: String,) -> RouterResponse<api_models::payments::RetrievePaymentLinkResponse> {let db = &*state.store;@@ -61,6 +62,12 @@ pub async fn retrieve_payment_link(.await.to_not_found_response(errors::ApiErrorResponse::PaymentLinkNotFound)?;+ if payment_link_config.processor_merchant_id.as_ref() != Some(requestor_processor_merchant_id)+ && requestor_processor_merchant_id != &payment_link_config.merchant_id+ {+ Err(errors::ApiErrorResponse::PaymentLinkNotFound)?+ }+let session_expiry = payment_link_config.fulfilment_time.unwrap_or_else(|| {common_utils::date_time::now().saturating_add(time::Duration::seconds(DEFAULT_SESSION_EXPIRY))diff --git a/crates/router/src/core/payment_methods.rs b/crates/router/src/core/payment_methods.rsindex 62c57e4e41..1ef3642f6c 100644--- a/crates/router/src/core/payment_methods.rs+++ b/crates/router/src/core/payment_methods.rs@@ -4703,6 +4703,10 @@ pub async fn get_token_data_for_payment_method(.await.to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)?;+ if payment_method.merchant_id != *provider.get_account().get_id() {+ Err(errors::ApiErrorResponse::PaymentMethodNotFound)?+ }+let token_data_response = Box::pin(generate_token_data_response(&state,request,@@ -6316,6 +6320,10 @@ pub async fn retrieve_payment_method(.change_context(errors::ApiErrorResponse::PaymentMethodNotFound).attach_printable("Failed to fetch payment method by storage")?;+ if payment_method.merchant_id != *platform.get_provider().get_account().get_id() {+ Err(errors::ApiErrorResponse::PaymentMethodNotFound)?+ }+when(matches!(payment_method.status,@@ -6684,6 +6692,10 @@ async fn fetch_volatile_payment_method_record(message: "Payment method token either expired or does not exist".to_string(),})?;+ if payment_method.merchant_id != key_store.merchant_id {+ Err(errors::ApiErrorResponse::PaymentMethodNotFound)?+ }+let keymanager_state = &state.into();let domain_payment_method = domain::PaymentMethod::convert_back(@@ -8479,14 +8491,21 @@ async fn fetch_payment_method(let merchant_account = provider.get_account();let key_store = provider.get_key_store();- db.find_payment_method(- key_store,- payment_method_id,- merchant_account.storage_scheme,- )- .await- .to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)- .attach_printable("Payment method not found for network token status check")+ let payment_method = db+ .find_payment_method(+ key_store,+ payment_method_id,+ merchant_account.storage_scheme,+ )+ .await+ .to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)+ .attach_printable("Payment method not found for network token status check")?;++ if payment_method.merchant_id != *merchant_account.get_id() {+ Err(errors::ApiErrorResponse::PaymentMethodNotFound)?+ }++ Ok(payment_method)}#[cfg(feature = "v2")]@@ -8575,28 +8594,39 @@ pub async fn payment_method_get_token_details_core() -> RouterResponse<payment_methods::PaymentMethodGetTokenDetailsResponse> {let token_data = pm_routes::ParentPaymentMethodToken::create_key_for_token(&temporary_token).get_data_for_token(&state)- .await;+ .await?;- match token_data {- Ok(storage::PaymentTokenData::PermanentCard(card_token_data)) => {- Ok(services::ApplicationResponse::Json(- payment_methods::PaymentMethodGetTokenDetailsResponse {- id: card_token_data.payment_method_id,- payment_method_token: temporary_token,- },- ))+ let (payment_method_id, storage_type) = match token_data {+ storage::PaymentTokenData::PermanentCard(card) => {+ (card.payment_method_id, card.storage_type)}- Ok(storage::PaymentTokenData::BankDebit(bank_debit_token_data)) => {- Ok(services::ApplicationResponse::Json(- payment_methods::PaymentMethodGetTokenDetailsResponse {- id: bank_debit_token_data.payment_method_id,- payment_method_token: temporary_token,- },- ))+ storage::PaymentTokenData::BankDebit(bank_debit) => {+ (bank_debit.payment_method_id, bank_debit.storage_type)+ }+ _ => Err(errors::ApiErrorResponse::PaymentMethodNotFound)?,+ };++ match storage_type {+ common_enums::StorageType::Volatile => {+ fetch_volatile_payment_method_record(+ &state,+ provider.get_key_store(),+ payment_method_id.get_string_repr(),+ )+ .await?;+ }+ common_enums::StorageType::Persistent => {+ fetch_payment_method_with_fallback(&state, &provider, &payment_method_id, storage_type)+ .await?;}- Ok(_) => Err(errors::ApiErrorResponse::PaymentMethodNotFound.into()),- Err(e) => Err(e),}++ Ok(services::ApplicationResponse::Json(+ payment_methods::PaymentMethodGetTokenDetailsResponse {+ id: payment_method_id,+ payment_method_token: temporary_token,+ },+ ))}#[cfg(feature = "v2")]@@ -8633,6 +8663,10 @@ impl<'a> pm_types::PaymentMethodUpdateHandler<'a> {),};+ if payment_method.merchant_id != *platform.get_provider().get_account().get_id() {+ Err(errors::ApiErrorResponse::PaymentMethodNotFound)?+ }+let handler = Self {platform,profile,diff --git a/crates/router/src/core/payment_methods/cards.rs b/crates/router/src/core/payment_methods/cards.rsindex 775947fb45..27f719a50c 100644--- a/crates/router/src/core/payment_methods/cards.rs+++ b/crates/router/src/core/payment_methods/cards.rs@@ -1651,6 +1651,10 @@ impl PaymentMethodsController for PmCards<'_> {.await.to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)?;+ if pm.merchant_id != *self.provider.get_account().get_id() {+ Err(errors::ApiErrorResponse::PaymentMethodNotFound)?+ }+let (card, locker_metadata) =if pm.get_payment_method_type() == Some(enums::PaymentMethod::Card) {let (card_detail, locker_metadata) = if self.state.conf.locker.locker_enabled {@@ -1719,6 +1723,10 @@ impl PaymentMethodsController for PmCards<'_> {.await.to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)?;+ if key.merchant_id != *self.provider.get_account().get_id() {+ Err(errors::ApiErrorResponse::PaymentMethodNotFound)?+ }+let customer_id = key.customer_id.clone().get_required_value("customer_id")?;let use_merchant_reference_id =@@ -2553,6 +2561,10 @@ pub async fn add_payment_method_data(.change_context(errors::ApiErrorResponse::PaymentMethodNotFound).attach_printable("Unable to find payment method")?;+ if payment_method.merchant_id != *provider.get_account().get_id() {+ Err(errors::ApiErrorResponse::PaymentMethodNotFound)?+ }+if payment_method.status != enums::PaymentMethodStatus::AwaitingData {return Err((errors::ApiErrorResponse::ClientSecretExpired).into());}@@ -2804,13 +2816,19 @@ pub async fn update_customer_payment_method(let pm = if let Some(pm) = pm_data {pm} else {- db.find_payment_method(- provider.get_key_store(),- payment_method_id,- provider.get_account().storage_scheme,- )- .await- .to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)?+ let payment_method = db+ .find_payment_method(+ provider.get_key_store(),+ payment_method_id,+ provider.get_account().storage_scheme,+ )+ .await+ .to_not_found_response(errors::ApiErrorResponse::PaymentMethodNotFound)?;++ if payment_method.merchant_id != *provider.get_account().get_id() {+ Err(errors::ApiErrorResponse::PaymentMethodNotFound)?+ }+ payment_method};let customer_id = pm.customer_id.clone().get_required_value("customer_id")?;diff --git a/crates/router/src/routes/payment_link.rs b/crates/router/src/routes/payment_link.rsindex 6c0021d381..79cb44d321 100644--- a/crates/router/src/routes/payment_link.rs+++ b/crates/router/src/routes/payment_link.rs@@ -46,7 +46,17 @@ pub async fn payment_link_retrieve(state,&req,payload.clone(),- |state, _auth, _, _| retrieve_payment_link(state, path.clone()),+ |state, auth, _, _| {+ let payment_link_id = path.clone();+ async move {+ retrieve_payment_link(+ state,+ auth.platform.get_processor().get_account().get_id(),+ payment_link_id,+ )+ .await+ }+ },&*auth_type,api_locking::LockAction::NotApplicable,)