Commit 3b73274e authored by Savorboard's avatar Savorboard

Fixed Incorrect local IP address judgment of IPv6. (#140)

parent 32d71144
...@@ -28,19 +28,14 @@ namespace DotNetCore.CAP.Dashboard ...@@ -28,19 +28,14 @@ namespace DotNetCore.CAP.Dashboard
public CapDashboardRequest(HttpContext context) public CapDashboardRequest(HttpContext context)
{ {
if (context == null) _context = context ?? throw new ArgumentNullException(nameof(context));
{
throw new ArgumentNullException(nameof(context));
}
_context = context;
} }
public override string Method => _context.Request.Method; public override string Method => _context.Request.Method;
public override string Path => _context.Request.Path.Value; public override string Path => _context.Request.Path.Value;
public override string PathBase => _context.Request.PathBase.Value; public override string PathBase => _context.Request.PathBase.Value;
public override string LocalIpAddress => _context.Connection.LocalIpAddress.ToString(); public override string LocalIpAddress => _context.Connection.LocalIpAddress.MapToIPv4().ToString();
public override string RemoteIpAddress => _context.Connection.RemoteIpAddress.ToString(); public override string RemoteIpAddress => _context.Connection.RemoteIpAddress.MapToIPv4().ToString();
public override string GetQuery(string key) public override string GetQuery(string key)
{ {
......
...@@ -9,26 +9,27 @@ namespace DotNetCore.CAP.Dashboard ...@@ -9,26 +9,27 @@ namespace DotNetCore.CAP.Dashboard
{ {
public bool Authorize(DashboardContext context) public bool Authorize(DashboardContext context)
{ {
var ipAddress = context.Request.RemoteIpAddress;
// if unknown, assume not local // if unknown, assume not local
if (string.IsNullOrEmpty(context.Request.RemoteIpAddress)) if (string.IsNullOrEmpty(ipAddress))
{ {
return false; return false;
} }
// check if localhost // check if localhost
if (context.Request.RemoteIpAddress == "127.0.0.1" || context.Request.RemoteIpAddress == "::1") if (ipAddress == "127.0.0.1" || ipAddress == "0.0.0.1")
{ {
return true; return true;
} }
// compare with local address // compare with local address
if (context.Request.RemoteIpAddress == context.Request.LocalIpAddress) if (ipAddress == context.Request.LocalIpAddress)
{ {
return true; return true;
} }
// check if private ip // check if private ip
if (Helper.IsInnerIP(context.Request.RemoteIpAddress)) if (Helper.IsInnerIP(ipAddress))
{ {
return true; return true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment