From f471a14098cf222ea201d2c7a2d3d4c90509b2d3 Mon Sep 17 00:00:00 2001 From: Akash Gupta Date: Mon, 9 Jan 2023 21:30:02 +0530 Subject: [PATCH] 757: Add new options for prefix of whitelabel headers (whitelabel_headers_prefix) --- server/svix-server/config.default.toml | 3 +++ server/svix-server/src/cfg.rs | 3 +++ server/svix-server/src/worker.rs | 13 ++++++++++--- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/server/svix-server/config.default.toml b/server/svix-server/config.default.toml index 6b98a764e..fcdff7763 100644 --- a/server/svix-server/config.default.toml +++ b/server/svix-server/config.default.toml @@ -79,6 +79,9 @@ cache_type = "memory" # If true, headers are prefixed with `Webhook-`, otherwise with `Svix-` (default). whitelabel_headers = false +# If value is configured, headers are prefixed with custom configured prefix value, otherwise with `Webhook-` (default). +whitelabel_header_prefix = "Custom-" + # If true, only allow https endpoints, otherwise also allow http. endpoint_https_only = false diff --git a/server/svix-server/src/cfg.rs b/server/svix-server/src/cfg.rs index 17abf209a..b0efe3e5a 100644 --- a/server/svix-server/src/cfg.rs +++ b/server/svix-server/src/cfg.rs @@ -155,6 +155,9 @@ pub struct ConfigurationInner { /// If true, headers are prefixed with `Webhook-`, otherwise with `Svix-` (default). pub whitelabel_headers: bool, + /// # If value is configured, headers are prefixed with custom configured prefix value, otherwise with `Webhook-` (default). + pub whitelabel_header_prefix: String, + /// If true, only allow https endpoints, otherwise also allow http. pub endpoint_https_only: bool, diff --git a/server/svix-server/src/worker.rs b/server/svix-server/src/worker.rs index 30e8076c5..4faa69612 100644 --- a/server/svix-server/src/worker.rs +++ b/server/svix-server/src/worker.rs @@ -172,6 +172,7 @@ fn generate_msg_headers( msg_id: &MessageId, signatures: String, whitelabel_headers: bool, + whitelabel_header_prefix: String, configured_headers: Option<&EndpointHeaders>, _endpoint_url: &str, ) -> HeaderMap { @@ -185,9 +186,10 @@ fn generate_msg_headers( .parse() .expect("Error parsing message signatures"); if whitelabel_headers { - headers.insert("webhook-id", id); - headers.insert("webhook-timestamp", timestamp); - headers.insert("webhook-signature", signatures_str); + let webhook_prefix = if whitelabel_header_prefix.is_empty() { "webhook-" } else { whitelabel_header_prefix }; + headers.insert(format!("{webhook_prefix}id"), id); + headers.insert(format!("{webhook_prefix}timestamp"), timestamp); + headers.insert(format!("{webhook_prefix}signature"), signatures_str); } else { headers.insert("svix-id", id); headers.insert("svix-timestamp", timestamp); @@ -272,6 +274,7 @@ async fn dispatch( &msg_task.msg_id, signatures, cfg.whitelabel_headers, + cfg.whitelabel_header_prefix, endp.headers.as_ref(), &endp.url, ); @@ -735,6 +738,7 @@ mod tests { // [`generate_msg_headers`] tests const TIMESTAMP: i64 = 1; const WHITELABEL_HEADERS: bool = false; + const WHITELABEL_HEADER_PREFIX: &str = "custom-" const BODY: &str = "{\"test\": \"body\"}"; const ENDPOINT_SIGNING_KEYS: &[&EndpointSecretInternal] = &[]; const ENDPOINT_URL: &str = "http://localhost:8071"; @@ -758,6 +762,7 @@ mod tests { &id, signatures, WHITELABEL_HEADERS, + WHITELABEL_HEADER_PREFIX, None, ENDPOINT_URL, ), @@ -791,6 +796,7 @@ mod tests { &id, signatures, WHITELABEL_HEADERS, + WHITELABEL_HEADER_PREFIX, Some(&EndpointHeaders(headers)), ENDPOINT_URL, ); @@ -826,6 +832,7 @@ mod tests { &test_message_id, signatures, WHITELABEL_HEADERS, + WHITELABEL_HEADER_PREFIX, None, ENDPOINT_URL, );