Dloizides.SecurityHeaders 0.1.0

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

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