Browse Source

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

master
Savorboard 6 years ago
parent
commit
666fdc4685
2 changed files with 8 additions and 12 deletions
  1. +3
    -8
      src/DotNetCore.CAP/Dashboard/DashboardRequest.cs
  2. +5
    -4
      src/DotNetCore.CAP/Dashboard/LocalRequestsOnlyAuthorizationFilter.cs

+ 3
- 8
src/DotNetCore.CAP/Dashboard/DashboardRequest.cs View File

@@ -28,19 +28,14 @@ namespace DotNetCore.CAP.Dashboard

public CapDashboardRequest(HttpContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}

_context = context;
_context = context ?? throw new ArgumentNullException(nameof(context));
}

public override string Method => _context.Request.Method;
public override string Path => _context.Request.Path.Value;
public override string PathBase => _context.Request.PathBase.Value;
public override string LocalIpAddress => _context.Connection.LocalIpAddress.ToString();
public override string RemoteIpAddress => _context.Connection.RemoteIpAddress.ToString();
public override string LocalIpAddress => _context.Connection.LocalIpAddress.MapToIPv4().ToString();
public override string RemoteIpAddress => _context.Connection.RemoteIpAddress.MapToIPv4().ToString();

public override string GetQuery(string key)
{


+ 5
- 4
src/DotNetCore.CAP/Dashboard/LocalRequestsOnlyAuthorizationFilter.cs View File

@@ -9,26 +9,27 @@ namespace DotNetCore.CAP.Dashboard
{
public bool Authorize(DashboardContext context)
{
var ipAddress = context.Request.RemoteIpAddress;
// if unknown, assume not local
if (string.IsNullOrEmpty(context.Request.RemoteIpAddress))
if (string.IsNullOrEmpty(ipAddress))
{
return false;
}

// 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;
}

// compare with local address
if (context.Request.RemoteIpAddress == context.Request.LocalIpAddress)
if (ipAddress == context.Request.LocalIpAddress)
{
return true;
}

// check if private ip
if (Helper.IsInnerIP(context.Request.RemoteIpAddress))
if (Helper.IsInnerIP(ipAddress))
{
return true;
}


Loading…
Cancel
Save