You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A lightweight, high-performance .NET 10 middleware library that adds security headers to your ASP.NET Core applications. Targets an **A+ rating** on [securityheaders.com](https://securityheaders.com) out of the box.
4
+
5
+
## Two Ways to Use SafeWebCore
6
+
7
+
### Option 1 — Strict A+ Preset (fastest)
8
+
9
+
One line for the strictest A+ configuration. Defined in `ServiceCollectionExtensions.AddNetSecureHeadersStrictAPlus()`.
**SafeWebCore** is a lightweight, high-performance .NET 10 middleware library that adds security headers to your ASP.NET Core applications. It targets an **A+ rating** on [securityheaders.com](https://securityheaders.com) out of the box — zero configuration required.
8
12
@@ -11,13 +15,23 @@
11
15
## ✨ Features
12
16
13
17
- 🔒 **A+ in one line** — `AddNetSecureHeadersStrictAPlus()` configures the strictest security headers instantly
18
+
- 🛠️ **Fully custom** — `AddNetSecureHeaders(opts => { ... })` gives you complete control over every header
14
19
- 🧩 **Nonce-based CSP** — per-request cryptographic nonces for `script-src` and `style-src`
Copy file name to clipboardExpand all lines: docs/csp-configuration.md
+110-4Lines changed: 110 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,8 @@
2
2
3
3
Content Security Policy (CSP) is the most powerful security header for preventing XSS attacks. SafeWebCore provides a fluent builder and nonce-based enforcement out of the box.
4
4
5
+
SafeWebCore implements the **full CSP Level 3** (W3C Recommendation) directive set and forward-looking **CSP Level 4** features including Trusted Types and `fenced-frame-src`.
6
+
5
7
---
6
8
7
9
## How CSP Works
@@ -42,6 +44,7 @@ These control where resources can be loaded from.
-**`frame-src` split from `child-src`** — In CSP Level 2, `child-src` governed both frames and workers. Level 3 separates them: `frame-src` for `<frame>`/`<iframe>`, `worker-src` for Worker/SharedWorker/ServiceWorker.
316
+
-**`worker-src`** — Dedicated directive for controlling Worker, SharedWorker, and ServiceWorker sources.
317
+
-**`manifest-src`** — Controls web app manifest loading.
318
+
-**Granular script/style directives** — `script-src-elem`, `script-src-attr`, `style-src-elem`, `style-src-attr` provide fine-grained control beyond the base `script-src`/`style-src`.
319
+
-**`report-to`** — Replaces the deprecated `report-uri` directive with the modern Reporting API v1.
320
+
-**Nonce + hash + `strict-dynamic`** — The recommended approach per Google and the W3C. SafeWebCore generates a unique cryptographic nonce per request using `stackalloc` + `RandomNumberGenerator` (zero heap allocations).
321
+
322
+
### CSP Level 4 (Emerging) — ✅ Ready
323
+
324
+
| Directive | Purpose | Status |
325
+
|-----------|---------|--------|
326
+
|`require-trusted-types-for`| Enforces Trusted Types for DOM XSS sinks (`innerHTML`, `eval()`, etc.) | ✅ |
327
+
|`trusted-types`| Controls which Trusted Type policy names are allowed | ✅ |
0 commit comments