SimpleOwaspHeaders.Cookies 1.0.2

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

SimpleOwaspHeaders

SimpleOwaspHeaders

NuGet .NET Build License: MIT Tests

Target framework: net10.0 · Language: C# · Test runner: xUnit

Route-aware OWASP security headers for ASP.NET Core 10, configured with IOptions<T> and appsettings.json.

Install

dotnet add package SimpleOwaspHeaders
# optional cookie hardening
dotnet add package SimpleOwaspHeaders.Cookies

Quick start

builder.Services.AddSimpleOwaspHeaders(options =>
{
    options.DefaultPolicy = SecurityHeaderPolicy.OwaspRecommended;

    options.AddNamedPolicy("Admin", policy => policy
        .WithContentSecurityPolicy(csp => csp
            .ScriptSources("'self'")
            .ImageSources("'self'", "data:")));

    options.ForPath("/admin", "Admin");
    options.ForPathRegex(@"^/api/public/.*", policy => policy
        .WithContentSecurityPolicy(csp => csp.DefaultSources("'none'")));

    options.IgnorePath("/health");
});

app.UseSimpleOwaspHeaders();
app.MapSimpleOwaspHeadersDiagnostics(); // optional — dev diagnostics when EnableDiagnosticsEndpoint = true
await app.RunOrExportSecurityReportAsync();

appsettings.json

{
  "SimpleOwaspHeaders": {
    "DefaultPreset": "OwaspRecommended",
    "EnableDiagnosticsEndpoint": true
  }
}
builder.Services.AddSimpleOwaspHeaders(builder.Configuration.GetSection("SimpleOwaspHeaders"));

How it works

  1. AddSimpleOwaspHeaders — register options, presets, and path policies
  2. ValidateOnStart — fail fast on invalid configuration
  3. UseSimpleOwaspHeaders — middleware runs on each request
  4. Policy resolver — match path, merge policies, pick effective headers
  5. Response — security header values written to the HTTP response

Each request passes through the middleware. The resolver picks the effective policy for that path, merges it onto the default, and the middleware writes the header values to the response.

See docs/POLICY_MERGE.md for merge order and path-matching rules.

Features

  • Options-firstAddSimpleOwaspHeaders() + startup validation
  • Per-route CSP — prefix, regex, and [SecureHeaders("Name")] endpoint policies; CSP directives merge individually
  • PresetsOwaspRecommended, Strict, ApiOnly, SpaWithCdn(cdnUrl)
  • Full CSP builder — all major directives, data:, nonces, Report-Only, report-to
  • Clear-Site-Data — path-specific (logout flows)
  • Permission-Policy — experimental, opt-in
  • Reporting-Endpoints — pairs with CSP report-to
  • SimpleOwaspHeaders.CookiesHttpOnly, Secure, SameSite on Set-Cookie
  • Roslyn analyzers — compile-time checks for common misconfiguration (docs/ANALYZERS.md)
  • Diagnostics — HTML reports with per-directive CSP breakdown (dev only)

Diagnostics (development)

Enable with EnableDiagnosticsEndpoint = true in configuration (development environment only).

HTTP endpoints (via MapSimpleOwaspHeadersDiagnostics):

Endpoint Output
GET /_simple-owasp-headers JSON for the current request
GET /_simple-owasp-headers/report?path=/admin HTML path report with CSP directive breakdown
GET /_simple-owasp-headers/matrix Configuration matrix across all routes
GET /_simple-owasp-headers/matrix?format=json Matrix data as JSON

Build-time / CI export (via RunOrExportSecurityReportAsync, CLI flags, env vars, or MSBuild):

Export the configuration matrix without starting the web server:

dotnet run -- --export-security-report ./artifacts/security-headers-report.html
dotnet run -- --export-security-report ./report.html --export-security-report-format=json

Environment variables:

  • SIMPLE_OWASP_HEADERS_REPORT_PATH — output path
  • SIMPLE_OWASP_HEADERS_REPORT_FORMAThtml, json, or both (default)

MSBuild (web projects referencing the package):

<PropertyGroup>
  <ExportSimpleOwaspHeadersReport>true</ExportSimpleOwaspHeadersReport>
  <SimpleOwaspHeadersReportOutputPath>$(OutputPath)security-headers-report.html</SimpleOwaspHeadersReportOutputPath>
</PropertyGroup>

AddSimpleOwaspHeaders() registers a startup export hook, so MSBuild export works without RunOrExportSecurityReportAsync() — export flags or SIMPLE_OWASP_HEADERS_REPORT_PATH exit the process after writing the report.

Sample app

cd samples/SimpleOwaspHeaders.Sample
dotnet run
Route Behaviour
/ Default OWASP headers
/admin Named Admin CSP policy
/api/public/info Regex path policy
/logout Clear-Site-Data
/_simple-owasp-headers/report HTML security report
/_simple-owasp-headers/matrix Configuration matrix

Contributing

Contributions are welcome. See CONTRIBUTING.md for setup, project layout, and how to add presets, policies, or analyzers.

Please read our Code of Conduct before participating.

Quick start for contributors:

git clone https://github.com/kearns2000/SimpleOwaspHeaders.git
cd SimpleOwaspHeaders
dotnet build -c Release
dotnet test -c Release

Open a pull request with tests for any behaviour change. CI runs build and test on every PR.

License

MIT

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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.2 95 7/4/2026
1.0.1 94 7/4/2026
1.0.0 79 7/4/2026