Meziantou.Framework.Http.ServerSideRequestForgery 2.0.2

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Meziantou.Framework.Http.ServerSideRequestForgery --version 2.0.2
                    
NuGet\Install-Package Meziantou.Framework.Http.ServerSideRequestForgery -Version 2.0.2
                    
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="Meziantou.Framework.Http.ServerSideRequestForgery" Version="2.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Meziantou.Framework.Http.ServerSideRequestForgery" Version="2.0.2" />
                    
Directory.Packages.props
<PackageReference Include="Meziantou.Framework.Http.ServerSideRequestForgery" />
                    
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 Meziantou.Framework.Http.ServerSideRequestForgery --version 2.0.2
                    
#r "nuget: Meziantou.Framework.Http.ServerSideRequestForgery, 2.0.2"
                    
#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 Meziantou.Framework.Http.ServerSideRequestForgery@2.0.2
                    
#: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=Meziantou.Framework.Http.ServerSideRequestForgery&version=2.0.2
                    
Install as a Cake Addin
#tool nuget:?package=Meziantou.Framework.Http.ServerSideRequestForgery&version=2.0.2
                    
Install as a Cake Tool

Meziantou.Framework.Http.ServerSideRequestForgery

SSRF protection for SocketsHttpHandler using scheme allow-listing and runtime IP validation.

Usage

using Meziantou.Framework.Http.ServerSideRequestForgery;

var options = new ServerSideRequestForgeryOptions
{
    ResolutionStrategy = IpAddressResolutionStrategy.PreferIpv4,
    DisallowMixedSafeAndUnsafeIpAddresses = true,
};

options.SafeSchemes.Add("https");
options.SafeSchemes.Add("wss");
options.UnsafeIpNetworks.Add(IPNetwork.Parse("203.0.113.0/24"));
options.SafeIpNetworks.Add(IPNetwork.Parse("198.51.100.10/32"));

var handler = new SocketsHttpHandler();
handler.ConfigureSsrf(options);

using var httpClient = new HttpClient(handler, disposeHandler: true);

Behavior

  • Validates request scheme against SafeSchemes.
  • Resolves DNS on every connection attempt to avoid TOCTOU vulnerabilities.
  • Validates each resolved address against UnsafeIpNetworks and SafeIpNetworks.
  • Optionally rejects mixed safe/unsafe DNS responses.
  • Uses IpAddressResolutionStrategy to select the final address (Ipv4Only, Ipv6Only, PreferIpv4, Random, RoundRobin).
  • Rejects connections that target an HTTP proxy.

Proxies

Validation happens when the connection is opened, which for a proxied request is the connection to the proxy, not to the target. The proxy then reaches the real target itself, over a tunnel this library cannot inspect, so a proxied request cannot be validated at all.

Rather than appear to protect such a request, the handler rejects it with a ServerSideRequestForgeryException. Note that SocketsHttpHandler.UseProxy defaults to true and HttpClient.DefaultProxy reads HTTP_PROXY, HTTPS_PROXY and ALL_PROXY, so a proxy can be in effect without the application configuring one. Send requests that need SSRF protection through a handler with UseProxy = false:

var handler = new SocketsHttpHandler { UseProxy = false };
handler.ConfigureSsrf(options);

Requests the proxy is configured to bypass are connected to directly and are validated normally.

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.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
2.0.5 39 9/11/2026
2.0.4 87 9/6/2026
2.0.3 85 9/3/2026
2.0.2 95 8/29/2026
2.0.1 99 8/9/2026
2.0.0 122 7/5/2026
1.0.2 120 6/28/2026
1.0.1 111 6/13/2026
1.0.0 118 5/18/2026