From 64edc49392f1786aebf6a5a0c9b60742ca734d6e Mon Sep 17 00:00:00 2001
From: BlockListed <44610569+BlockListed@users.noreply.github.com>
Date: Mon, 6 Feb 2023 23:19:08 +0100
Subject: [PATCH 1/7] change description of domain configuration

Vaultwarden send won't work if the domain includes a trailing slash.
This should be documented, as it may lead to confusion amoung users.
---
 src/config.rs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/config.rs b/src/config.rs
index 46deed54..1ba6e402 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -401,7 +401,8 @@ make_config! {
     /// General settings
     settings {
         /// Domain URL |> This needs to be set to the URL used to access the server, including 'http[s]://'
-        /// and port, if it's different than the default. Some server functions don't work correctly without this value
+        /// and port, if it's different than the default, but excluding a trailing slash.
+        /// Some server functions don't work correctly without this value
         domain:                 String, true,   def,    "http://localhost".to_string();
         /// Domain Set |> Indicates if the domain is set by the admin. Otherwise the default will be used.
         domain_set:             bool,   false,  def,    false;

From eb9b481eba63dbbfe0e83fac238be3482e21ccfa Mon Sep 17 00:00:00 2001
From: BlockListed <44610569+BlockListed@users.noreply.github.com>
Date: Tue, 7 Feb 2023 08:48:48 +0100
Subject: [PATCH 2/7] improve wording of domain description

---
 src/config.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/config.rs b/src/config.rs
index 1ba6e402..60b2db27 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -401,7 +401,7 @@ make_config! {
     /// General settings
     settings {
         /// Domain URL |> This needs to be set to the URL used to access the server, including 'http[s]://'
-        /// and port, if it's different than the default, but excluding a trailing slash.
+        /// and port, if it's different than the default. Don't include a trailing slash.
         /// Some server functions don't work correctly without this value
         domain:                 String, true,   def,    "http://localhost".to_string();
         /// Domain Set |> Indicates if the domain is set by the admin. Otherwise the default will be used.

From a72d0b518fa96ba63c4029f0c60e6bd53cd92661 Mon Sep 17 00:00:00 2001
From: BlockListed <44610569+BlockListed@users.noreply.github.com>
Date: Tue, 7 Feb 2023 12:48:48 +0100
Subject: [PATCH 3/7] remove documentation of bug since I'm fixing it

---
 src/config.rs | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/config.rs b/src/config.rs
index 60b2db27..46deed54 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -401,8 +401,7 @@ make_config! {
     /// General settings
     settings {
         /// Domain URL |> This needs to be set to the URL used to access the server, including 'http[s]://'
-        /// and port, if it's different than the default. Don't include a trailing slash.
-        /// Some server functions don't work correctly without this value
+        /// and port, if it's different than the default. Some server functions don't work correctly without this value
         domain:                 String, true,   def,    "http://localhost".to_string();
         /// Domain Set |> Indicates if the domain is set by the admin. Otherwise the default will be used.
         domain_set:             bool,   false,  def,    false;

From 679bc7a59b5daef65ef7916474577106a46fa0e9 Mon Sep 17 00:00:00 2001
From: BlockListed <44610569+BlockListed@users.noreply.github.com>
Date: Tue, 7 Feb 2023 13:03:28 +0100
Subject: [PATCH 4/7] fix trailing slash not being removed from domain

---
 src/auth.rs | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/auth.rs b/src/auth.rs
index 03f14cb8..5e31524e 100644
--- a/src/auth.rs
+++ b/src/auth.rs
@@ -283,7 +283,8 @@ impl<'r> FromRequest<'r> for Host {
 
         // Get host
         let host = if CONFIG.domain_set() {
-            CONFIG.domain()
+            // Remove trailing slash if it exists since we're getting a host
+            CONFIG.domain().trim_end_matches('/').to_string()
         } else if let Some(referer) = headers.get_one("Referer") {
             referer.to_string()
         } else {

From a2aa7c9bc23145f0f5db72f8aeed826902c86fde Mon Sep 17 00:00:00 2001
From: BlockListed <44610569+BlockListed@users.noreply.github.com>
Date: Tue, 7 Feb 2023 18:19:16 +0100
Subject: [PATCH 5/7] Revert "fix trailing slash not being removed from domain"

This reverts commit 679bc7a59b5daef65ef7916474577106a46fa0e9.
---
 src/auth.rs | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/src/auth.rs b/src/auth.rs
index 5e31524e..03f14cb8 100644
--- a/src/auth.rs
+++ b/src/auth.rs
@@ -283,8 +283,7 @@ impl<'r> FromRequest<'r> for Host {
 
         // Get host
         let host = if CONFIG.domain_set() {
-            // Remove trailing slash if it exists since we're getting a host
-            CONFIG.domain().trim_end_matches('/').to_string()
+            CONFIG.domain()
         } else if let Some(referer) = headers.get_one("Referer") {
             referer.to_string()
         } else {

From 5d1c11ceba3826b5ae000d9a4d8c0ec7e094428c Mon Sep 17 00:00:00 2001
From: BlockListed <44610569+BlockListed@users.noreply.github.com>
Date: Tue, 7 Feb 2023 18:34:47 +0100
Subject: [PATCH 6/7] fix trailing slash in configuration builder

---
 src/config.rs | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/config.rs b/src/config.rs
index 46deed54..42a75ca2 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -141,6 +141,14 @@ macro_rules! make_config {
                 )+)+
                 config.domain_set = _domain_set;
 
+                if config.domain_set {
+                    if config.domain.ends_with('/') {
+                        println!("[WARNING] The configured domain ends with a trailing slash.");
+                        println!("[WARNING] The trailing slash is getting removed.");
+                        config.domain = config.domain.trim_end_matches('/').to_string();
+                    }
+                }
+
                 config.signups_domains_whitelist = config.signups_domains_whitelist.trim().to_lowercase();
                 config.org_creation_users = config.org_creation_users.trim().to_lowercase();
 

From c04a1352cbc62cb55e4bb412c245c832780a20df Mon Sep 17 00:00:00 2001
From: BlockListed <44610569+BlockListed@users.noreply.github.com>
Date: Tue, 7 Feb 2023 18:49:26 +0100
Subject: [PATCH 7/7] remove warn when sanitizing domain

---
 src/config.rs | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/src/config.rs b/src/config.rs
index 42a75ca2..8ae7109c 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -141,13 +141,7 @@ macro_rules! make_config {
                 )+)+
                 config.domain_set = _domain_set;
 
-                if config.domain_set {
-                    if config.domain.ends_with('/') {
-                        println!("[WARNING] The configured domain ends with a trailing slash.");
-                        println!("[WARNING] The trailing slash is getting removed.");
-                        config.domain = config.domain.trim_end_matches('/').to_string();
-                    }
-                }
+                config.domain = config.domain.trim_end_matches('/').to_string();
 
                 config.signups_domains_whitelist = config.signups_domains_whitelist.trim().to_lowercase();
                 config.org_creation_users = config.org_creation_users.trim().to_lowercase();