AngelSix.AspNetCore.ClientIp 1.0.0

dotnet add package AngelSix.AspNetCore.ClientIp --version 1.0.0
                    
NuGet\Install-Package AngelSix.AspNetCore.ClientIp -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="AngelSix.AspNetCore.ClientIp" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="AngelSix.AspNetCore.ClientIp" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="AngelSix.AspNetCore.ClientIp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add AngelSix.AspNetCore.ClientIp --version 1.0.0
                    
#r "nuget: AngelSix.AspNetCore.ClientIp, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package AngelSix.AspNetCore.ClientIp@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=AngelSix.AspNetCore.ClientIp&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=AngelSix.AspNetCore.ClientIp&version=1.0.0
                    
Install as a Cake Tool

AngelSix.AspNetCore.ClientIp

Resolves the true client IP behind a reverse proxy, and decides local-network access safely.

Behind a proxy — Caddy, nginx, Traefik, especially in Docker — the connection your app can see belongs to the proxy, not the caller. The three ways that usually gets handled are all wrong, and each fails in its own direction:

  • Reading Connection.RemoteIpAddress alone. In Docker that is the bridge gateway, which is an RFC1918 private address. Any "local network only" check on it therefore returns true for every caller on the internet.
  • Reading X-Forwarded-For directly. Any client can set that header. IP bans and rate limits then become one header away from useless, and whatever address an attacker puts in it is the one that gets banned — so they can pick a victim.
  • Deciding trust after UseForwardedHeaders has run. That middleware overwrites RemoteIpAddress with the forwarded client and consumes the header, so the peer is already gone. Checks written after it see the client where they expect the proxy, conclude nothing is trustworthy, and lock out the legitimate local network.

This package does the one thing that works: capture the peer first, believe a forwarded header only when that peer is a configured proxy, and refuse rather than guess when it cannot tell.

Usage

app.UseAngelSixClientIp();   // FIRST — before logging, rate limiting, bans, auth
ClientIpResolver.GetClientIp(context);            // logs, bans, rate-limit partition keys
ClientIpResolver.IsLocalNetworkRequest(context);  // admin / setup gates — fails closed
ClientIpResolver.IsPrivateOrLoopback(address);

Configuration

Set KNOWN_PROXY to the address your app sees inbound traffic as. In Docker that is the bridge gateway (e.g. 172.30.0.1) — not the host the proxy runs on, because the published port NAT rewrites the source before it arrives. This catches people out constantly.

KNOWN_PROXY=172.30.0.1

Loopback is always trusted. Multiple values are comma-separated. Or configure in code:

var options = ClientIpOptions.FromEnvironment();
options.KnownProxies.Add(IPAddress.Parse("10.0.0.5"));
ClientIpResolver.Configure(options);

Surface it in your health check

Getting this wrong is silent: nothing throws, nothing logs, every client IP just collapses onto one value and stays that way until somebody notices by accident.

var (healthy, detail) = ProxyTrustReport.Describe();

When it is wrong, detail names the exact KNOWN_PROXY value to set — so the alert carries its own fix.

Licence

MIT.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 281 8/3/2026