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(revenue_recovery): improve recovery resource validation (#14967)
CHALLA NISHANTH BABU8c41c7bea0ff
diff --git a/crates/router/src/core/payments.rs b/crates/router/src/core/payments.rsindex 0a17fcddd0..4344a269f2 100644--- a/crates/router/src/core/payments.rs+++ b/crates/router/src/core/payments.rs@@ -4676,6 +4676,16 @@ pub async fn revenue_recovery_get_intent_core(let payment_intent = payment_data.get_payment_intent();+ // The intent is fetched by id alone, so make sure it belongs to the caller+ if !utils::is_owned_by_merchant_and_profile(+ &platform,+ &profile,+ &payment_intent.merchant_id,+ &payment_intent.profile_id,+ ) {+ return Err(errors::ApiErrorResponse::PaymentNotFound.into());+ }+// Get workflow entries to determine recovery statuslet (calculate_workflow, execute_workflow) = get_workflow_entries(&state, &payment_intent.id).awaitdiff --git a/crates/router/src/core/payments/operations/payment_attempt_list.rs b/crates/router/src/core/payments/operations/payment_attempt_list.rsindex e8d575b737..e9241c54b5 100644--- a/crates/router/src/core/payments/operations/payment_attempt_list.rs+++ b/crates/router/src/core/payments/operations/payment_attempt_list.rs@@ -19,6 +19,7 @@ use crate::{api, domain,storage::{self, enums},},+ utils,};#[derive(Debug, Clone, Copy)]@@ -89,11 +90,31 @@ impl<F: Send + Clone + Sync>_payment_id: &common_utils::id_type::GlobalPaymentId,request: &PaymentAttemptListRequest,platform: &domain::Platform,- _profile: &domain::Profile,+ profile: &domain::Profile,_header_payload: &hyperswitch_domain_models::payments::HeaderPayload,) -> RouterResult<operations::GetTrackerResponse<payments::PaymentAttemptListData<F>>> {let db = &*state.store;let storage_scheme = platform.get_processor().get_storage_scheme();++ // Attempts are fetched by payment id alone, so make sure the payment belongs to the caller+ let payment_intent = db+ .find_payment_intent_by_id(+ &request.payment_intent_id,+ platform.get_processor().get_key_store(),+ storage_scheme,+ )+ .await+ .to_not_found_response(errors::ApiErrorResponse::PaymentNotFound)?;++ if !utils::is_owned_by_merchant_and_profile(+ platform,+ profile,+ &payment_intent.merchant_id,+ &payment_intent.profile_id,+ ) {+ return Err(errors::ApiErrorResponse::PaymentNotFound.into());+ }+let payment_attempt_list = db.find_payment_attempts_by_payment_intent_id(&request.payment_intent_id,diff --git a/crates/router/src/core/revenue_recovery.rs b/crates/router/src/core/revenue_recovery.rsindex efcdf5ae99..d9c01af043 100644--- a/crates/router/src/core/revenue_recovery.rs+++ b/crates/router/src/core/revenue_recovery.rs@@ -56,6 +56,7 @@ use crate::{},transformers::{ForeignFrom, ForeignInto},},+ utils,workflows::revenue_recovery as revenue_recovery_workflow,};pub const CALCULATE_WORKFLOW: &str = "CALCULATE_WORKFLOW";@@ -1492,6 +1493,8 @@ async fn insert_execute_pcr_task_to_pt(pub async fn retrieve_revenue_recovery_process_tracker(state: SessionState,+ platform: domain::Platform,+ profile: domain::Profile,id: GlobalPaymentId,) -> RouterResponse<revenue_recovery::RevenueRecoveryResponse> {let db = &*state.store;@@ -1516,6 +1519,18 @@ pub async fn retrieve_revenue_recovery_process_tracker(.change_context(errors::ApiErrorResponse::InternalServerError).attach_printable("unable to deserialize Pcr Workflow Tracking Data")?;+ // The process tracker is looked up by payment id alone, so make sure it belongs to the caller+ if !utils::is_owned_by_merchant_and_profile(+ &platform,+ &profile,+ &tracking_data.merchant_id,+ &tracking_data.profile_id,+ ) {+ return Err(report!(errors::ApiErrorResponse::GenericNotFoundError {+ message: "Entry For the following id doesn't exists".to_owned(),+ }));+ }+let psync_task = PSYNC_WORKFLOW;let process_tracker_id_for_psync = tracking_datadiff --git a/crates/router/src/routes/process_tracker/revenue_recovery.rs b/crates/router/src/routes/process_tracker/revenue_recovery.rsindex a65ef5f1d7..3a61ce35eb 100644--- a/crates/router/src/routes/process_tracker/revenue_recovery.rs+++ b/crates/router/src/routes/process_tracker/revenue_recovery.rs@@ -24,9 +24,11 @@ pub async fn revenue_recovery_pt_retrieve_api(state,&req,payload,- |state, _: (), id, _| {+ |state, auth: auth::AuthenticationData, id, _| {revenue_recovery::retrieve_revenue_recovery_process_tracker(state,+ auth.platform,+ auth.profile,id.revenue_recovery_id,)},diff --git a/crates/router/src/utils.rs b/crates/router/src/utils.rsindex e63c1f846b..9bd8068f68 100644--- a/crates/router/src/utils.rs+++ b/crates/router/src/utils.rs@@ -1437,6 +1437,17 @@ pub async fn trigger_refund_outgoing_webhook(todo!()}+/// Checks that a resource fetched by id alone belongs to the authenticated merchant and profile+#[cfg(feature = "v2")]+pub fn is_owned_by_merchant_and_profile(+ platform: &domain::Platform,+ profile: &domain::Profile,+ merchant_id: &id_type::MerchantId,+ profile_id: &id_type::ProfileId,+) -> bool {+ merchant_id == platform.get_processor().get_account().get_id() && profile_id == profile.get_id()+}+pub fn get_locale_from_header(headers: &actix_web::http::header::HeaderMap) -> String {get_header_value_by_key(ACCEPT_LANGUAGE.into(), headers).ok()