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(router): enforce V2 management endpoint profile scope (#15116)
Ayush Anand5949f501563f
diff --git a/api-reference/v2/openapi_spec_v2.json b/api-reference/v2/openapi_spec_v2.jsonindex 1727c9307a..e5345881b3 100644--- a/api-reference/v2/openapi_spec_v2.json+++ b/api-reference/v2/openapi_spec_v2.json@@ -216,6 +216,26 @@"summary": "Connector Account - Create","description": "Creates a new Connector Account for the merchant account. The connector could be a payment processor/facilitator/acquirer or a provider of specialized services like Fraud/Accounting etc.","operationId": "Create a Merchant Connector",+ "parameters": [+ {+ "name": "X-Merchant-Id",+ "in": "header",+ "description": "Merchant ID of the connector account.",+ "required": true,+ "schema": {+ "type": "string"+ }+ },+ {+ "name": "X-Profile-Id",+ "in": "header",+ "description": "Authenticated business profile. Must match profile_id in the request body.",+ "required": true,+ "schema": {+ "type": "string"+ }+ }+ ],"requestBody": {"content": {"application/json": {@@ -232,7 +252,8 @@},"connector_label": "EU_adyen","connector_name": "adyen",- "connector_type": "payment_processor"+ "connector_type": "payment_processor",+ "profile_id": "{{profile_id}}"}},"Create a merchant connector account under a specific profile": {@@ -255,7 +276,8 @@"key1": "{{adyen_merchant_account}}"},"connector_name": "adyen",- "connector_type": "payment_processor"+ "connector_type": "payment_processor",+ "profile_id": "{{profile_id}}"}}}@@ -275,12 +297,15 @@}},"400": {- "description": "Missing Mandatory fields"+ "description": "Missing mandatory fields or profile_id does not match X-Profile-Id"}},"security": [{"admin_api_key": []+ },+ {+ "jwt_key": []}]}@@ -885,6 +910,15 @@"example": {"X-Merchant-Id": "abc_iG5VNjsN9xuCg7Xx0uWh"}+ },+ {+ "name": "X-Profile-Id",+ "in": "header",+ "description": "Authenticated business profile. Must match the profile ID in the path.",+ "required": true,+ "schema": {+ "type": "string"+ }}],"responses": {@@ -901,6 +935,9 @@}}},+ "400": {+ "description": "Path profile ID does not match X-Profile-Id"+ },"401": {"description": "Unauthorized request"},@@ -911,6 +948,9 @@"security": [{"admin_api_key": []+ },+ {+ "jwt_key": []}]}@@ -2642,14 +2682,14 @@"Payments"],"summary": "Payments - List",- "description": "To list the *payments*",+ "description": "List payments and their total count within the authenticated X-Profile-Id.\nAn optional profile_id query filter must match X-Profile-Id.","operationId": "List all Payments","parameters": [{"name": "payment_id",- "in": "path",+ "in": "query","description": "The identifier for payment",- "required": true,+ "required": false,"schema": {"type": "string","nullable": true@@ -2658,20 +2698,20 @@},{"name": "profile_id",- "in": "path",- "description": "The identifier for business profile",- "required": true,+ "in": "query",+ "description": "Optional business-profile filter. Must match the authenticated X-Profile-Id header.",+ "required": false,"schema": {"type": "string","nullable": true},- "example": "pay_fafa124123"+ "example": "pro_abcdefgh12345678"},{"name": "customer_id",- "in": "path",+ "in": "query","description": "The identifier for customer",- "required": true,+ "required": false,"schema": {"type": "string","nullable": true,@@ -2682,9 +2722,9 @@},{"name": "starting_after",- "in": "path",+ "in": "query","description": "A cursor for use in pagination, fetch the next list after some object",- "required": true,+ "required": false,"schema": {"type": "string","nullable": true@@ -2693,9 +2733,9 @@},{"name": "ending_before",- "in": "path",+ "in": "query","description": "A cursor for use in pagination, fetch the previous list before some object",- "required": true,+ "required": false,"schema": {"type": "string","nullable": true@@ -2704,27 +2744,27 @@},{"name": "limit",- "in": "path",+ "in": "query","description": "limit on the number of objects to return",- "required": true,+ "required": false,"schema": {"$ref": "#/components/schemas/common_utils.types.list.PageSize"}},{"name": "offset",- "in": "path",+ "in": "query","description": "The starting point within a list of objects",- "required": true,+ "required": false,"schema": {"$ref": "#/components/schemas/common_utils.types.list.PageOffset"}},{"name": "created",- "in": "path",+ "in": "query","description": "The time at which payment is created",- "required": true,+ "required": false,"schema": {"type": "string","format": "date-time",@@ -2734,9 +2774,9 @@},{"name": "created.lt",- "in": "path",+ "in": "query","description": "Time less than the payment created time",- "required": true,+ "required": false,"schema": {"type": "string","format": "date-time",@@ -2746,9 +2786,9 @@},{"name": "created.gt",- "in": "path",+ "in": "query","description": "Time greater than the payment created time",- "required": true,+ "required": false,"schema": {"type": "string","format": "date-time",@@ -2758,9 +2798,9 @@},{"name": "created.lte",- "in": "path",+ "in": "query","description": "Time less than or equals to the payment created time",- "required": true,+ "required": false,"schema": {"type": "string","format": "date-time",@@ -2770,9 +2810,9 @@},{"name": "created.gte",- "in": "path",+ "in": "query","description": "Time greater than or equals to the payment created time",- "required": true,+ "required": false,"schema": {"type": "string","format": "date-time",@@ -2782,9 +2822,9 @@},{"name": "start_amount",- "in": "path",+ "in": "query","description": "The start amount to filter list of transactions which are greater than or equal to the start amount",- "required": true,+ "required": false,"schema": {"type": "integer","format": "int64",@@ -2793,9 +2833,9 @@},{"name": "end_amount",- "in": "path",+ "in": "query","description": "The end amount to filter list of transactions which are less than or equal to the end amount",- "required": true,+ "required": false,"schema": {"type": "integer","format": "int64",@@ -2804,9 +2844,9 @@},{"name": "connector",- "in": "path",+ "in": "query","description": "The connector to filter payments list",- "required": true,+ "required": false,"schema": {"type": "array","items": {@@ -2817,9 +2857,9 @@},{"name": "currency",- "in": "path",+ "in": "query","description": "The currency to filter payments list",- "required": true,+ "required": false,"schema": {"type": "array","items": {@@ -2830,9 +2870,9 @@},{"name": "status",- "in": "path",+ "in": "query","description": "The payment status to filter payments list",- "required": true,+ "required": false,"schema": {"type": "array","items": {@@ -2843,9 +2883,9 @@},{"name": "payment_method_type",- "in": "path",+ "in": "query","description": "The payment method type to filter payments list",- "required": true,+ "required": false,"schema": {"type": "array","items": {@@ -2856,9 +2896,9 @@},{"name": "payment_method_subtype",- "in": "path",+ "in": "query","description": "The payment method subtype to filter payments list",- "required": true,+ "required": false,"schema": {"type": "array","items": {@@ -2869,9 +2909,9 @@},{"name": "authentication_type",- "in": "path",+ "in": "query","description": "The authentication type to filter payments list",- "required": true,+ "required": false,"schema": {"type": "array","items": {@@ -2882,9 +2922,9 @@},{"name": "merchant_connector_id",- "in": "path",+ "in": "query","description": "The merchant connector id to filter payments list",- "required": true,+ "required": false,"schema": {"type": "array","items": {@@ -2895,27 +2935,27 @@},{"name": "order_on",- "in": "path",+ "in": "query","description": "The field on which the payments list should be sorted",- "required": true,+ "required": false,"schema": {"$ref": "#/components/schemas/SortOn"}},{"name": "order_by",- "in": "path",+ "in": "query","description": "The order in which payments list should be sorted",- "required": true,+ "required": false,"schema": {"$ref": "#/components/schemas/SortBy"}},{"name": "card_network",- "in": "path",+ "in": "query","description": "The card networks to filter payments list",- "required": true,+ "required": false,"schema": {"type": "array","items": {@@ -2926,13 +2966,22 @@},{"name": "merchant_order_reference_id",- "in": "path",+ "in": "query","description": "The identifier for merchant order reference id",- "required": true,+ "required": false,"schema": {"type": "string","nullable": true}+ },+ {+ "name": "X-Profile-Id",+ "in": "header",+ "description": "Authenticated business profile used to scope payment rows and total_count.",+ "required": true,+ "schema": {+ "type": "string"+ }}],"responses": {@@ -2946,6 +2995,9 @@}}},+ "400": {+ "description": "Query profile_id does not match X-Profile-Id"+ },"404": {"description": "No payments found"}diff --git a/crates/api_models/src/payments.rs b/crates/api_models/src/payments.rsindex eaae10ce91..15307e15fc 100644--- a/crates/api_models/src/payments.rs+++ b/crates/api_models/src/payments.rs@@ -9395,14 +9395,15 @@ pub struct PaymentListConstraints {#[cfg(feature = "v2")]#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, utoipa::IntoParams)]+#[into_params(parameter_in = Query)]#[serde(deny_unknown_fields)]pub struct PaymentListConstraints {/// The identifier for payment#[param(example = "pay_fafa124123", value_type = Option<String>)]pub payment_id: Option<id_type::GlobalPaymentId>,- /// The identifier for business profile- #[param(example = "pay_fafa124123", value_type = Option<String>)]+ /// Optional business-profile filter. Must match the authenticated X-Profile-Id header.+ #[param(example = "pro_abcdefgh12345678", value_type = Option<String>)]pub profile_id: Option<id_type::ProfileId>,/// The identifier for customerdiff --git a/crates/openapi/src/routes/merchant_connector_account.rs b/crates/openapi/src/routes/merchant_connector_account.rsindex 5c51fab174..e463195c5c 100644--- a/crates/openapi/src/routes/merchant_connector_account.rs+++ b/crates/openapi/src/routes/merchant_connector_account.rs@@ -71,6 +71,10 @@ pub async fn connector_create() {}#[utoipa::path(post,path = "/v2/connector-accounts",+ params(+ ("X-Merchant-Id" = String, Header, description = "Merchant ID of the connector account."),+ ("X-Profile-Id" = String, Header, description = "Authenticated business profile. Must match profile_id in the request body."),+ ),request_body(content = MerchantConnectorCreate,examples(@@ -79,6 +83,7 @@ pub async fn connector_create() {}value = json!({"connector_type": "payment_processor","connector_name": "adyen",+ "profile_id": "{{profile_id}}","connector_account_details": {"auth_type": "BodyKey","api_key": "{{adyen-api-key}}",@@ -107,6 +112,7 @@ pub async fn connector_create() {}"connector_type": "payment_processor","connector_name": "adyen","connector_label": "EU_adyen",+ "profile_id": "{{profile_id}}","connector_account_details": {"auth_type": "BodyKey","api_key": "{{adyen-api-key}}",@@ -119,11 +125,11 @@ pub async fn connector_create() {}),responses((status = 200, description = "Merchant Connector Created", body = MerchantConnectorResponse),- (status = 400, description = "Missing Mandatory fields"),+ (status = 400, description = "Missing mandatory fields or profile_id does not match X-Profile-Id"),),tag = "Merchant Connector Account",operation_id = "Create a Merchant Connector",- security(("admin_api_key" = []))+ security(("admin_api_key" = []), ("jwt_key" = [])))]pub async fn connector_create() {}diff --git a/crates/openapi/src/routes/payments.rs b/crates/openapi/src/routes/payments.rsindex d1cb551a35..83f9e9b450 100644--- a/crates/openapi/src/routes/payments.rs+++ b/crates/openapi/src/routes/payments.rs@@ -1599,14 +1599,19 @@ pub fn list_payment_methods() {}/// Payments - List///-/// To list the *payments*+/// List payments and their total count within the authenticated X-Profile-Id.+/// An optional profile_id query filter must match X-Profile-Id.#[cfg(feature = "v2")]#[utoipa::path(get,path = "/v2/payments/list",- params(api_models::payments::PaymentListConstraints),+ params(+ api_models::payments::PaymentListConstraints,+ ("X-Profile-Id" = String, Header, description = "Authenticated business profile used to scope payment rows and total_count."),+ ),responses((status = 200, description = "Successfully retrieved a payment list", body = PaymentListResponse),+ (status = 400, description = "Query profile_id does not match X-Profile-Id"),(status = 404, description = "No payments found")),tag = "Payments",diff --git a/crates/openapi/src/routes/profile.rs b/crates/openapi/src/routes/profile.rsindex 265e26f520..3bbfcfa213 100644--- a/crates/openapi/src/routes/profile.rs+++ b/crates/openapi/src/routes/profile.rs@@ -361,15 +361,17 @@ pub async fn routing_retrieve_default_config() {}description = "Merchant ID of the profile.",example = json!({"X-Merchant-Id": "abc_iG5VNjsN9xuCg7Xx0uWh"})),+ ("X-Profile-Id" = String, Header, description = "Authenticated business profile. Must match the profile ID in the path."),),responses((status = 200, description = "Merchant Connector list retrieved successfully", body = Vec<MerchantConnectorResponse>),+ (status = 400, description = "Path profile ID does not match X-Profile-Id"),(status = 404, description = "Merchant Connector does not exist in records"),(status = 401, description = "Unauthorized request")),tag = "Business Profile",operation_id = "List all Merchant Connectors for Profile",- security(("admin_api_key" = []))+ security(("admin_api_key" = []), ("jwt_key" = [])))]#[cfg(feature = "v2")]pub async fn connector_list() {}diff --git a/crates/router/src/core/admin.rs b/crates/router/src/core/admin.rsindex 7cd5b79d29..23fdd43619 100644--- a/crates/router/src/core/admin.rs+++ b/crates/router/src/core/admin.rs@@ -2823,6 +2823,7 @@ pub async fn create_connector(.clone().validate_and_get_business_profile(&processor, store).await?;+ core_utils::validate_profile_id_from_auth_layer(auth_profile_id, &business_profile)?;#[cfg(feature = "v2")]if req.connector_type == common_enums::ConnectorType::BillingProcessor {@@ -2836,7 +2837,6 @@ pub async fn create_connector().await?;}- core_utils::validate_profile_id_from_auth_layer(auth_profile_id, &business_profile)?;let pm_auth_config_validation = PMAuthConfigValidation {connector_type: &req.connector_type,diff --git a/crates/router/src/routes/admin.rs b/crates/router/src/routes/admin.rsindex 441559e35d..d479b44659 100644--- a/crates/router/src/routes/admin.rs+++ b/crates/router/src/routes/admin.rs@@ -632,7 +632,7 @@ pub async fn connector_create(state,req,auth_data.platform.get_processor().clone(),- None,+ Some(auth_data.profile.get_id().clone()),)).await},@@ -751,13 +751,14 @@ pub async fn connector_list(flow,state,&req,- profile_id.to_owned(),- |state, auth: auth::AuthenticationData, _, _| {- list_connectors_for_a_profile(- state,- auth.platform.get_processor().clone(),- profile_id.clone(),- )+ profile_id,+ |state, auth: auth::AuthenticationData, profile_id, _| async move {+ crate::core::utils::validate_profile_id_from_auth_layer(+ Some(profile_id.clone()),+ &auth.profile,+ )?;+ list_connectors_for_a_profile(state, auth.platform.get_processor().clone(), profile_id)+ .await},auth::auth_type(&auth::AdminApiAuthWithMerchantIdFromHeader,diff --git a/crates/router/src/routes/payments.rs b/crates/router/src/routes/payments.rsindex fdc38e2ce3..55eae3d8d2 100644--- a/crates/router/src/routes/payments.rs+++ b/crates/router/src/routes/payments.rs@@ -2373,8 +2373,15 @@ pub async fn revenue_recovery_invoices_list(state,&req,payload,- |state, auth: auth::AuthenticationData, req, _| {- payments::list::revenue_recovery_list_payments(state, auth.platform, req)+ |state, auth: auth::AuthenticationData, mut req, _| async move {+ if let Some(profile_id) = req.profile_id.take() {+ crate::core::utils::validate_profile_id_from_auth_layer(+ Some(profile_id),+ &auth.profile,+ )?;+ }+ req.profile_id = Some(auth.profile.get_id().clone());+ payments::list::revenue_recovery_list_payments(state, auth.platform, req).await},auth::auth_type(&auth::V2ApiKeyAuth {@@ -2406,8 +2413,15 @@ pub async fn payments_list(state,&req,payload,- |state, auth: auth::AuthenticationData, req, _| {- payments::list::list_payments(state, auth.platform, req)+ |state, auth: auth::AuthenticationData, mut req, _| async move {+ if let Some(profile_id) = req.profile_id.take() {+ crate::core::utils::validate_profile_id_from_auth_layer(+ Some(profile_id),+ &auth.profile,+ )?;+ }+ req.profile_id = Some(auth.profile.get_id().clone());+ payments::list::list_payments(state, auth.platform, req).await},auth::auth_type(&auth::V2ApiKeyAuth {