简化域名判断
This commit is contained in:
parent
bec5c732ab
commit
3676caf118
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,11 +14,6 @@ namespace FastGithub.HttpServer
|
||||
/// </summary>
|
||||
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<HttpReverseProxyMiddleware> 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user