简化域名判断
This commit is contained in:
parent
bec5c732ab
commit
3676caf118
@ -105,10 +105,10 @@ namespace FastGithub.HttpServer
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
await this.httpReverseProxy.InvokeAsync(context, async ctx =>
|
await this.httpReverseProxy.InvokeAsync(context, async next =>
|
||||||
{
|
{
|
||||||
var destinationPrefix = $"{ctx.Request.Scheme}://{ctx.Request.Host}";
|
var destinationPrefix = $"{context.Request.Scheme}://{context.Request.Host}";
|
||||||
await this.httpForwarder.SendAsync(ctx, destinationPrefix, this.defaultHttpClient);
|
await this.httpForwarder.SendAsync(context, destinationPrefix, this.defaultHttpClient);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,11 +14,6 @@ namespace FastGithub.HttpServer
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
sealed class HttpReverseProxyMiddleware
|
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 static readonly DomainConfig defaultDomainConfig = new() { TlsSni = true };
|
||||||
|
|
||||||
private readonly IHttpForwarder httpForwarder;
|
private readonly IHttpForwarder httpForwarder;
|
||||||
@ -26,7 +21,6 @@ namespace FastGithub.HttpServer
|
|||||||
private readonly FastGithubConfig fastGithubConfig;
|
private readonly FastGithubConfig fastGithubConfig;
|
||||||
private readonly ILogger<HttpReverseProxyMiddleware> logger;
|
private readonly ILogger<HttpReverseProxyMiddleware> logger;
|
||||||
|
|
||||||
|
|
||||||
public HttpReverseProxyMiddleware(
|
public HttpReverseProxyMiddleware(
|
||||||
IHttpForwarder httpForwarder,
|
IHttpForwarder httpForwarder,
|
||||||
IHttpClientFactory httpClientFactory,
|
IHttpClientFactory httpClientFactory,
|
||||||
@ -84,20 +78,14 @@ namespace FastGithub.HttpServer
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// http(s)://127.0.0.1
|
// 未配置的域名,但仍然被解析到本机ip的域名
|
||||||
// http(s)://localhost
|
if (host.Host.Contains('.') == true)
|
||||||
if (host.Host == LOOPBACK || host.Host == LOCALHOST)
|
|
||||||
{
|
{
|
||||||
if (host.Port == null || host.Port == HTTPS_PORT || host.Port == HTTP_PORT)
|
domainConfig = defaultDomainConfig;
|
||||||
{
|
return true;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 未配置的域名,但dns污染解析为127.0.0.1的域名
|
return false;
|
||||||
this.logger.LogWarning($"检测到{host.Host}可能遭遇了dns污染");
|
|
||||||
domainConfig = defaultDomainConfig;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user