aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-11-21 17:35:59 +0800
committercrupest <crupest@outlook.com>2022-11-21 17:35:59 +0800
commit5782b39e791199faf60df22a3d396f60ab56bc40 (patch)
tree7d065ee8cd87463c6edf0880fe67452ec1ccd63b
parent63851882dcb4cc19dc85059a0529405c75c95bf3 (diff)
downloadtimeline-5782b39e791199faf60df22a3d396f60ab56bc40.tar.gz
timeline-5782b39e791199faf60df22a3d396f60ab56bc40.tar.bz2
timeline-5782b39e791199faf60df22a3d396f60ab56bc40.zip
Revert forwarded headers change.
-rw-r--r--BackEnd/Timeline/Configs/ApplicationConfiguration.cs2
-rw-r--r--BackEnd/Timeline/Startup.cs74
-rw-r--r--Dockerfile1
3 files changed, 0 insertions, 77 deletions
diff --git a/BackEnd/Timeline/Configs/ApplicationConfiguration.cs b/BackEnd/Timeline/Configs/ApplicationConfiguration.cs
index c808e946..bc77fd5a 100644
--- a/BackEnd/Timeline/Configs/ApplicationConfiguration.cs
+++ b/BackEnd/Timeline/Configs/ApplicationConfiguration.cs
@@ -12,8 +12,6 @@ namespace Timeline.Configs
public const string DatabaseBackupDirectoryName = "backup";
public const string FrontEndKey = "FrontEnd";
public const string DisableAutoBackupKey = "DisableAutoBackup";
- public const string EnableForwardedHeadersKey = "EnableForwardedHeaders";
- public const string ForwardedHeadersAllowedProxyHostsKey = "ForwardedHeadersAllowedProxyHosts";
public static bool CheckIsValidBoolString(string? value, string configPath, Boolean defaultValue)
{
diff --git a/BackEnd/Timeline/Startup.cs b/BackEnd/Timeline/Startup.cs
index a5569d9f..628be35d 100644
--- a/BackEnd/Timeline/Startup.cs
+++ b/BackEnd/Timeline/Startup.cs
@@ -6,10 +6,7 @@ using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
-using System.Collections.Generic;
using System.ComponentModel;
-using System.Net;
-using System.Text;
using System.Text.Json.Serialization;
using Timeline.Auth;
using Timeline.Configs;
@@ -36,10 +33,6 @@ namespace Timeline
{
public class Startup
{
- private readonly bool _enableForwardedHeaders;
- private readonly string? _forwardedHeadersAllowedProxyHostsString;
- private readonly List<string>? _forwardedHeadersAllowedProxyHosts = null;
- private readonly List<List<IPAddress>>? _forwardedHeadersAllowedProxyIPs = null;
private readonly FrontEndMode _frontEndMode;
public Startup(IConfiguration configuration, IWebHostEnvironment environment)
@@ -65,51 +58,6 @@ namespace Timeline
Console.WriteLine("Unknown FrontEnd configuration value '{0}', fallback to normal.", frontEndModeString);
}
}
-
- _enableForwardedHeaders = ApplicationConfiguration.GetBoolConfig(configuration, ApplicationConfiguration.EnableForwardedHeadersKey, false);
- _forwardedHeadersAllowedProxyHostsString = Configuration.GetValue<string?>(ApplicationConfiguration.ForwardedHeadersAllowedProxyHostsKey);
-
- if (_enableForwardedHeaders)
- {
- Console.ForegroundColor = ConsoleColor.Green;
- Console.WriteLine("Forwarded headers enabled.");
- Console.ResetColor();
-
- Console.ForegroundColor = ConsoleColor.Yellow;
- if (_forwardedHeadersAllowedProxyHostsString is not null)
- {
- _forwardedHeadersAllowedProxyHosts = new List<string>();
- foreach (var host in _forwardedHeadersAllowedProxyHostsString.Split(new char[] { ';', ',' }))
- {
- _forwardedHeadersAllowedProxyHosts.Add(host.Trim());
- }
-
- _forwardedHeadersAllowedProxyIPs = new();
- foreach (var host in _forwardedHeadersAllowedProxyHosts)
- {
- // Resolve host to ip
- var ips = System.Net.Dns.GetHostAddresses(host);
- _forwardedHeadersAllowedProxyIPs.Add(new(ips));
- }
-
- Console.WriteLine("Allowed proxy hosts:");
- Console.ForegroundColor = ConsoleColor.Cyan;
- StringBuilder log = new();
- for (int i = 0; i < _forwardedHeadersAllowedProxyHosts.Count; i++)
- {
- log.Append(_forwardedHeadersAllowedProxyHosts[i]);
- log.Append(" (");
- log.Append(string.Join(' ', _forwardedHeadersAllowedProxyIPs));
- log.Append(")\n");
- }
- Console.WriteLine(log.ToString());
- }
- else
- {
- Console.WriteLine("Allowed proxy hosts settings is default");
- }
- Console.ResetColor();
- }
}
public IWebHostEnvironment Environment { get; }
@@ -191,23 +139,6 @@ namespace Timeline
config.RootPath = "ClientApp";
});
}
-
- if (_enableForwardedHeaders)
- {
- services.Configure<ForwardedHeadersOptions>(options =>
- {
- options.ForwardedHeaders = Microsoft.AspNetCore.HttpOverrides.ForwardedHeaders.XForwardedFor | Microsoft.AspNetCore.HttpOverrides.ForwardedHeaders.XForwardedProto;
- if (_forwardedHeadersAllowedProxyHostsString is not null)
- {
- options.KnownNetworks.Clear();
- options.KnownProxies.Clear();
- foreach (var ips in _forwardedHeadersAllowedProxyIPs!)
- {
- ips.ForEach(ip => options.KnownProxies.Add(ip));
- }
- }
- });
- }
}
@@ -224,11 +155,6 @@ namespace Timeline
});
}
- if (_enableForwardedHeaders)
- {
- app.UseForwardedHeaders();
- }
-
app.UseOpenApi();
app.UseReDoc();
diff --git a/Dockerfile b/Dockerfile
index 0d916052..8bff7263 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -12,7 +12,6 @@ COPY --from=front-build /timeline-app/dist /timeline-app/Timeline/ClientApp
RUN dotnet publish Timeline/Timeline.csproj --configuration Release --output ./Timeline/publish/ -r linux-x64 --self-contained false
FROM mcr.microsoft.com/dotnet/aspnet:6.0
-ENV ASPNETCORE_URLS=http://0.0.0.0:80
WORKDIR /app
COPY --from=back-build /timeline-app/Timeline/publish .
EXPOSE 80