Skip to content

Commit

Permalink
add support for bypass proxy authentication for clients from current …
Browse files Browse the repository at this point in the history
…LAN (#122)
  • Loading branch information
atauenis committed Apr 22, 2024
1 parent 356ba9b commit afa0566
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ConfigFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,11 @@ static class ConfigFile
/// </summary>
public static string ContentDirectory = "./html";

/// <summary>
/// Bypass client authentication for local IPs
/// </summary>
public static bool OpenForLocalIPs = false;



/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions ConfigFileLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,9 @@ public static void ProcessConfiguration()
case "AuthenticateRealm":
ConfigFile.AuthenticateRealm = Line.Value;
break;
case "OpenForLocalIPs":
ConfigFile.OpenForLocalIPs = ToBoolean(Line.Value);
break;
default:
Log.WriteLine(true, false, "Warning: Invalid authentication option at {0}.", Line.Location);
break;
Expand Down
5 changes: 5 additions & 0 deletions HttpTransit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ public void ProcessTransit()
//PAC is always unprotected
break;
default:
if (ConfigFile.OpenForLocalIPs && IsLanIP(ClientRequest.RemoteEndPoint.Address))
{
Log.WriteLine(" Bypassed authorization of local client.");
break;
}
if (string.IsNullOrEmpty(ClientRequest.Headers["Proxy-Authorization"]))
{
Log.WriteLine(" Unauthorized client.");
Expand Down
15 changes: 15 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -976,6 +976,21 @@ from ipa in Netif.GetIPProperties().UnicastAddresses
return IPs.ToArray();
}

/// <summary>
/// Check if IP is inside LAN (behind router)
/// </summary>
/// <param name="address">The IP Address to check</param>
/// <returns><c>True</c> if it's local address or <c>False</c> if it's from Internet</returns>
public static bool IsLanIP(IPAddress address)
{
var ping = new Ping();
var rep = ping.Send(address, 100, new byte[] { 1 }, new PingOptions()
{
DontFragment = true,
Ttl = 1
});
return rep.Status != IPStatus.TtlExpired && rep.Status != IPStatus.TimedOut && rep.Status != IPStatus.TimeExceeded;
}

/// <summary>
/// Get this proxy server name and port
Expand Down

0 comments on commit afa0566

Please sign in to comment.