mirror of
https://github.com/juspay/hyperswitch.git
synced 2025-10-30 01:27:31 +08:00
feat(payout_link): secure payout links using server side validations and client side headers (#5219)
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
use std::collections::HashMap;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
#[cfg(feature = "v2")]
|
||||
use common_utils::new_type;
|
||||
@ -1390,11 +1390,39 @@ pub struct BusinessGenericLinkConfig {
|
||||
/// Custom domain name to be used for hosting the link
|
||||
pub domain_name: Option<String>,
|
||||
|
||||
/// A list of allowed domains (glob patterns) where this link can be embedded / opened from
|
||||
pub allowed_domains: HashSet<String>,
|
||||
|
||||
#[serde(flatten)]
|
||||
#[schema(value_type = GenericLinkUiConfig)]
|
||||
pub ui_config: link_utils::GenericLinkUiConfig,
|
||||
}
|
||||
|
||||
impl BusinessGenericLinkConfig {
|
||||
pub fn validate(&self) -> Result<(), &str> {
|
||||
// Validate host domain name
|
||||
let host_domain_valid = self
|
||||
.domain_name
|
||||
.clone()
|
||||
.map(|host_domain| link_utils::validate_strict_domain(&host_domain))
|
||||
.unwrap_or(true);
|
||||
if !host_domain_valid {
|
||||
return Err("Invalid host domain name received");
|
||||
}
|
||||
|
||||
let are_allowed_domains_valid = self
|
||||
.allowed_domains
|
||||
.clone()
|
||||
.iter()
|
||||
.all(|allowed_domain| link_utils::validate_wildcard_domain(allowed_domain));
|
||||
if !are_allowed_domains_valid {
|
||||
return Err("Invalid allowed domain names received");
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, serde::Deserialize, serde::Serialize, PartialEq, ToSchema)]
|
||||
pub struct BusinessPaymentLinkConfig {
|
||||
/// Custom domain name to be used for hosting the link in your own domain
|
||||
|
||||
Reference in New Issue
Block a user