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(webhooks): respect role scope when listing events so merchant users can search across profiles (#12214)
Venu Madhav Bandarupalli55d48b684acc
diff --git a/crates/router/src/routes/webhook_events.rs b/crates/router/src/routes/webhook_events.rsindex f85389a409..104a9c8dd9 100644--- a/crates/router/src/routes/webhook_events.rs+++ b/crates/router/src/routes/webhook_events.rs@@ -1,13 +1,15 @@use actix_web::{web, HttpRequest, Responder};+use common_enums::EntityType;+use error_stack::ResultExt;use router_env::{instrument, tracing, Flow};use crate::{- core::{api_locking, webhooks::webhook_events},+ core::{api_locking, errors, webhooks::webhook_events},routes::AppState,services::{api,authentication::{self as auth, UserFromToken},- authorization::permissions::Permission,+ authorization::{permissions::Permission, roles::RoleInfo},},types::api::webhook_events::{EventListConstraints, EventListRequestInternal, WebhookDeliveryAttemptListRequestInternal,@@ -77,18 +79,34 @@ pub async fn list_initial_webhook_delivery_attempts_with_jwtauth(state,&req,request_internal,- |state, auth: UserFromToken, mut request_internal, _| {- let merchant_id = auth.merchant_id;- let profile_id = auth.profile_id;+ |state, auth: UserFromToken, request_internal, _| async move {+ let role_info = RoleInfo::from_role_id_org_id_tenant_id(+ &state,+ &auth.role_id,+ &auth.org_id,+ auth.tenant_id.as_ref().unwrap_or(&state.tenant.tenant_id),+ )+ .await+ .change_context(errors::ApiErrorResponse::InternalServerError)+ .attach_printable("Failed to fetch role info while listing webhook events")?;- request_internal.merchant_id = merchant_id;- request_internal.constraints.profile_id = Some(profile_id);+ // Merchant-or-higher scopes search across all profiles in the merchant;+ // profile-scoped users stay confined to their JWT's profile_id.+ let request_internal = EventListRequestInternal {+ merchant_id: auth.merchant_id,+ constraints: EventListConstraints {+ profile_id: (role_info.get_entity_type() == EntityType::Profile)+ .then_some(auth.profile_id),+ ..request_internal.constraints+ },+ };webhook_events::list_initial_delivery_attempts(state,request_internal.merchant_id,request_internal.constraints,)+ .await},&auth::JWTAuth {permission: Permission::ProfileWebhookEventRead,