Security.ConfigGuard 1.0.0

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

Security.ConfigGuard

Refuse to boot on a default/weak secret. A startup guard that makes "the dev sentinel reached production" an impossible-to-miss crash instead of a silent, forgeable-hash vulnerability.

Born from a real finding: a production API-key pepper was still the public dev sentinel 0000…0001, so anyone with the key format could recompute every stored hash. Rotating the value fixes the incident; this package fixes the bug class.

Install

dotnet add package Security.ConfigGuard

Use

var builder = WebApplication.CreateBuilder(args);

builder.AddSecretGuard(o =>
{
    o.Require("Auth:ApiKeyPepper");                      // present + non-empty + strong
    o.RejectKnownDefault(                                 // ...and never THIS value
        "Auth:ApiKeyPepper",
        "0000000000000000000000000000000000000000000000000000000000000001");
});

builder.AddSecretGuard(...) (the IHostApplicationBuilder overload) validates immediately, while the host is still being built — the process throws before Kestrel binds a port. An IServiceCollection overload is also available; it registers an IHostedService that throws from StartAsync, aborting host startup.

Environment semantics (read this)

Environment Behaviour
Production Throws WeakSecretException — the service does not boot
Staging Throws WeakSecretException — the service does not boot
Development Exempt — logs at Debug, boots
Testing Exempt — logs at Debug, boots
anything else Exempt unless added via EnforceIn(...)

Development and Testing are exempt by design: dev sentinels live in appsettings.Development.json and test harnesses reuse them. A guard that fired there would break every dev run and every test — and a mis-scoped guard crash-loops the very deployment it was meant to protect. Widen the set deliberately with o.EnforceIn("Production", "Staging", "Canary").

What counts as weak

Rejected generically, in this order:

Reason Example
Missing key absent, empty, or whitespace
KnownDefault exactly a value passed to RejectKnownDefault
TooShort shorter than MinimumLength (default 32 chars)
AllSameCharacter 0000…0000
AllSameByte abababab… (hex decoding to one repeated byte)
LowEntropy fewer than MinimumDistinctCharacters (default 4) distinct chars — this alone catches 0000…0001

Per-key tuning:

o.Require("Payments:WebhookSecret", r =>
{
    r.MinimumLength = 40;
    r.RejectKnownDefault("whsec_test_placeholder");
});

Secret hygiene

The secret value is never logged, echoed, or placed in an exception message. Only the config key name and a SecretWeakness reason are reported, so WeakSecretException is safe to log verbatim. Comparison is ordinal, not constant-time — this is config validation at boot, not an authentication path.

Adopters

  • poueni-api — guards Auth:ApiKeyPepper (the HMAC pepper behind tenants.api_key_hash).

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

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Security.ConfigGuard:

Package Downloads
Dloizides.ServiceDefaults

Aspire-style service defaults for ASP.NET Core: OpenTelemetry (logging/metrics/tracing) wiring, HTTP resilience + service discovery, standard health-check registration (via ServiceDefaults.HealthChecks), and the platform endpoint map (anonymous /health/live|start|ready Kubernetes probes plus an ACME HTTP-01 no-op). Extracted from ~8 services that had each hand-copied the ServiceDefaults/Extensions.cs; normalizes the PostgressConnection connection-string typo by resolving both the correct (PostgresConnection) and legacy-typo keys.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 730 7/11/2026