Guides & Recipes — Security
L3StableNuGet: v1.0.0Local HEAD: v2.2.0AOT: Partial
Verified SSRF protection and MFA configuration patterns compiled on .NET 10 (ImplicitUsings=disable, Nullable=enable).
Recipe 1: Outbound SSRF Guard with SafeSocketsHttpHandler
Section titled “Recipe 1: Outbound SSRF Guard with SafeSocketsHttpHandler”using System.Net.Http;using EricksonLopez.Security.Network;
namespace Example.SecurityQuickStart;
public static class SsrfHttpClientRecipe{ public static HttpClient CreateHardenedClient() { var options = new SsrfProtectionOptions { RequireHttps = true, BlockCloudMetadata = true, RestrictToAllowedHostnames = true, }; options.AllowedHostnames.Add("api.partner.com");
var handler = new SafeSocketsHttpHandler(options: options); return new HttpClient(handler, disposeHandler: true); }}Recipe 2: TotpService Secret & Code Generation (EricksonLopez.Security.Mfa)
Section titled “Recipe 2: TotpService Secret & Code Generation (EricksonLopez.Security.Mfa)”using System;using EricksonLopez.Security.Mfa;
namespace Example.SecurityQuickStart;
public static class TotpRecipe{ public static bool VerifyProvisionedCode() { var service = new TotpService(); TotpSetupInfo setup = service.GenerateSetupInfo("NorthwindApp", "user@example.com"); string code = service.ComputeCode(setup.SecretKey, DateTimeOffset.UtcNow); return service.VerifyCode(setup.SecretKey, code, DateTimeOffset.UtcNow); }}