diff --git a/bitwarden_license/src/Scim/Startup.cs b/bitwarden_license/src/Scim/Startup.cs index 4aaccd9ed2..4ef46459c3 100644 --- a/bitwarden_license/src/Scim/Startup.cs +++ b/bitwarden_license/src/Scim/Startup.cs @@ -93,6 +93,12 @@ public class Startup // Add general security headers app.UseMiddleware(); + // Forwarding Headers + if (globalSettings.SelfHosted) + { + app.UseForwardedHeaders(globalSettings); + } + if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); diff --git a/src/Events/Startup.cs b/src/Events/Startup.cs index 50147fcda5..d41a27be0d 100644 --- a/src/Events/Startup.cs +++ b/src/Events/Startup.cs @@ -93,6 +93,12 @@ public class Startup // Add general security headers app.UseMiddleware(); + // Forwarding Headers + if (globalSettings.SelfHosted) + { + app.UseForwardedHeaders(globalSettings); + } + if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); diff --git a/src/Icons/Startup.cs b/src/Icons/Startup.cs index f64ea07edf..f63407fa7a 100644 --- a/src/Icons/Startup.cs +++ b/src/Icons/Startup.cs @@ -55,6 +55,12 @@ public class Startup // Add general security headers app.UseMiddleware(); + // Forwarding Headers + if (globalSettings.SelfHosted) + { + app.UseForwardedHeaders(globalSettings); + } + if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); diff --git a/src/Notifications/Startup.cs b/src/Notifications/Startup.cs index 2468e078b6..440808b78b 100644 --- a/src/Notifications/Startup.cs +++ b/src/Notifications/Startup.cs @@ -90,6 +90,12 @@ public class Startup // Add general security headers app.UseMiddleware(); + // Forwarding Headers + if (globalSettings.SelfHosted) + { + app.UseForwardedHeaders(globalSettings); + } + if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); diff --git a/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs b/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs index 679aaed1b7..c239be969a 100644 --- a/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs +++ b/src/SharedWeb/Utilities/ServiceCollectionExtensions.cs @@ -540,10 +540,17 @@ public static class ServiceCollectionExtensions if (!globalSettings.UnifiedDeployment) { // Trust the X-Forwarded-Host header of the nginx docker container - var nginxIp = Dns.GetHostEntry("nginx").AddressList.FirstOrDefault(); - if (nginxIp != null) + try { - options.KnownProxies.Add(nginxIp); + var nginxIp = Dns.GetHostEntry("nginx")?.AddressList.FirstOrDefault(); + if (nginxIp != null) + { + options.KnownProxies.Add(nginxIp); + } + } + catch + { + // Ignore DNS errors } }