diff --git a/app/controllers/blazer/base_controller.rb b/app/controllers/blazer/base_controller.rb index 9d7253aae..925ddeee0 100644 --- a/app/controllers/blazer/base_controller.rb +++ b/app/controllers/blazer/base_controller.rb @@ -23,9 +23,7 @@ class BaseController < ApplicationController end if Blazer.override_csp - after_action do - response.headers['Content-Security-Policy'] = "default-src 'self' https: 'unsafe-inline' 'unsafe-eval' data: blob:" - end + after_action :override_csp end layout "blazer/application" @@ -129,5 +127,22 @@ def render_errors(resource) def default_url_options {} end + + def override_csp + script_nonce = content_security_policy_nonce || raise(Blazer::Error, "couldn't find nonce for script-src") + + response.headers['Content-Security-Policy'] = <<~CSP.squish + default-src 'self'; + base-uri 'none'; + img-src 'self' #{Rails.configuration.asset_host} data: blob:; + script-src 'self' 'nonce-#{script_nonce}' 'strict-dynamic' 'unsafe-eval' https: 'report-sample'; + style-src 'self' #{Rails.configuration.asset_host} 'unsafe-inline' 'report-sample'; + object-src 'none'; + connect-src 'self' #{"https://*.tiles.mapbox.com https://api.mapbox.com https://events.mapbox.com" if Blazer.maps?}; + child-src blob:; + worker-src blob: ; + form-action 'self'; + CSP + end end end diff --git a/app/views/blazer/_variables.html.erb b/app/views/blazer/_variables.html.erb index a2bc8df1f..349f43115 100644 --- a/app/views/blazer/_variables.html.erb +++ b/app/views/blazer/_variables.html.erb @@ -1,6 +1,6 @@ <% if @bind_vars.any? %> <% var_params = request.query_parameters %> - @@ -38,7 +38,7 @@
<%= f.select :invert, [["Any results (bad data)", false], ["No results (missing data)", true]] %>
- @@ -50,7 +50,7 @@
<%= f.select :schedule, Blazer.check_schedules.map { |v| [v, v] } %>
- diff --git a/app/views/blazer/checks/index.html.erb b/app/views/blazer/checks/index.html.erb index 5ce7296b8..de2ef08fc 100644 --- a/app/views/blazer/checks/index.html.erb +++ b/app/views/blazer/checks/index.html.erb @@ -62,7 +62,7 @@ - + <% end %> <%= csrf_meta_tags %>