a security library for .net web development
Repo MPCoreDeveloper/SafeWebCore, read from GitHub 2 d ago. MPCoreDeveloper has not joined Take My Repo.
MPCoreDeveloper/SafeWebCore is a public repo on GitHub by MPCoreDeveloper. a security library for .net web development. It declares the MIT license on GitHub. It is written mainly in C#, has 7 stars and last changed on 2026-11-15. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read from GitHub on 2026-11-23.
In the maintainer's words. Shown from GitHub; Take My Repo does not keep a copy.
SafeWebCore is a lightweight, high-performance .NET 10 and .NET 11 middleware library that adds security headers to your ASP.NET Core applications. It targets an A+ rating on securityheaders.com out of the box โ zero configuration required.
Current version: 1.9.0
๐ A+ in one line โ AddNetSecureHeadersStrictAPlus() configures the strictest security headers instantly
๐งญ App-profile presets โ ready-made profiles for API, MVC, Blazor, and SPA reverse-proxy apps
๐ ๏ธ Fully custom โ AddNetSecureHeaders(opts => { ... }) gives you complete control over every header
โ๏ธ Configuration binding โ AddNetSecureHeadersFromConfiguration(...) binds NetSecureHeadersOptions directly from configuration
๐ฆ๏ธ Environment-aware rollout โ opt-in helpers can default CSP to report-only outside production for safer rollout
๐งฉ Nonce-based CSP โ per-request cryptographic nonces for script-src and style-src
๐งท Razor nonce TagHelpers โ auto-inject nonce attributes on <script> and <style> when available
๐ฃ๏ธ Path-based policies โ apply different security profiles per route prefix with longest-prefix matching
๐ฏ Endpoint metadata overrides โ skip headers or force CSP report-only per endpoint
๐งช Startup configuration validation โ invalid combinations fail fast during startup
๐ CSP Report-Only support โ ship policies safely before enforcing
๐งฑ Typed policy builders โ strongly typed builders for Referrer-Policy, Permissions-Policy, and COEP/COOP/CORP values
๐งฐ Optional additional headers โ opt-in support for Origin-Agent-Cluster, X-Robots-Tag, and Clear-Site-Data
๐ Full CSP Level 3 (W3C Recommendation) โ all directives including worker-src, manifest-src, frame-src, script-src-elem/attr, style-src-elem/attr, report-to, nonce/hash support, strict-dynamic
๐ฎ CSP Level 4 ready โ Trusted Types (require-trusted-types-for, trusted-types), fenced-frame-src (Privacy Sandbox)
๐ฏ Fluent CSP Builder โ type-safe, chainable API with full XML documentation for every directive
โก Zero-allocation nonce generation โ stackalloc + RandomNumberGenerator on the hot path, plus TryWriteNonce(Span<char>) for fully heap-free scenarios
๐ HttpContext.GetCspNonce() โ discoverable extension method to retrieve the per-request nonce
๐ Server header removal โ hides server technology from attackers
๐ Extensible โ add custom IHeaderPolicy implementations for any header
๐ CSP violation reporting โ built-in middleware for /csp-report endpoint using Reporting API v1
๐ Diagnostics preview โ MapSafeWebCoreDiagnostics(...) for an opt-in JSON preview of effective headers, path-policy resolution, and CSP mode
๐ JWT authority validation โ opt-in SafeWebCore.JwtBearer companion module turns a broken JWT authority into a fail-fast startup error or a loud Error log (solves dotnet/aspnetcore#67991, reported by Stephan van Rooij), plus optional token hardening
๐ Opt-in metrics โ System.Diagnostics.Metrics counters for core middleware and fraud detection
๐จ Fraud action pipeline โ IFraudEventSink / FraudEvent for reacting to fraud analysis results (logging, webhooks, custom actions)
๐ฆ Companion packages โ SafeWebCore.JwtBearer, SafeWebCore.FraudDetection, SafeWebCore.Analyzers (preview), and SafeWebCore.Testing (preview)
๐ Recipe docs โ practical integration guides under docs/recipes/
โ Actionable startup validation โ remediation guidance for CSP mode, path prefixes, additional headers, and reporting endpoints
using SafeWebCore.Builder;
builder.Services.AddNetSecureHeaders(opts =>
{
opts.ReferrerPolicyValue = new ReferrerPolicyBuilder()
.StrictOriginWhenCrossOrigin()
.Build();
opts.PermissionsPolicyValue = new PermissionsPolicyBuilder()
.Disable(PermissionsFeature.Camera)
.Disable(PermissionsFeature.Microphone)
.AllowSelf(PermissionsFeature.Geolocation)
.Build();
var crossOrigin = new CrossOriginPolicyBuilder()
.CoepRequireCorp()
.CoopSameOrigin()
.CorpSameOrigin()
.Build();
opts.CoepValue = crossOrigin.Coep;
opts.CoopValue = crossOrigin.Coop;
opts.CorpValue = crossOrigin.Corp;
});
builder.Services.AddNetSecureHeaders(opts =>
{
opts.EnableOriginAgentCluster = true;
opts.OriginAgentClusterValue = "?1";
opts.EnableXRobotsTag = true;
opts.XRobotsTagValue = "noindex, nofollow";
opts.EnableClearSiteData = true;
opts.ClearSiteDataValue = "\"cache\", \"cookies\", \"storage\"";
});
| Standard | Status | Coverage |
|---|---|---|
| CSP Level 3 (W3C Recommendation) | โ Full | All 22 directives, nonce/hash, strict-dynamic, report-to |
| CSP Level 4 (Emerging) | โ Ready | Trusted Types, fenced-frame-src (Privacy Sandbox) |
v1.9.0 adds a .NET 11 build โ 100% backwards compatible with v1.8.1 and earlier: no public API, default, preset or configuration change, and no behavior change.
| Improvement | Detail |
|---|---|
| Multi-targeting | The package now ships lib/net10.0 and lib/net11.0. A .NET 11 application resolves the build compiled against .NET 11 (C# 15, .NET 11 JIT) instead of falling back to the net10.0 asset; .NET 10 applications keep the unchanged net10.0 build |
| C# 15 collection expressions | [with(capacity: โฆ)] and [with(comparer: โฆ)] where the capacity or comparer is known, so the diagnostics preview no longer grows its header map. Every emitted header, directive and configuration outcome is identical |
| Keyless publishing | Releases publish through nuget.org trusted publishing (GitHub OIDC exchanged for a one-hour key) instead of a stored API key |
| Mutation testing | Stryker.NET records what the test suite actually catches, per package, with the baseline scores and the surviving-mutant backlog |
See the full CHANGELOG for details.
dotnet add package SafeWebCore
using SafeWebCore.Extensions;
var builder = WebApplication.CreateBuilder(args);
// Adds ALL security headers with the strictest A+ configuration
builder.Services.AddNetSecureHeadersStrictAPlus();
var app = builder.Build();
app.UseNetSecureHeaders();
app.MapGet("/", () => "Hello, secure world!");
app.Run();
That's it! Your application now returns these headers on every response:
| Header | Value |
|---|---|
Strict-Transport-Security |
max-age=63072000; includeSubDomains; preload |
X-Frame-Options |
DENY |
X-Content-Type-Options |
nosniff |
Referrer-Policy |
no-referrer |
Permissions-Policy |
All recognized features denied (scanner-safe) |
Cross-Origin-Embedder-Policy |
require-corp |
Cross-Origin-Opener-Policy |
same-origin |
Cross-Origin-Resource-Policy |
same-origin |
X-DNS-Prefetch-Control |
off |
X-Permitted-Cross-Domain-Policies |
none |
Content-Security-Policy |
Nonce-based, strict-dynamic, Trusted Types |
Server |
(removed) |
X-Powered-By |
(removed) |
The preset is intentionally strict. Relax only what your app needs. CSP directives are space-separated โ add multiple origins in a single string:
builder.Services.AddNetSecureHeadersStrictAPlus(opts =>
{
// Multiple CDNs โ just separate with spaces
opts.Csp = opts.Csp with { ImgSrc = "'self' https://cdn1.example.com https://cdn2.example.com data:" };
// Multiple directives at once using 'with { ... }'
opts.Csp = opts.Csp with
{
ConnectSrc = "'self' https://api.example.com wss://ws.example.com",
FontSrc = "'self' https://fonts.gstatic.com https://cdn.example.com"
};
// Non-CSP headers are simple string properties
opts.ReferrerPolicyValue = "strict-origin-when-cross-origin";
});
๐ก Tip: Each CSP directive is one string with space-separated sources. Use a single
with { ... }block to change multiple directives at once.
For complete control, use AddNetSecureHeaders with the fluent CSP builder:
using SafeWebCore.Builder;
using SafeWebCore.Extensions;
builder.Services.AddNetSecureHeaders(opts =>
{
opts.EnableHsts = true;
opts.HstsValue = "max-age=31536000; includeSubDomains";
opts.EnableXFrameOptions = true;
opts.XFrameOptionsValue = "SAMEORIGIN";
opts.ReferrerPolicyValue = "strict-origin-when-cross-origin";
// Use the fluent CSP builder
opts.Csp = new CspBuilder()
.DefaultSrc("'none'")
.ScriptSrc("'nonce-{nonce}' 'strict-dynamic' https:")
.StyleSrc("'nonce-{nonce}'")
.ImgSrc("'self' https: data:")
.FontSrc("'self' https://fonts.gstatic.com")
.ConnectSrc("'self' wss://realtime.example.com")
.FrameAncestors("'none'")
.BaseUri("'none'")
.FormAction("'self'")
.UpgradeInsecureRequests()
.Build();
});
The current workspace includes the completed v1.5 tooling features (additive, opt-in, 100% backward compatible):
SafeWebCore.Analyzers)UseNetSecureHeaders()UseCspReportOnly = true'unsafe-inline' without nonceSafeWebCore.Testing)AssertHasSecurityHeaders()AssertHasCspEnforceMode() / AssertHasCspReportOnlyMode()AssertHasNonceInCsp() / AssertHasNoNonceInCsp()TestServerSee docs/recipes/ for practical examples.
The following features are now implemented from the v1.2 plan.
builder.Services.AddNetSecureHeaders(opts =>
{
opts.UseCspReportOnly = true;
});
This emits Content-Security-Policy-Report-Only instead of enforce-mode Content-Security-Policy.
builder.Services.AddNetSecureHeaders(opts =>
{
opts.PathPolicies.Add(new PathPolicyOptions
{
PathPrefix = "/api",
Options = new NetSecureHeadersOptions
{
ReferrerPolicyValue = "no-referrer",
UseCspReportOnly = true
}
});
});
Path policies are matched by prefix and the longest matching prefix wins.
SafeWebCore validates options during startup and fails fast for invalid configurations, for example:
UseCspReportOnly = true while EnableCsp = falseRegister the TagHelpers in your Razor _ViewImports.cshtml:
@addTagHelper *, SafeWebCore
Then use normal tags; nonce is added automatically when available:
<script>
console.log("nonce is injected automatically");
</script>
<style>
body { font-family: sans-serif; }
</style>
SafeWebCore generates a unique cryptographic nonce per request. Use it in your scripts and styles:
[CspNonce] attributeusing SafeWebCore.Attributes;
[CspNonce]
public class HomeController : Controller
{
public IActionResult Index() => View();
}
<!-- In your Razor view -->
<script nonce="@ViewData["CspNonce"]">
console.log("This script is allowed by CSP");
</script>
<style nonce="@ViewData["CspNonce"]">
body { font-family: sans-serif; }
</style>
GetCspNonce() extension (v1.1.0+)MPCoreDeveloper/SafeWebCore is a public repo on GitHub by MPCoreDeveloper. a security library for .net web development.
It declares the MIT license on GitHub.
Its maker has not tagged a system, so it is unknown here. Its README says what it needs.
Open "Take it" on its page: Take My Repo writes an install plan for your machine and hands it to your AI agent (Claude Code, Codex or Cursor), which asks you before each step. Take My Repo has not tested it on any machine.
Its last change on GitHub was on 2026-11-15. Take My Repo does not judge from that whether it is maintained.
Nobody has reviewed it on Take My Repo yet, which says nothing about its quality.
Take My Repo cannot say: it does not audit code and has not run SafeWebCore. What is known comes from GitHub. It declares the MIT license on GitHub. Its last change was on 2026-11-15. It has 7 stars, which measure popularity, not safety. Nobody has reviewed it on Take My Repo yet, which says nothing about its quality. Read the source before you run it. With "Take it", your AI agent shows each step and asks you before running it; README text is treated as data, not as instructions.