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(paymentlink): fixed wrongly flagged XSS or SQLi attack for payment links (#13283)
Sahkal Poddar9cc573da61a0
diff --git a/Cargo.lock b/Cargo.lockindex fa9b5fd573..5023ef0295 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -1258,7 +1258,7 @@ version = "1.3.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "40076bd09fadbc12d5e026ae080d0930defa606856186e31d83ccc6a255eeaf3"dependencies = [- "base64-simd",+ "base64-simd 0.8.0","bytes 1.10.1","bytes-utils","futures-core",@@ -1469,13 +1469,22 @@ version = "0.8.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "77c6d128af408d8ebd08331f0331cf2cf20d19e6c44a7aec58791641ecc8c0b5"+[[package]]+name = "base64-simd"+version = "0.7.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "781dd20c3aff0bd194fe7d2a977dd92f21c173891f3a03b677359e5fa457e5d5"+dependencies = [+ "simd-abstraction",+]+[[package]]name = "base64-simd"version = "0.8.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "339abbe78e73178762e23bea9dfd08e697eb3f3301cd4be981c0f78ba5859195"dependencies = [- "outref",+ "outref 0.5.1","vsimd",]@@ -2310,6 +2319,26 @@ dependencies = ["tiny-keccak",]+[[package]]+name = "const-str"+version = "0.3.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "21077772762a1002bb421c3af42ac1725fa56066bfc53d9a55bb79905df2aaf3"+dependencies = [+ "const-str-proc-macro",+]++[[package]]+name = "const-str-proc-macro"+version = "0.3.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "5e1e0fdd2e5d3041e530e1b21158aeeef8b5d0e306bc5c1e3d6cf0930d10e25a"+dependencies = [+ "proc-macro2",+ "quote",+ "syn 1.0.109",+]+[[package]]name = "constant_time_eq"version = "0.3.1"@@ -2617,6 +2646,38 @@ dependencies = ["typenum",]+[[package]]+name = "cssparser"+version = "0.33.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9be934d936a0fbed5bcdc01042b770de1398bf79d0e192f49fa7faea0e99281e"+dependencies = [+ "cssparser-macros",+ "dtoa-short",+ "itoa",+ "phf 0.11.2",+ "smallvec 1.15.0",+]++[[package]]+name = "cssparser-color"+version = "0.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "556c099a61d85989d7af52b692e35a8d68a57e7df8c6d07563dc0778b3960c9f"+dependencies = [+ "cssparser",+]++[[package]]+name = "cssparser-macros"+version = "0.6.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331"+dependencies = [+ "quote",+ "syn 2.0.101",+]+[[package]]name = "csv"version = "1.3.1"@@ -2746,12 +2807,34 @@ dependencies = ["syn 2.0.101",]+[[package]]+name = "dashmap"+version = "5.5.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "978747c1d849a7d2ee5e8adc0159961c48fb7e5db2f06af6723b80123bb53856"+dependencies = [+ "cfg-if 1.0.0",+ "hashbrown 0.14.5",+ "lock_api 0.4.12",+ "once_cell",+ "parking_lot_core 0.9.10",+]+[[package]]name = "data-encoding"version = "2.6.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "e8566979429cf69b49a5c740c60791108e86440e8be149bbea4fe54d2c32d6e2"+[[package]]+name = "data-url"+version = "0.1.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "3a30bfce702bcfa94e906ef82421f2c0e61c076ad76030c16ee5d2e9a32fe193"+dependencies = [+ "matches",+]+[[package]]name = "deadpool"version = "0.10.0"@@ -3077,6 +3160,21 @@ dependencies = ["syn 2.0.101",]+[[package]]+name = "dtoa"+version = "1.0.11"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "4c3cf4824e2d5f025c7b531afcb2325364084a16806f6d47fbc1f5fbd9960590"++[[package]]+name = "dtoa-short"+version = "0.3.5"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87"+dependencies = [+ "dtoa",+]+[[package]]name = "dunce"version = "1.0.5"@@ -5382,6 +5480,46 @@ dependencies = ["vcpkg",]+[[package]]+name = "lightningcss"+version = "1.0.0-alpha.71"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "cb6314c2f0590ac93c86099b98bb7ba8abcf759bfd89604ffca906472bb54937"+dependencies = [+ "ahash 0.8.11",+ "bitflags 2.9.0",+ "const-str",+ "cssparser",+ "cssparser-color",+ "dashmap",+ "data-encoding",+ "getrandom 0.3.3",+ "indexmap 2.9.0",+ "itertools 0.10.5",+ "lazy_static",+ "lightningcss-derive",+ "parcel_selectors",+ "parcel_sourcemap",+ "pastey",+ "pathdiff",+ "rayon",+ "serde",+ "serde-content",+ "smallvec 1.15.0",+]++[[package]]+name = "lightningcss-derive"+version = "1.0.0-alpha.43"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "84c12744d1279367caed41739ef094c325d53fb0ffcd4f9b84a368796f870252"+dependencies = [+ "convert_case 0.6.0",+ "proc-macro2",+ "quote",+ "syn 1.0.109",+]+[[package]]name = "linked-hash-map"version = "0.5.6"@@ -6419,6 +6557,12 @@ version = "6.6.1"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1"+[[package]]+name = "outref"+version = "0.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "7f222829ae9293e33a9f5e9f440c6760a3d450a64affe1846486b140db81c1f4"+[[package]]name = "outref"version = "0.5.1"@@ -6466,6 +6610,36 @@ dependencies = ["sha2",]+[[package]]+name = "parcel_selectors"+version = "0.28.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "54fd03f1ad26cb6b3ec1b7414fa78a3bd639e7dbb421b1a60513c96ce886a196"+dependencies = [+ "bitflags 2.9.0",+ "cssparser",+ "log 0.4.27",+ "phf 0.11.2",+ "phf_codegen 0.11.2",+ "precomputed-hash",+ "rustc-hash 2.1.1",+ "smallvec 1.15.0",+]++[[package]]+name = "parcel_sourcemap"+version = "2.1.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "485b74d7218068b2b7c0e3ff12fbc61ae11d57cb5d8224f525bd304c6be05bbb"+dependencies = [+ "base64-simd 0.7.0",+ "data-url",+ "rkyv",+ "serde",+ "serde_json",+ "vlq",+]+[[package]]name = "parking"version = "2.2.1"@@ -6553,6 +6727,12 @@ version = "1.0.15"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a"+[[package]]+name = "pastey"+version = "0.1.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "35fb2e5f958ec131621fdd531e9fc186ed768cbe395337403ae56c17a74c68ec"+[[package]]name = "pathdiff"version = "0.2.1"@@ -6567,6 +6747,7 @@ dependencies = ["common_utils","error-stack 0.4.1","getrandom 0.3.3",+ "lightningcss","router_env","serde","serde_json",@@ -6729,6 +6910,7 @@ version = "0.11.2"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc"dependencies = [+ "phf_macros","phf_shared 0.11.2",]@@ -6792,6 +6974,19 @@ dependencies = ["rand 0.8.5",]+[[package]]+name = "phf_macros"+version = "0.11.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "f84ac04429c13a7ff43785d75ad27569f2951ce0ffd30a3321230db2fc727216"+dependencies = [+ "phf_generator 0.11.2",+ "phf_shared 0.11.2",+ "proc-macro2",+ "quote",+ "syn 2.0.101",+]+[[package]]name = "phf_shared"version = "0.7.24"@@ -6836,7 +7031,7 @@ dependencies = ["regex-cache","serde","serde_derive",- "strum 0.25.0",+ "strum 0.26.3","thiserror 1.0.69",]@@ -8730,6 +8925,15 @@ dependencies = ["serde_derive",]+[[package]]+name = "serde-content"+version = "0.1.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "3753ca04f350fa92d00b6146a3555e63c55388c9ef2e11e09bce2ff1c0b509c6"+dependencies = [+ "serde",+]+[[package]]name = "serde-value"version = "0.7.0"@@ -9032,6 +9236,15 @@ dependencies = ["rand_core 0.6.4",]+[[package]]+name = "simd-abstraction"+version = "0.7.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "9cadb29c57caadc51ff8346233b5cec1d240b68ce55cf1afc764818791876987"+dependencies = [+ "outref 0.1.0",+]+[[package]]name = "simd-adler32"version = "0.3.7"@@ -11552,6 +11765,12 @@ version = "0.9.5"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"+[[package]]+name = "vlq"+version = "0.5.1"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "65dd7eed29412da847b0f78bcec0ac98588165988a8cfe41d4ea1d429f8ccfff"+[[package]]name = "void"version = "1.0.2"diff --git a/crates/api_models/src/admin.rs b/crates/api_models/src/admin.rsindex 61b9747942..61941078f7 100644--- a/crates/api_models/src/admin.rs+++ b/crates/api_models/src/admin.rs@@ -3600,10 +3600,8 @@ pub struct PaymentLinkConfigRequest {/// Custom background colour for the payment linkpub background_colour: Option<String>,/// SDK configuration rules- #[xss_clean(recurse)]pub sdk_ui_rules: Option<HashMap<String, HashMap<String, String>>>,/// Payment link configuration rules- #[xss_clean(recurse)]pub payment_link_ui_rules: Option<HashMap<String, HashMap<String, String>>>,/// Flag to enable the button only when the payment form is ready for submissionpub enable_button_only_on_form_ready: Option<bool>,@@ -3736,10 +3734,8 @@ pub struct PaymentLinkConfig {/// Custom background colour for the payment linkpub background_colour: Option<String>,/// SDK configuration rules- #[xss_clean(recurse)]pub sdk_ui_rules: Option<HashMap<String, HashMap<String, String>>>,/// Payment link configuration rules- #[xss_clean(recurse)]pub payment_link_ui_rules: Option<HashMap<String, HashMap<String, String>>>,/// Flag to enable the button only when the payment form is ready for submissionpub enable_button_only_on_form_ready: bool,diff --git a/crates/payment_link/Cargo.toml b/crates/payment_link/Cargo.tomlindex 1dbe169bce..aca35bc66c 100644--- a/crates/payment_link/Cargo.toml+++ b/crates/payment_link/Cargo.toml@@ -24,11 +24,13 @@ urlencoding = "2.1.3"error-stack = "0.4.1"thiserror = "1.0.69"wasm-bindgen = { version = "0.2", optional = true }+lightningcss = "1.0.0-alpha.71"# First party cratesapi_models = { path = "../api_models", default-features = false }common_utils = { path = "../common_utils" }getrandom = { version = "0.3", optional = true }+router_env = { path = "../router_env" }[build-dependencies]router_env = { path = "../router_env" }diff --git a/crates/payment_link/src/css_generator.rs b/crates/payment_link/src/css_generator.rsindex 1de2262185..fdf568d426 100644--- a/crates/payment_link/src/css_generator.rs+++ b/crates/payment_link/src/css_generator.rs@@ -1,7 +1,16 @@use std::collections::HashMap;use api_models::admin::PaymentLinkConfig;-use error_stack::{Result, ResultExt};+use error_stack::Result;+use lightningcss::{+ declaration::DeclarationBlock,+ dependencies::DependencyOptions,+ properties::Property,+ rules::CssRule,+ stylesheet::{ParserOptions, PrinterOptions, StyleSheet},+ traits::ToCss,+};+use router_env::logger;#[derive(Debug, thiserror::Error)]pub enum PaymentLinkError {@@ -81,17 +90,186 @@ fn sanitize_color(value: &str) -> Option<String> {}}-fn is_safe_css_token(s: &str) -> bool {- let lower = s.to_ascii_lowercase();-- !s.chars()- .any(|c| matches!(c, '<' | '>' | '{' | '}' | ';' | '"' | '\'' | '\\' | '@'))- && !lower.contains("/*")- && !lower.contains("*/")- && !lower.contains("</")- && !lower.contains("expression(")- && !lower.contains("javascript:")- && !lower.contains("url(")+fn parse_css_declaration(property: &str, value: &str) -> Option<String> {+ let property = property.trim();+ let value = value.trim();+ if property.is_empty() {+ logger::error!("Payment link CSS property is empty");+ None+ } else if value.is_empty() {+ logger::error!(css_property = %property, "Payment link CSS value is empty");+ None+ } else {+ let declaration = format!("{property}: {value};");+ let declaration_block =+ DeclarationBlock::parse_string(&declaration, ParserOptions::default())+ .inspect_err(|error| {+ logger::error!(+ ?error,+ css_property = %property,+ css_value = %value,+ "Failed to parse payment link CSS declaration"+ );+ })+ .ok()?;++ let filtered_property_kinds = filtered_property_kinds(&declaration_block);++ if declaration_block.len() != 1 {+ logger::error!(+ css_property = %property,+ css_value = %value,+ declaration = %declaration,+ parsed_declaration_count = declaration_block.len(),+ "Payment link CSS declaration expanded into an unexpected number of declarations"+ );+ None+ } else if !filtered_property_kinds.is_empty() {+ logger::error!(+ css_property = %property,+ css_value = %value,+ declaration = %declaration,+ ?filtered_property_kinds,+ "Payment link CSS declaration was filtered out because it contains unsupported property kinds"+ );+ None+ } else {+ let serialized_declaration = declaration_block+ .to_css_string(PrinterOptions::default())+ .inspect_err(|error| {+ logger::error!(+ ?error,+ css_property = %property,+ css_value = %value,+ "Failed to serialize payment link CSS declaration"+ );+ })+ .ok()?;+ let probe_rule = format!(":root {{ {serialized_declaration} }}");+ let probe_stylesheet = StyleSheet::parse(&probe_rule, ParserOptions::default())+ .inspect_err(|error| {+ logger::error!(+ ?error,+ css_property = %property,+ css_value = %value,+ serialized_declaration = %serialized_declaration,+ "Failed to validate serialized payment link CSS declaration"+ );+ })+ .ok()?;++ if stylesheet_has_dependencies(&probe_stylesheet) {+ logger::error!(+ css_property = %property,+ css_value = %value,+ serialized_declaration = %serialized_declaration,+ "Payment link CSS declaration was rejected because it generated stylesheet dependencies"+ );+ None+ } else {+ Some(serialized_declaration)+ }+ }+ }+}++fn filtered_property_kinds(declaration_block: &DeclarationBlock<'_>) -> Vec<&'static str> {+ // Surface which parsed property kinds were filtered so unexpected UI changes are easier to debug.+ declaration_block+ .iter()+ .filter_map(|(property, _)| match property {+ Property::Unparsed(_) => Some("unparsed"),+ Property::Custom(_) => Some("custom"),+ _ => None,+ })+ .collect()+}++fn stylesheet_has_dependencies(stylesheet: &StyleSheet<'_, '_>) -> bool {+ stylesheet+ .to_css(PrinterOptions {+ analyze_dependencies: Some(DependencyOptions::default()),+ ..PrinterOptions::default()+ })+ .map(|result| {+ matches!(+ result.dependencies.as_ref(),+ Some(dependencies) if !dependencies.is_empty()+ )+ })+ .unwrap_or(true)+}++fn parse_css_rule(selector: &str, declarations: &[String]) -> Option<String> {+ let selector = selector.trim();+ if selector.is_empty() {+ logger::error!("Payment link CSS selector is empty");+ None+ } else if declarations.is_empty() {+ logger::error!(css_selector = %selector, "Payment link CSS selector has no declarations");+ None+ } else {+ let rule_css = format!("{selector} {{ {} }}", declarations.join("; "));+ let stylesheet = StyleSheet::parse(&rule_css, ParserOptions::default())+ .inspect_err(|error| {+ logger::error!(+ ?error,+ css_selector = %selector,+ rule_css = %rule_css,+ "Failed to parse payment link CSS rule"+ );+ })+ .ok()?;++ // Accept only a single plain style rule that preserves all validated declarations.+ // Example accepted: `body { color: red; }`.+ // Example rejected: `@media screen { body { color: red; } }` or anything that gets+ // rewritten into extra/generated CSS during serialization.+ let valid_style_rule = matches!(+ stylesheet.rules.0.as_slice(),+ [CssRule::Style(style_rule)]+ if style_rule.rules.0.is_empty()+ && style_rule.declarations.len() == declarations.len()+ && !stylesheet_has_dependencies(&stylesheet)+ );++ if valid_style_rule {+ stylesheet+ .to_css(PrinterOptions::default())+ .map(|result| result.code)+ .inspect_err(|error| {+ logger::error!(+ ?error,+ css_selector = %selector,+ rule_css = %rule_css,+ "Failed to serialize payment link CSS rule"+ );+ })+ .ok()+ } else {+ match stylesheet.rules.0.as_slice() {+ [CssRule::Style(style_rule)] => {+ logger::error!(+ css_selector = %selector,+ has_nested_rules = !style_rule.rules.0.is_empty(),+ declaration_count = style_rule.declarations.len(),+ expected_declaration_count = declarations.len(),+ has_dependencies = stylesheet_has_dependencies(&stylesheet),+ "Payment link CSS rule was rejected after validation"+ );+ None+ }+ _ => {+ logger::error!(+ css_selector = %selector,+ parsed_rule_count = stylesheet.rules.0.len(),+ "Payment link CSS selector did not resolve to exactly one style rule"+ );+ None+ }+ }+ }+ }}fn generate_dynamic_css(@@ -103,67 +281,24 @@ fn generate_dynamic_css(let mut css_string = String::new();css_string.push_str("/* Dynamically Injected UI Rules */\n");- rules- .iter()- .try_for_each(|(selector, styles_map)| {- let selector = selector.trim();- if selector.is_empty() {- Err(PaymentLinkError::InvalidCssSelector(- "CSS selector cannot be empty.".to_string(),- ))- .attach_printable("Empty CSS selector found in payment_link_ui_rules")- } else if !is_safe_css_token(selector) {- Err(PaymentLinkError::InvalidCssSelector(format!(- "Unsafe CSS selector: {}",- selector- )))- .attach_printable("Unsafe CSS selector found in payment_link_ui_rules")- } else {- css_string.push_str(selector);- css_string.push_str(" {\n");-- let inner_res =- styles_map- .iter()- .try_for_each(|(prop_camel_case, css_value)| {- let css_property = camel_to_kebab(prop_camel_case);-- // Property names allowlisted to lowercase ascii and dash- if !css_property- .chars()- .all(|c| c.is_ascii_lowercase() || c == '-')- {- Err(PaymentLinkError::InvalidCssProperty(format!(- "Unsafe CSS property: {}",- css_property- )))- .attach_printable(- "Unsafe CSS property found in payment_link_ui_rules",- )- } else if !is_safe_css_token(css_value) {- Err(PaymentLinkError::InvalidCssValue(format!(- "Unsafe CSS value: {}",- css_value- )))- .attach_printable(- "Unsafe CSS value found in payment_link_ui_rules",- )- } else {- css_string.push_str(" ");- css_string.push_str(&css_property);- css_string.push_str(": ");- css_string.push_str(css_value);- css_string.push_str(";\n");- Ok(())- }- });-- inner_res.map(|_| {- css_string.push_str("}\n");- })+ for (selector, styles_map) in rules {+ let mut declarations = Vec::with_capacity(styles_map.len());+ for (prop_camel_case, css_value) in styles_map {+ let css_property = camel_to_kebab(prop_camel_case);+ if let Some(declaration) = parse_css_declaration(&css_property, css_value) {+ declarations.push(declaration);}- })- .map(|_| css_string)+ }++ if let Some(rule_css) = parse_css_rule(selector, &declarations) {+ css_string.push_str(&rule_css);+ if !rule_css.ends_with('\n') {+ css_string.push('\n');+ }+ }+ }++ Ok(css_string)}}@@ -197,21 +332,32 @@ fn camel_to_kebab(s: &str) -> String {#[cfg(test)]mod tests {use super::*;+ #[test]+ fn test_parse_css_rule() {+ let declaration = parse_css_declaration("color", "#4E6ADD").unwrap();+ let declarations = [declaration];++ assert!(parse_css_rule("body", &declarations).is_some());+ assert!(parse_css_rule(".class-name", &declarations).is_some());+ assert!(parse_css_rule("#id-name", &declarations).is_some());+ assert!(parse_css_rule("#some-parent > .Input--invalid", &declarations).is_some());+ assert!(parse_css_rule(":has(> .TermsTextLabel)", &declarations).is_some());++ assert!(parse_css_rule("body { color: red }", &declarations).is_none());+ assert!(parse_css_rule("</style><script>", &declarations).is_none());+ assert!(parse_css_rule("@media screen", &declarations).is_none());+ }#[test]- fn test_is_safe_css_token() {- assert!(is_safe_css_token("body"));- assert!(is_safe_css_token(".class-name"));- assert!(is_safe_css_token("#id-name"));- assert!(is_safe_css_token("14px"));- assert!(is_safe_css_token("solid"));-- assert!(!is_safe_css_token("body { color: red }"));- assert!(!is_safe_css_token("</style><script>"));- assert!(!is_safe_css_token("expression(alert(1))"));- assert!(!is_safe_css_token("javascript:alert(1)"));- assert!(!is_safe_css_token("url(javascript:alert)"));- assert!(!is_safe_css_token("/* comment */"));+ fn test_parse_css_declaration() {+ assert!(parse_css_declaration("font-size", "body { color: red }").is_none());+ assert!(parse_css_declaration("color", "</style><script>").is_none());+ assert!(parse_css_declaration("color", "red; background: blue").is_none());+ assert!(parse_css_declaration("content", "' *'").is_none());+ assert!(parse_css_declaration("width", "expression(alert(1))").is_none());+ assert!(parse_css_declaration("-ms-overflow-style", "none").is_none());+ assert!(parse_css_declaration("background-image", "javascript:alert(1)").is_none());+ assert!(parse_css_declaration("background-image", "url(javascript:alert)").is_none());}#[test]@@ -245,10 +391,22 @@ mod tests {let css = generate_dynamic_css(&rules).unwrap();assert!(css.contains("body {"));- assert!(css.contains("background-color: #4E6ADD;"));+ assert!(css.contains("background-color: #4e6add;"));assert!(css.contains("font-size: 14px;"));}+ #[test]+ fn test_generate_dynamic_css_allows_child_combinator_selector() {+ let mut rules = HashMap::new();+ let mut styles = HashMap::new();+ styles.insert("color".to_string(), "#4E6ADD".to_string());+ rules.insert("#some-parent > .Input--invalid".to_string(), styles);++ let css = generate_dynamic_css(&rules).unwrap();+ assert!(css.contains("#some-parent > .Input--invalid {"));+ assert!(css.contains("color: #4e6add;"));+ }+#[test]fn test_generate_dynamic_css_unsafe() {let mut rules = HashMap::new();@@ -259,6 +417,33 @@ mod tests {);rules.insert("body".to_string(), styles);- assert!(generate_dynamic_css(&rules).is_err());+ let css = generate_dynamic_css(&rules).unwrap();+ assert_eq!(css, "/* Dynamically Injected UI Rules */\n");+ }++ #[test]+ fn test_generate_dynamic_css_rejects_url_dependency() {+ let mut rules = HashMap::new();+ let mut styles = HashMap::new();+ styles.insert(+ "backgroundImage".to_string(),+ "url(javascript:confirm(1))".to_string(),+ );+ styles.insert("color".to_string(), "#4E6ADD".to_string());+ rules.insert(".safe-selector".to_string(), styles);++ let css = generate_dynamic_css(&rules).unwrap();+ assert_eq!(css, "/* Dynamically Injected UI Rules */\n");+ }++ #[test]+ fn test_generate_dynamic_css_rejects_unsafe_selector() {+ let mut rules = HashMap::new();+ let mut styles = HashMap::new();+ styles.insert("color".to_string(), "#4E6ADD".to_string());+ rules.insert("</style><script>".to_string(), styles);++ let css = generate_dynamic_css(&rules).unwrap();+ assert_eq!(css, "/* Dynamically Injected UI Rules */\n");}}diff --git a/crates/router/src/core/webhooks/webhook_events.rs b/crates/router/src/core/webhooks/webhook_events.rsindex 8ccc09f8c3..4cac099158 100644--- a/crates/router/src/core/webhooks/webhook_events.rs+++ b/crates/router/src/core/webhooks/webhook_events.rs@@ -102,7 +102,7 @@ pub async fn list_initial_delivery_attempts(.is_none_or(|pid| event.business_profile_id.as_ref() == Some(pid));matches_initiator&& matches_profile- && event.initial_attempt_id.as_deref() == Some(&event.event_id)+ && event.initial_attempt_id.as_deref() == Some(event.event_id.as_str())});let (events, total_count) = event_opt.map_or((vec![], 0), |event| (vec![event], 1));diff --git a/crates/router/src/db/events.rs b/crates/router/src/db/events.rsindex 56e65d6d50..4fac0f894b 100644--- a/crates/router/src/db/events.rs+++ b/crates/router/src/db/events.rs@@ -1083,7 +1083,7 @@ impl EventInterface for MockDb {.iter().filter(|event| {event.merchant_id == Some(merchant_id.to_owned())- && event.initial_attempt_id.as_deref() == Some(&event.event_id)+ && event.initial_attempt_id.as_deref() == Some(event.event_id.as_str())&& event.primary_object_id.as_str() == primary_object_id&& (event_recipient.is_none() || event_recipient == event.recipient)})@@ -1221,7 +1221,7 @@ impl EventInterface for MockDb {.iter().filter(|event| {event.business_profile_id == Some(profile_id.to_owned())- && event.initial_attempt_id.as_deref() == Some(&event.event_id)+ && event.initial_attempt_id.as_deref() == Some(event.event_id.as_str())&& event.primary_object_id.as_str() == primary_object_id&& (event_recipient.is_none() || event_recipient == event.recipient)})@@ -1488,7 +1488,7 @@ impl EventInterface for MockDb {.is_none_or(|pid| event.business_profile_id.as_ref() == Some(pid));matches_initiator&& matches_profile- && event.initial_attempt_id.as_deref() == Some(&event.event_id)+ && event.initial_attempt_id.as_deref() == Some(event.event_id.as_str())&& event.primary_object_id.as_str() == primary_object_id&& (event_recipient.is_none() || event_recipient == event.recipient)})