Skip to content

Commit

Permalink
Improve loopback address detection (HangfireIO#2436)
Browse files Browse the repository at this point in the history
  • Loading branch information
meziantou authored Aug 28, 2024
1 parent 4e95258 commit 43c5456
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

using System;
using System.Collections.Generic;
using System.Net;

namespace Hangfire.Dashboard
{
Expand All @@ -39,7 +40,8 @@ public bool Authorize(DashboardContext context)
if (context.Request.RemoteIpAddress == context.Request.LocalIpAddress)
return true;

return false;
// Handle addresses such as ::ffff:127.0.0.1 (IP v4 mapped to IP v6)
return IPAddress.TryParse(context.Request.RemoteIpAddress, out IPAddress address) && IPAddress.IsLoopback(address);
}

#if FEATURE_OWIN
Expand All @@ -59,7 +61,8 @@ public bool Authorize(IDictionary<string, object> owinEnvironment)
if (context.Request.RemoteIpAddress == context.Request.LocalIpAddress)
return true;

return false;
// Handle addresses such as ::ffff:127.0.0.1 (IP v4 mapped to IP v6)
return IPAddress.TryParse(context.Request.RemoteIpAddress, out IPAddress address) && IPAddress.IsLoopback(address);
}
#endif
}
Expand Down

0 comments on commit 43c5456

Please sign in to comment.