Paduraksa.ProxyProtocol.AspNetCore
0.1.0
dotnet add package Paduraksa.ProxyProtocol.AspNetCore --version 0.1.0
NuGet\Install-Package Paduraksa.ProxyProtocol.AspNetCore -Version 0.1.0
<PackageReference Include="Paduraksa.ProxyProtocol.AspNetCore" Version="0.1.0" />
<PackageVersion Include="Paduraksa.ProxyProtocol.AspNetCore" Version="0.1.0" />
<PackageReference Include="Paduraksa.ProxyProtocol.AspNetCore" />
paket add Paduraksa.ProxyProtocol.AspNetCore --version 0.1.0
#r "nuget: Paduraksa.ProxyProtocol.AspNetCore, 0.1.0"
#:package Paduraksa.ProxyProtocol.AspNetCore@0.1.0
#addin nuget:?package=Paduraksa.ProxyProtocol.AspNetCore&version=0.1.0
#tool nuget:?package=Paduraksa.ProxyProtocol.AspNetCore&version=0.1.0
Paduraksa.ProxyProtocol.AspNetCore
PROXY protocol (HAProxy v1 and v2) support for Kestrel. A connection middleware reads the header from a load balancer, then makes the connection's remote and
local endpoints the client's, so HttpContext.Connection.RemoteIpAddress and everything built on it (rate limits, logging, IP rules) sees the real client.
The parsing is Paduraksa.ProxyProtocol: strict, fuzzed and allocation-free.
using Paduraksa.ProxyProtocol.AspNetCore;
builder.WebHost.ConfigureKestrel(kestrel =>
{
kestrel.ListenAnyIP(8080, listen =>
{
listen.UseProxyProtocol(options =>
{
// System.Net.IPNetwork in full: Microsoft.AspNetCore.HttpOverrides has an IPNetwork too.
options.TrustedProxies = [System.Net.IPNetwork.Parse("10.0.0.0/8")]; // your load balancers
options.HeaderTimeout = TimeSpan.FromSeconds(3);
// Optional, for counters and logs; an exception it throws is swallowed.
options.OnOutcome = (outcome, connection) => metrics.Count(outcome);
});
listen.UseHttps(certificate); // after UseProxyProtocol: the header comes before the TLS handshake
});
});
Warning: call
UseProxyProtocolbeforeUseHttps. The load balancer's header comes first on the wire, so it has to be read before the TLS handshake. In the other order every HTTPS connection through the load balancer is closed during the TLS handshake and the app never sees a request: it looks like the proxy refusing everyone, health checks included. Kestrel doesn't let the middleware see whetherUseHttpsalready ran, so this isn't detected for you. If every connection from the load balancer fails, check the order first.
Behaviour
- Secure by default.
TrustedProxiesis empty, which refuses every connection until you add your load balancers; a warning in the log says so at startup. A connection from anywhere else is aborted without reading a byte. - Unix sockets have no peer address to match, so a
ListenUnixSocketlistener refuses every connection until you setTrustUnixSockets = true. The socket's file permissions are then the whole check: let only your proxy connect. - Refusals are not logged one by one.
OnOutcomegets the outcome and the connection (for a refused one,connection.RemoteEndPointis the peer that was refused), so count or log them there. - Required by default. A trusted peer that sends no valid header within
HeaderTimeout(default 3 s), or whose header is malformed or overMaxV2Length(default 4096), is aborted. Required = falsemakes the header optional: a trusted peer whose first bytes don't begin a header goes on unchanged, with the socket's endpoints. Untrusted peers go on unchanged too, and a header they send is not honoured. A header that begins correctly and then breaks still aborts.- On success the connection's
RemoteEndPointandLocalEndPointbecome the header's source and destination (when it carries addresses;LOCALandUNKNOWNkeep the socket's), andIProxyProtocolFeatureexposes the parsed header and the proxy's own endpoint. - Trust matching treats an IPv4-mapped IPv6 peer (
::ffff:10.0.0.1, what a dual-mode listener reports) as IPv4. - QUIC / HTTP/3 has no connection middleware, so the PROXY protocol doesn't apply there.
Keep the listener reachable by the load balancer alone: anything that can connect from a trusted address can claim any client address.
Targets .NET 10 and .NET 8.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. 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. |
-
net10.0
- Paduraksa.ProxyProtocol (>= 0.1.0)
-
net8.0
- Paduraksa.ProxyProtocol (>= 0.1.0)
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 |
|---|---|---|
| 0.1.0 | 122 | 11/13/2026 |