Skip to content

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

feat(routing): authenticate Decision Engine calls with x-admin-secret (#13539)

Prajjwal Kumar6de35e4e00eb
diff --git a/config/config.example.toml b/config/config.example.toml
index 2c63abcdb9..9100d7f078 100644
--- a/config/config.example.toml
+++ b/config/config.example.toml
@@ -1425,6 +1425,7 @@ dynamic_routing_enabled = true # Enable or disable Open
static_routing_enabled = true # Enable or disable Open Router for static routing
url = "http://localhost:8080" # Open Router URL
dashboard_url = "http://localhost:5173" # Decision Engine dashboard (browser) URL for merchant SSO redirect
+admin_secret = "" # Shared secret sent as x-admin-secret on Decision Engine admin endpoints; empty disables the header
[grpc_client.unified_connector_service]
base_url = "http://localhost:8000" # Unified Connector Service Base URL
diff --git a/config/development.toml b/config/development.toml
index 9dd761faba..219115a05b 100644
--- a/config/development.toml
+++ b/config/development.toml
@@ -1561,6 +1561,7 @@ dynamic_routing_enabled = false
static_routing_enabled = false
url = "http://localhost:8080"
dashboard_url = "http://localhost:5173"
+admin_secret = ""
[l2_l3_data_config]
enabled = "true"
diff --git a/crates/router/src/configs/secrets_transformers.rs b/crates/router/src/configs/secrets_transformers.rs
index 0e44aff462..41105c50d5 100644
--- a/crates/router/src/configs/secrets_transformers.rs
+++ b/crates/router/src/configs/secrets_transformers.rs
@@ -4,6 +4,7 @@ use hyperswitch_interfaces::secrets_interface::{
secret_state::{RawSecret, SecretStateContainer, SecuredSecret},
SecretManagementInterface, SecretsManagementError,
};
+use hyperswitch_masking::PeekInterface;
use crate::settings::{self, Settings};
@@ -630,6 +631,18 @@ pub(crate) async fn fetch_raw_secrets(
None
};
+ #[allow(clippy::expect_used)]
+ let open_router = {
+ let mut open_router = conf.open_router;
+ if !open_router.admin_secret.peek().is_empty() {
+ open_router.admin_secret = secret_management_client
+ .get_secret(open_router.admin_secret)
+ .await
+ .expect("Failed to decrypt open router admin secret");
+ }
+ open_router
+ };
+
Settings {
server: conf.server,
application_source: conf.application_source,
@@ -734,7 +747,7 @@ pub(crate) async fn fetch_raw_secrets(
platform: conf.platform,
l2_l3_data_config: conf.l2_l3_data_config,
authentication_providers: conf.authentication_providers,
- open_router: conf.open_router,
+ open_router,
#[cfg(feature = "v2")]
revenue_recovery: conf.revenue_recovery,
merchant_advice_codes: conf.merchant_advice_codes,
diff --git a/crates/router/src/configs/settings.rs b/crates/router/src/configs/settings.rs
index 573f50c1b8..e760d28e60 100644
--- a/crates/router/src/configs/settings.rs
+++ b/crates/router/src/configs/settings.rs
@@ -421,6 +421,12 @@ pub struct OpenRouter {
/// Browser-facing Decision Engine dashboard base URL, used for the merchant SSO redirect.
#[serde(default)]
pub dashboard_url: String,
+ /// Shared secret sent as the `x-admin-secret` header on Decision Engine requests. The DE
+ /// verifies it on admin endpoints (merchant provisioning, SSO code mint) and accepts it as
+ /// service-to-service auth on its protected routes. Decrypted via secrets management when
+ /// enabled; empty disables the header.
+ #[serde(default)]
+ pub admin_secret: Secret<String>,
}
#[derive(Debug, Deserialize, Clone, Default)]
diff --git a/crates/router/src/core/payments/routing/utils.rs b/crates/router/src/core/payments/routing/utils.rs
index a8949db157..aea7b6841e 100644
--- a/crates/router/src/core/payments/routing/utils.rs
+++ b/crates/router/src/core/payments/routing/utils.rs
@@ -29,6 +29,7 @@ use euclid::{
use external_services::grpc_client::dynamic_routing as ir_client;
use hyperswitch_domain_models::business_profile;
use hyperswitch_interfaces::events::routing_api_logs as routing_events;
+use hyperswitch_masking::{Mask, PeekInterface};
use router_env::RequestId;
use serde::{Deserialize, Serialize};
@@ -158,6 +159,8 @@ impl DecisionEngineEndpoint {
}
}
+const DECISION_ENGINE_ADMIN_SECRET_HEADER: &str = "x-admin-secret";
+
pub async fn build_and_send_decision_engine_http_request<Req, Res, ErrRes>(
state: &SessionState,
http_method: services::Method,
@@ -180,6 +183,18 @@ where
.method(http_method)
.url(&url);
+ // The Decision Engine authenticates Hyperswitch via a shared admin secret: its admin
+ // endpoints (merchant provisioning, SSO code mint) verify the header in the handler, and
+ // its protected router accepts it as service-to-service auth. Attach it on every call
+ // when configured; an empty secret omits the header.
+ let admin_secret = &state.conf.open_router.admin_secret;
+ if !admin_secret.peek().is_empty() {
+ request_builder = request_builder.headers(vec![(
+ DECISION_ENGINE_ADMIN_SECRET_HEADER.to_string(),
+ admin_secret.clone().into_masked(),
+ )]);
+ }
+
if let Some(body_content) = request_body {
let body = common_utils::request::RequestContent::Json(Box::new(body_content));
request_builder = request_builder.set_body(body);
@@ -297,9 +312,10 @@ where
.trigger_event(state, closure)
.await?
} else {
- let resp = closure()
- .await
- .change_context(errors::RoutingError::OpenRouterCallFailed)?;
+ // Keep the closure's error context (e.g. `RoutingEventsError` carrying the DE status
+ // code) so callers can react to specific statuses, like the 404-gated merchant
+ // provisioning in the SSO mint flow.
+ let resp = closure().await?;
RoutingEventsResponse::new(None, resp)
};