Skip to content

Commit

Permalink
Merge branch '4.60-bug-fixes' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
exileDev committed Dec 15, 2023
2 parents 2b935d6 + bc643dd commit 1626480
Showing 1 changed file with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -475,35 +475,39 @@ public static void UseNopEndpoints(this IApplicationBuilder application)
public static void UseNopProxy(this IApplicationBuilder application)
{
var appSettings = EngineContext.Current.Resolve<AppSettings>();
var hostingConfig = appSettings.Get<HostingConfig>();

if (appSettings.Get<HostingConfig>().UseProxy)
if (hostingConfig.UseProxy)
{
var options = new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.All,
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto,
// IIS already serves as a reverse proxy and will add X-Forwarded headers to all requests,
// so we need to increase this limit, otherwise, passed forwarding headers will be ignored.
ForwardLimit = 2
};

if (!string.IsNullOrEmpty(appSettings.Get<HostingConfig>().ForwardedForHeaderName))
options.ForwardedForHeaderName = appSettings.Get<HostingConfig>().ForwardedForHeaderName;
if (!string.IsNullOrEmpty(hostingConfig.ForwardedForHeaderName))
options.ForwardedForHeaderName = hostingConfig.ForwardedForHeaderName;

if (!string.IsNullOrEmpty(appSettings.Get<HostingConfig>().ForwardedProtoHeaderName))
options.ForwardedProtoHeaderName = appSettings.Get<HostingConfig>().ForwardedProtoHeaderName;
if (!string.IsNullOrEmpty(hostingConfig.ForwardedProtoHeaderName))
options.ForwardedProtoHeaderName = hostingConfig.ForwardedProtoHeaderName;

if (!string.IsNullOrEmpty(appSettings.Get<HostingConfig>().KnownProxies))
options.KnownNetworks.Clear();
options.KnownProxies.Clear();

if (!string.IsNullOrEmpty(hostingConfig.KnownProxies))
{
foreach (var strIp in appSettings.Get<HostingConfig>().KnownProxies.Split(',', StringSplitOptions.RemoveEmptyEntries).ToList())
foreach (var strIp in hostingConfig.KnownProxies.Split(',', StringSplitOptions.RemoveEmptyEntries).ToList())
{
if (IPAddress.TryParse(strIp, out var ip))
options.KnownProxies.Add(ip);
}
}

if (!string.IsNullOrEmpty(appSettings.Get<HostingConfig>().KnownNetworks))
if (!string.IsNullOrEmpty(hostingConfig.KnownNetworks))
{
foreach (var strIpNet in appSettings.Get<HostingConfig>().KnownNetworks.Split(',', StringSplitOptions.RemoveEmptyEntries).ToList())
foreach (var strIpNet in hostingConfig.KnownNetworks.Split(',', StringSplitOptions.RemoveEmptyEntries).ToList())
{
var ipNetParts = strIpNet.Split("/");
if (ipNetParts.Length == 2)
Expand Down

0 comments on commit 1626480

Please sign in to comment.