Dloizides.SecurityHeaders
0.1.0
dotnet add package Dloizides.SecurityHeaders --version 0.1.0
NuGet\Install-Package Dloizides.SecurityHeaders -Version 0.1.0
<PackageReference Include="Dloizides.SecurityHeaders" Version="0.1.0" />
<PackageVersion Include="Dloizides.SecurityHeaders" Version="0.1.0" />
<PackageReference Include="Dloizides.SecurityHeaders" />
paket add Dloizides.SecurityHeaders --version 0.1.0
#r "nuget: Dloizides.SecurityHeaders, 0.1.0"
#:package Dloizides.SecurityHeaders@0.1.0
#addin nuget:?package=Dloizides.SecurityHeaders&version=0.1.0
#tool nuget:?package=Dloizides.SecurityHeaders&version=0.1.0
Dloizides.SecurityHeaders
Global security headers for ASP.NET Core APIs (ServiceDefaults 2.0, security floor row 8).
builder.Services.AddDloizidesSecurityHeaders();
app.UseDloizidesSecurityHeaders();
| Header | Value |
|---|---|
| X-Content-Type-Options | nosniff, always |
| Content-Security-Policy | default-src 'none'; frame-ancestors 'none'; base-uri 'none'; form-action 'none' unless the endpoint set its own |
| Referrer-Policy | no-referrer unless the endpoint set its own |
| Permissions-Policy | camera, microphone, geolocation and other sensors denied |
| Strict-Transport-Security | max-age=31536000; includeSubDomains on HTTPS requests outside Development |
Headers are written in OnStarting, so they survive the exception handler clearing the response.
Options (validated at startup): ContentSecurityPolicy (must contain frame-ancestors 'none'), PermissionsPolicy (non-empty), HstsMaxAge (at least 365 days).
Order behind a TLS-terminating ingress
HSTS is sent only when Request.IsHttps is true. Behind an ingress that terminates TLS, call app.UseForwardedHeaders() (with X-Forwarded-Proto) before UseDloizidesSecurityHeaders(), or no HSTS is sent. ServiceDefaults 2.0 fixes this order for you.
Docs UI (Swagger, Scalar)
The default API CSP (default-src 'none') blocks the scripts and styles of a docs UI. An endpoint or middleware that sets its own Content-Security-Policy before the response starts keeps it unchanged; this package adds a separate frame-ancestors 'none' policy beside it.
Endpoint values never go below the floor
An endpoint CSP is kept untouched and a second CSP policy frame-ancestors 'none' is added beside it; browsers enforce every policy they receive (CSP3), so the page can never be framed. An endpoint Referrer-Policy is kept only if it is no-referrer, same-origin, strict-origin or strict-origin-when-cross-origin; anything else becomes no-referrer.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Dloizides.SecurityHeaders:
| 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 |
|---|---|---|
| 0.1.0 | 148 | 11/21/2026 |