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
All notable changes to this project will be documented in this file.
3
+
All notable changes to SafeWebCore will be documented in this file.
4
4
5
5
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
8
+
---
9
+
8
10
## [Unreleased]
9
11
12
+
## [1.1.0] — 2025-06-28
13
+
14
+
### Added
15
+
16
+
-**`HttpContext.GetCspNonce()` extension method** — Discoverable way to retrieve the per-request CSP nonce without magic strings. Available via `using SafeWebCore.Extensions;`.
17
+
```csharp
18
+
varnonce=HttpContext.GetCspNonce();
19
+
```
20
+
-**`NonceService.TryWriteNonce(Span<char>, out int)`** — Zero-allocation overload that writes the nonce directly into a caller-provided buffer. Ideal for high-throughput scenarios or writing directly into response buffers.
if (nonceService.TryWriteNonce(buffer, outintwritten))
24
+
{
25
+
// Use buffer[..written] — no heap allocation
26
+
}
27
+
```
28
+
-**`NonceService.NonceLength` constant** — Public constant (44) for the length of a generated nonce string. Eliminates magic numbers when pre-allocating buffers.
29
+
30
+
### Changed
31
+
32
+
-**CSP template is now pre-built once** in the middleware constructor instead of being rebuilt on every request. Only the lightweight `string.Replace("{nonce}", nonce)` runs per-request. This significantly reduces per-request allocations.
33
+
-**`CspOptions.Build()` uses `StringBuilder`** — Replaced `List<string>` + interpolated string allocations + `string.Join` with a pre-sized `StringBuilder(512)`. Eliminates ~20 intermediate string allocations per call.
34
+
-**`CspReportMiddleware` now passes `CancellationToken`** — `ReadToEndAsync` uses `context.RequestAborted` for proper cancellation when clients disconnect.
35
+
-**`CspNonceAttribute` uses C# pattern matching** — Collapsed nested conditionals into a single `is string { Length: > 0 } nonce` pattern expression.
36
+
-**Preset application extracted to `ApplyPreset` helper** — Internal `NetSecureHeadersOptions.ApplyPreset()` method consolidates the 20+ line property copy into a single reusable call. Adding new options in the future requires updating only one place.
37
+
38
+
### Compatibility
39
+
40
+
- ✅ **100% backwards compatible** with v1.0.0
41
+
- All existing public APIs (`AddNetSecureHeadersStrictAPlus`, `UseNetSecureHeaders`, `CspBuilder`, `[CspNonce]`, CSP reporting) remain unchanged
42
+
- No breaking changes to method signatures, behavior, or configuration
43
+
- All 40 existing tests pass without modification
44
+
45
+
---
46
+
47
+
## [1.0.0] — 2025-06-15
48
+
10
49
### Added
11
50
12
-
- Initial project structure
13
-
- CSP middleware foundation
14
-
- xUnit test project
51
+
- Strict A+ preset — `AddNetSecureHeadersStrictAPlus()` for one-line A+ configuration on securityheaders.com
52
+
- Fluent `CspBuilder` with full CSP Level 3 (W3C Recommendation) directive coverage
- 🎯 **Fluent CSP Builder** — type-safe, chainable API with full XML documentation for every directive
23
-
- ⚡ **Zero-allocation nonce generation** — `stackalloc` + `RandomNumberGenerator` on the hot path
23
+
- ⚡ **Zero-allocation nonce generation** — `stackalloc` + `RandomNumberGenerator` on the hot path, plus `TryWriteNonce(Span<char>)` for fully heap-free scenarios
24
+
- 🔍 **`HttpContext.GetCspNonce()`** — discoverable extension method to retrieve the per-request nonce
24
25
- 🛑 **Server header removal** — hides server technology from attackers
25
26
- 🔌 **Extensible** — add custom `IHeaderPolicy` implementations for any header
26
27
- 📊 **CSP violation reporting** — built-in middleware for `/csp-report` endpoint using Reporting API v1
@@ -31,7 +32,24 @@
31
32
|----------|--------|----------|
32
33
|**CSP Level 3** (W3C Recommendation) | ✅ Full | All 22 directives, nonce/hash, `strict-dynamic`, `report-to`|
-**`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
337
-**`worker-src`** — Dedicated directive for controlling Worker, SharedWorker, and ServiceWorker sources.
317
338
-**`manifest-src`** — Controls web app manifest loading.
318
339
-**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.
340
+
-**`report-to`** — Modern Reporting API v1 for CSP violation reporting.
320
341
-**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).
Copy file name to clipboardExpand all lines: docs/presets.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -209,6 +209,10 @@ This is useful for:
209
209
- Building custom presets based on the strict A+ baseline
210
210
- Inspecting the exact values at startup
211
211
212
+
### Building custom presets *(v1.1.0+)*
213
+
214
+
Internally, `AddNetSecureHeadersStrictAPlus` uses an `ApplyPreset` helper to copy all preset values. You can inspect `SecurePresets.StrictAPlus()` as a baseline and override properties using the customize callback — without needing to create a full custom configuration.
0 commit comments