feat: Add CSP configuration to use CSPMiddleware and CSP nonce to script tags in several cshtml script

This commit is contained in:
Developer 02
2024-05-14 11:22:07 +02:00
parent 674d753735
commit 87a766a2e8
8 changed files with 26 additions and 23 deletions

View File

@@ -1,4 +1,7 @@
@using DigitalData.Core.DTO;
@{
var nonce = _accessor.HttpContext?.Items["csp-nonce"] as string;
}
@using DigitalData.Core.DTO;
@using Microsoft.AspNetCore.Http.Features
@using Newtonsoft.Json.Serialization;
@using Newtonsoft.Json;
@@ -10,7 +13,7 @@
}
@if (showBanner)
{
<script>
<script nonce="@nonce">
@{
var serializerSettings = new JsonSerializerSettings
{
@@ -18,7 +21,7 @@
};
string serializedProps = JsonConvert.SerializeObject(_cookieSettings, serializerSettings);
}
var props = @Html.Raw(serializedProps);
var cookieSettings = new BootstrapCookieConsentSettings(props)
</script>
var props = @Html.Raw(serializedProps);
var cookieSettings = new BootstrapCookieConsentSettings(props)
</script>
}

View File

@@ -29,4 +29,4 @@
</main>
@Html.AntiForgeryToken()
</body>
</html>
</html>