Ver a proveniência

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

master
Savorboard há 6 anos
ascendente
cometimento
3b73274e5d
2 ficheiros alterados com 8 adições e 12 eliminações
  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 Ver ficheiro

@@ -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 Ver ficheiro

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


Carregando…
Cancelar
Guardar