WebService: fixed issue in GetRequestRemoteEndPoint() for reading X-Real-IP from reverse proxy headers. Minor fix in syntax of parsing PTR response.

This commit is contained in:
Shreyas Zare
2020-09-19 16:58:55 +05:30
parent 7aff64f737
commit bb246c79e4

View File

@@ -522,16 +522,19 @@ namespace DnsServerCore
{
try
{
string xRealIp = request.Headers["X-Real-IP"];
if (IPAddress.TryParse(xRealIp, out IPAddress address))
{
//get the real IP address of the requesting client from X-Real-IP header set in nginx proxy_pass block
return new IPEndPoint(address, 0);
}
if (request.RemoteEndPoint == null)
return new IPEndPoint(IPAddress.Any, 0);
if (NetUtilities.IsPrivateIP(request.RemoteEndPoint.Address))
{
string xRealIp = request.Headers["X-Real-IP"];
if (IPAddress.TryParse(xRealIp, out IPAddress address))
{
//get the real IP address of the requesting client from X-Real-IP header set in nginx proxy_pass block
return new IPEndPoint(address, 0);
}
}
return request.RemoteEndPoint;
}
catch
@@ -1502,10 +1505,12 @@ namespace DnsServerCore
DnsDatagram ptrResponse = await _dnsServer.DirectQueryAsync(new DnsQuestionRecord(address, DnsClass.IN), 200);
if ((ptrResponse != null) && (ptrResponse.Answer.Count > 0))
{
string ptrDomain = DnsClient.ParseResponsePTR(ptrResponse);
jsonWriter.WritePropertyName("domain");
jsonWriter.WriteValue(ptrDomain);
IReadOnlyList<string> ptrDomains = DnsClient.ParseResponsePTR(ptrResponse);
if (ptrDomains != null)
{
jsonWriter.WritePropertyName("domain");
jsonWriter.WriteValue(ptrDomains[0]);
}
}
}
catch