From 8582b08a987802efea606aa7963b14bff711e685 Mon Sep 17 00:00:00 2001 From: clemkeirua Date: Fri, 3 May 2019 15:25:51 +0200 Subject: [PATCH 01/24] add security policy --- config/environments/development.rb | 3 +++ config/environments/production.rb | 2 ++ .../initializers/content_security_policy.rb | 21 +++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 config/initializers/content_security_policy.rb diff --git a/config/environments/development.rb b/config/environments/development.rb index 9a178ab8c..1d51b0cd3 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -59,6 +59,9 @@ Rails.application.configure do port: 3000 } + # Use Content-Security-Policy-Report-Only instead of Content-Security-Policy + config.content_security_policy_report_only = true + # Raises error for missing translations # config.action_view.raise_on_missing_translations = true diff --git a/config/environments/production.rb b/config/environments/production.rb index f2474f93d..befbe17aa 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -109,5 +109,7 @@ Rails.application.configure do host: ENV['APP_HOST'] } + config.content_security_policy_report_only = true + config.lograge.enabled = ENV['LOGRAGE_ENABLED'] == 'enabled' end diff --git a/config/initializers/content_security_policy.rb b/config/initializers/content_security_policy.rb new file mode 100644 index 000000000..9db6e18cf --- /dev/null +++ b/config/initializers/content_security_policy.rb @@ -0,0 +1,21 @@ +Rails.application.config.content_security_policy do |policy| + # En cas de non respect d'une des règles, faire un POST sur cette URL + policy.report_uri "/csp-violation-report-endpoint" + # Nos whitelist + policy.img_src :self, "https://*.openstreetmap.org" + # sendinblue et matomo, et… miniprofiler :( + # https://github.com/MiniProfiler/rack-mini-profiler/issues/327 + if Rails.env.development? + #policy.script_src :self, "https://sibautomation.com", "//stats.data.gouv.fr", :unsafe_eval, :unsafe_inline + policy.script_src :self, "https://sibautomation.com", "//stats.data.gouv.fr", :unsafe_eval + else + policy.script_src :self, "https://sibautomation.com", "//stats.data.gouv.fr" + end + # Pour les CSS, on a beaucoup de style inline et quelques balises