From 3676caf11804170c6e85f044c7073b23433e2381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=9B=BD=E4=BC=9F?= <366193849@qq.com> Date: Sat, 6 Nov 2021 12:00:10 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=80=E5=8C=96=E5=9F=9F=E5=90=8D=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- FastGithub.HttpServer/HttpProxyMiddleware.cs | 6 ++--- .../HttpReverseProxyMiddleware.cs | 22 +++++-------------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/FastGithub.HttpServer/HttpProxyMiddleware.cs b/FastGithub.HttpServer/HttpProxyMiddleware.cs index e380191..95b4bdb 100644 --- a/FastGithub.HttpServer/HttpProxyMiddleware.cs +++ b/FastGithub.HttpServer/HttpProxyMiddleware.cs @@ -105,10 +105,10 @@ namespace FastGithub.HttpServer } else { - await this.httpReverseProxy.InvokeAsync(context, async ctx => + await this.httpReverseProxy.InvokeAsync(context, async next => { - var destinationPrefix = $"{ctx.Request.Scheme}://{ctx.Request.Host}"; - await this.httpForwarder.SendAsync(ctx, destinationPrefix, this.defaultHttpClient); + var destinationPrefix = $"{context.Request.Scheme}://{context.Request.Host}"; + await this.httpForwarder.SendAsync(context, destinationPrefix, this.defaultHttpClient); }); } } diff --git a/FastGithub.HttpServer/HttpReverseProxyMiddleware.cs b/FastGithub.HttpServer/HttpReverseProxyMiddleware.cs index 854315a..6eefa24 100644 --- a/FastGithub.HttpServer/HttpReverseProxyMiddleware.cs +++ b/FastGithub.HttpServer/HttpReverseProxyMiddleware.cs @@ -14,11 +14,6 @@ namespace FastGithub.HttpServer /// sealed class HttpReverseProxyMiddleware { - private const string LOOPBACK = "127.0.0.1"; - private const string LOCALHOST = "localhost"; - private const int HTTP_PORT = 80; - private const int HTTPS_PORT = 443; - private static readonly DomainConfig defaultDomainConfig = new() { TlsSni = true }; private readonly IHttpForwarder httpForwarder; @@ -26,7 +21,6 @@ namespace FastGithub.HttpServer private readonly FastGithubConfig fastGithubConfig; private readonly ILogger logger; - public HttpReverseProxyMiddleware( IHttpForwarder httpForwarder, IHttpClientFactory httpClientFactory, @@ -84,20 +78,14 @@ namespace FastGithub.HttpServer return true; } - // http(s)://127.0.0.1 - // http(s)://localhost - if (host.Host == LOOPBACK || host.Host == LOCALHOST) + // 未配置的域名,但仍然被解析到本机ip的域名 + if (host.Host.Contains('.') == true) { - if (host.Port == null || host.Port == HTTPS_PORT || host.Port == HTTP_PORT) - { - return false; - } + domainConfig = defaultDomainConfig; + return true; } - // 未配置的域名,但dns污染解析为127.0.0.1的域名 - this.logger.LogWarning($"检测到{host.Host}可能遭遇了dns污染"); - domainConfig = defaultDomainConfig; - return true; + return false; } ///