Umbraco.Community.CSPManager 2.0.2-alpha

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

Umbraco.Community.CSPManager

Platform Downloads NuGet GitHub license Build

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

Getting Started

dotnet add package Umbraco.Community.CSPManager

Quick Start

  1. Install the package using the command above
  2. Build and run your Umbraco application
  3. Navigate to the CSP Management section in the Umbraco backoffice
  4. Configure your Content Security Policies for frontend and/or backend
  5. Test your configuration using the evaluation tools

Policy Management

Policy section

Policy Settings

Policy Settings section

Evaluation

CSP Evaluation section

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:

  1. Check the GitHub Issues page
  2. Review the full documentation (link below)
  3. 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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