feat: Implementierung von CSPMiddleware zur Hinzufügung von CSP-Headern mit Nonce für verbesserte Sicherheit.

This commit is contained in:
Developer 02
2024-05-14 11:19:22 +02:00
parent f7a5d4fc28
commit b71c778a4d
3 changed files with 74 additions and 1 deletions

View File

@@ -0,0 +1,23 @@
using Microsoft.AspNetCore.Builder;
namespace DigitalData.Core.API
{
/// <summary>
/// Provides extension methods for adding middleware to the application's request pipeline.
/// </summary>
public static class DIExtensions
{
/// <summary>
/// Adds the <see cref="CSPMiddleware"/> to the application's request pipeline to include
/// Content Security Policy (CSP) headers in the HTTP response.
/// </summary>
/// <param name="app">The application builder.</param>
/// <param name="policy">
/// The CSP policy string with placeholders. The first format parameter {0} will be replaced
/// by the nonce value.
/// </param>
/// <returns>The application builder with the CSP middleware added.</returns>
public static IApplicationBuilder UseCSPMiddleware(this IApplicationBuilder app, string policy)
=> app.UseMiddleware<CSPMiddleware>(policy);
}
}