Security.ConfigGuard
1.0.0
dotnet add package Security.ConfigGuard --version 1.0.0
NuGet\Install-Package Security.ConfigGuard -Version 1.0.0
<PackageReference Include="Security.ConfigGuard" Version="1.0.0" />
<PackageVersion Include="Security.ConfigGuard" Version="1.0.0" />
<PackageReference Include="Security.ConfigGuard" />
paket add Security.ConfigGuard --version 1.0.0
#r "nuget: Security.ConfigGuard, 1.0.0"
#:package Security.ConfigGuard@1.0.0
#addin nuget:?package=Security.ConfigGuard&version=1.0.0
#tool nuget:?package=Security.ConfigGuard&version=1.0.0
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 behindtenants.api_key_hash).
License
MIT
| Product | Versions 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. |
-
net8.0
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.0)
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 |