Umbraco.Community.CSPManager
2.0.2-alpha
dotnet add package Umbraco.Community.CSPManager --version 2.0.2-alpha
NuGet\Install-Package Umbraco.Community.CSPManager -Version 2.0.2-alpha
<PackageReference Include="Umbraco.Community.CSPManager" Version="2.0.2-alpha" />
<PackageVersion Include="Umbraco.Community.CSPManager" Version="2.0.2-alpha" />
<PackageReference Include="Umbraco.Community.CSPManager" />
paket add Umbraco.Community.CSPManager --version 2.0.2-alpha
#r "nuget: Umbraco.Community.CSPManager, 2.0.2-alpha"
#:package Umbraco.Community.CSPManager@2.0.2-alpha
#addin nuget:?package=Umbraco.Community.CSPManager&version=2.0.2-alpha&prerelease
#tool nuget:?package=Umbraco.Community.CSPManager&version=2.0.2-alpha&prerelease
Umbraco.Community.CSPManager
A comprehensive Content Security Policy (CSP) management package for Umbraco CMS that helps protect your website from XSS attacks and other code injection vulnerabilities. Manage CSP headers for both frontend and backend through an intuitive backoffice interface.
Features
- 🛡️ Frontend & Backend CSP Management - Configure different Content Security Policies for your website frontend and Umbraco backoffice
- 🎛️ Intuitive Backoffice Interface - Easy-to-use management screens within the Umbraco backoffice
- 🔍 CSP Evaluation Tools - Test and validate your Content Security Policies before deployment
- 🏷️ Nonce Support - Built-in tag helpers for script and style nonces
- ⚙️ Flexible Configuration - Customize CSP directives to match your website's requirements
- 📊 Real-time Testing - Evaluate CSP effectiveness with built-in testing tools
Table of Contents
- Requirements
- Installation
- Quick Start
- Policy Management
- Policy Settings
- Evaluation
- Configuration Options
- Nonce Tag Helper
- Advanced Usage
- Troubleshooting
- Contributing
Getting Started
dotnet add package Umbraco.Community.CSPManager
Quick Start
- Install the package using the command above
- Build and run your Umbraco application
- Navigate to the CSP Management section in the Umbraco backoffice
- Configure your Content Security Policies for frontend and/or backend
- Test your configuration using the evaluation tools
Policy Management
Policy Settings
Evaluation
Configuration Options
You can configure CSP Manager behavior in your appsettings.json
:
{
"CspManager": {
"DisableBackOfficeHeader": false
}
}
DisableBackOfficeHeader - Emergency kill switch to disable CSP headers for the backoffice if needed (default: false
)
Nonce Tag Helper
To use CSP nonce you can make use of the Tag Helper. To find out more about nonce see see nonce Guide.
First you will need to include the namespace in the ViewImports.cshtml
@addTagHelper *, Umbraco.Community.CSPManager
To use the nonce add csp-manager-add-nonce="true"
to your <script>
or <style>
tags.
The nonce values shown are for demo purposes only.
<script csp-manager-add-nonce="true"></script>
<style csp-manager-add-nonce="true"></style>
<script nonce="scriptRAnd0m">
doWhatever();
</script>
<style nonce="styleRAnd0m">
.alert { color: red; }
</style>
When this is added it will include the nonce in the CSP header and output in the page.
If you need to access the nonce within a data attribute you can use csp-manager-add-nonce-data-attribute="true"
<script csp-manager-add-nonce-data-attribute="true"></script>
<style csp-manager-add-nonce-data-attribute="true"></style>
<script data-nonce="scriptRAnd0m">
doWhatever();
</script>
<style data-nonce="styleRAnd0m">
.alert { color: red; }
</style>
Advanced Usage
Notification Events
The CSP Manager provides notification events that allow you to extend functionality and integrate with your application logic.
CspWritingNotification
Triggered when building a CSP definition for an HTTP request. Use this to dynamically modify Content Security Policies based on request context.
using Umbraco.Cms.Core.Events;
using Umbraco.Community.CSPManager.Notifications;
public class CustomCspWritingHandler : INotificationHandler<CspWritingNotification>
{
public void Handle(CspWritingNotification notification)
{
// Modify CSP definition based on request context
if (notification.HttpContext.Request.Path.StartsWithSegments("/api"))
{
// Apply different CSP for API endpoints
notification.CspDefinition?.Directives.Add("connect-src", "'self' api.example.com");
}
}
}
CspSavedNotification
Triggered when a CSP definition is saved through the backoffice. Use this for cache invalidation, logging, or integration with external systems.
public class CustomCspSavedHandler : INotificationHandler<CspSavedNotification>
{
public void Handle(CspSavedNotification notification)
{
// Log CSP changes
var csp = notification.CspDefinition;
Logger.Information("CSP policy updated for {Area}",
csp.IsBackOffice ? "BackOffice" : "Frontend");
// Integrate with external monitoring
// NotifySecurityTeam(csp);
}
}
Registering Notification Handlers
Register your custom handlers in your Startup.cs
or Program.cs
:
services.AddNotificationHandler<CspWritingNotification, CustomCspWritingHandler>();
services.AddNotificationHandler<CspSavedNotification, CustomCspSavedHandler>();
Getting Help
If you encounter issues not covered here:
- Check the GitHub Issues page
- Review the full documentation (link below)
- Create a new issue with detailed information about your problem
Contributing
Contributions are welcome! Please read our Contributing Guidelines and feel free to submit issues and pull requests.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. 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. |
-
net9.0
- Umbraco.Cms.Api.Management (>= 16.0.0)
- Umbraco.Cms.Web.Website (>= 16.0.0)
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 |
---|---|---|
2.0.2-alpha | 160 | 8/19/2025 |
1.4.2 | 6,165 | 3/17/2025 |
1.4.1 | 12,141 | 9/8/2024 |
1.4.0 | 265 | 8/23/2024 |
1.3.1-beta | 335 | 5/2/2024 |
1.3.0-beta | 202 | 4/5/2024 |
1.2.1 | 9,628 | 3/26/2024 |
1.2.0 | 7,515 | 10/26/2023 |
1.1.0-alpha | 2,532 | 3/7/2023 |
1.0.1-alpha | 352 | 1/11/2023 |
1.0.0-alpha | 222 | 1/6/2023 |