Guías y Recetas — Security
L3StableNuGet: v1.0.0Local HEAD: v2.2.0AOT: Partial
Patrones verificados de defensa SSRF y MFA compilados en .NET 10 (ImplicitUsings=disable, Nullable=enable).
Receta 1: Guardia SSRF Saliente con SafeSocketsHttpHandler
Sección titulada «Receta 1: Guardia SSRF Saliente con 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); }}Receta 2: Generación y Validación TOTP con TotpService (EricksonLopez.Security.Mfa)
Sección titulada «Receta 2: Generación y Validación TOTP con TotpService (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); }}