From fc4e47cec608cc3dba24b19d0145ac69320b975e Mon Sep 17 00:00:00 2001 From: Nicolas Dorier Date: Thu, 9 Sep 2021 21:51:28 +0900 Subject: [PATCH] Add CSP at the website level (#2863) --- BTCPayServer.Tests/BTCPayServerTester.cs | 4 +- BTCPayServer.Tests/SeleniumTester.cs | 1 + .../NotificationsDropdown/Default.cshtml | 2 +- .../Configuration/DefaultConfiguration.cs | 1 + .../Filters/ContentSecurityPolicyAttribute.cs | 141 ++++++++++-------- BTCPayServer/Hosting/Startup.cs | 10 +- .../Security/ContentSecurityPolicies.cs | 21 +-- BTCPayServer/TagHelpers.cs | 128 ++++++++++++++++ BTCPayServer/Views/Invoice/PosData.cshtml | 6 +- 9 files changed, 224 insertions(+), 90 deletions(-) create mode 100644 BTCPayServer/TagHelpers.cs diff --git a/BTCPayServer.Tests/BTCPayServerTester.cs b/BTCPayServer.Tests/BTCPayServerTester.cs index 949ac53d34..d6d7e51ff1 100644 --- a/BTCPayServer.Tests/BTCPayServerTester.cs +++ b/BTCPayServer.Tests/BTCPayServerTester.cs @@ -134,7 +134,7 @@ public async Task StartAsync() config.AppendLine($"torrcfile={TestUtils.GetTestDataFullPath("Tor/torrc")}"); config.AppendLine($"socksendpoint={SocksEndpoint}"); config.AppendLine($"debuglog=debug.log"); - + config.AppendLine($"nocsp={NoCSP.ToString().ToLowerInvariant()}"); if (!string.IsNullOrEmpty(SSHPassword) && string.IsNullOrEmpty(SSHKeyFile)) config.AppendLine($"sshpassword={SSHPassword}"); @@ -283,6 +283,8 @@ public T GetService() public string SSHPassword { get; internal set; } public string SSHKeyFile { get; internal set; } public string SSHConnection { get; set; } + public bool NoCSP { get; set; } + public T GetController(string userId = null, string storeId = null, bool isAdmin = false) where T : Controller { var context = new DefaultHttpContext(); diff --git a/BTCPayServer.Tests/SeleniumTester.cs b/BTCPayServer.Tests/SeleniumTester.cs index 868671fff6..0b3e98d70f 100644 --- a/BTCPayServer.Tests/SeleniumTester.cs +++ b/BTCPayServer.Tests/SeleniumTester.cs @@ -38,6 +38,7 @@ public class SeleniumTester : IDisposable public async Task StartAsync() { + Server.PayTester.NoCSP = true; await Server.StartAsync(); var windowSize = (Width: 1200, Height: 1000); diff --git a/BTCPayServer/Components/NotificationsDropdown/Default.cshtml b/BTCPayServer/Components/NotificationsDropdown/Default.cshtml index a2fef15099..6dcf907f79 100644 --- a/BTCPayServer/Components/NotificationsDropdown/Default.cshtml +++ b/BTCPayServer/Components/NotificationsDropdown/Default.cshtml @@ -67,7 +67,7 @@ else @if (!disabled) { -