UnambitiousFx.Myelin 1.2.0

dotnet add package UnambitiousFx.Myelin --version 1.2.0
                    
NuGet\Install-Package UnambitiousFx.Myelin -Version 1.2.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="UnambitiousFx.Myelin" Version="1.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="UnambitiousFx.Myelin" Version="1.2.0" />
                    
Directory.Packages.props
<PackageReference Include="UnambitiousFx.Myelin" />
                    
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 UnambitiousFx.Myelin --version 1.2.0
                    
#r "nuget: UnambitiousFx.Myelin, 1.2.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 UnambitiousFx.Myelin@1.2.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=UnambitiousFx.Myelin&version=1.2.0
                    
Install as a Cake Addin
#tool nuget:?package=UnambitiousFx.Myelin&version=1.2.0
                    
Install as a Cake Tool

UnambitiousFx.Myelin

Build Status NuGet codecov License: MIT .NET Documentation

SSRF-safe outbound HTTP for .NET. Use it whenever your server fetches a URL it did not write itself: webhooks, « import from URL », link previews, avatar or icon fetchers, third-party callbacks.

A plain HttpClient connects to 127.0.0.1, to the cloud metadata endpoint 169.254.169.254 or to your private network if the URL says so. Checking the URL text is not enough: 0x7f000001 is 127.0.0.1, a public name can resolve to a private address (or change its answer between your check and the connection), and a harmless URL can redirect to a harmful one. Myelin closes those doors.

Myelin is the sheath around a nerve fibre that keeps the signal from leaking. Here, it keeps your server's requests from leaking into your own network.

🔧 Compatibility & support

  • Dependencies: Microsoft.Extensions.Http, Logging.Abstractions and Options only.
  • NativeAOT and trimming compatible: CI publishes and runs an AOT binary on every change.
  • Supported .NET versions: net8.0, net9.0, net10.0, and net11.0.

🎯 Features

  • Public addresses only: every special-purpose range of the IANA IPv4 and IPv6 registries is refused (private, loopback, link-local and cloud metadata, carrier-grade NAT, documentation, multicast…), IPv4-mapped and NAT64 forms judged on the IPv4 address they embed.
  • DNS rebinding proof: the host is resolved once, every answer checked, and the socket connects to exactly those addresses. No proxy.
  • HTTPS only, no credentials in the URL, optional host allow-list with *.example.com wildcards.
  • Every redirect revalidated for a GET; a POST or a request with extra headers is never redirected.
  • Bounded time and size, declared or streamed.
  • Quiet logs: a refusal is logged with its host and reason, never a path that may hold a secret.
  • IHttpClientFactory integration: AddHttpClient<T>().UseMyelin().

📦 Installation

dotnet add package UnambitiousFx.Myelin

🚀 Quick start

using UnambitiousFx.Myelin;

builder.Services.AddMyelin(o =>
{
    o.AllowedHosts = ["api.example.com", "*.cdn.example.org"]; // optional: empty allows any public host
    o.UserAgent = "MyApp/1.0";
});

public sealed class IconFetcher(SafeHttpClient http)
{
    public async Task<byte[]?> FetchAsync(Uri url, CancellationToken ct)
    {
        try
        {
            var response = await http.GetAsync(url, maxBytes: 512_000, ct);
            return response.Status == HttpStatusCode.OK ? response.Body : null;
        }
        catch (OutboundRefusedException refused) // refused.Reason: "address_refused", "not_https", "too_large"...
        {
            return null;
        }
    }
}

Already using IHttpClientFactory?

builder.Services.AddHttpClient<WebhookSender>().UseMyelin(o => o.AllowedHosts = ["hooks.example.com"]);

📚 API

Type Role
SafeHttpClient GetAsync (redirects revalidated), PostJsonAsync, SendOnceAsync; bodies read within maxBytes.
MyelinHandler.Create(resolver?) The SocketsHttpHandler that resolves, checks and connects.
AddressPolicy.IsAllowed(IPAddress) The address check on its own.
MyelinOptions AllowedHosts, UserAgent, Timeout, MaxRedirects.
OutboundRefusedException Reason (see RefusalReasons) and Host.
IHostResolver Replace DNS resolution (tests, custom resolvers).

🤝 Contributing

See CONTRIBUTING.md.

📄 License

MIT.

Product 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 is compatible.  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.  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
1.2.0 48 11/21/2026
1.1.0 4,667 11/11/2026
1.0.0 1,149 11/10/2026