Merge pull request #3838 from Keirua/feat/content-security-policy

Add Content Security Policy test headers
This commit is contained in:
Keirua 2019-05-06 10:23:44 +02:00 committed by GitHub
commit 748adfd3d5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 32 additions and 1 deletions

View file

@ -19,7 +19,7 @@
= stylesheet_link_tag 'new_design/new_application', media: 'all', 'data-turbolinks-track': 'reload'
= stylesheet_link_tag 'new_design/print', media: 'print', 'data-turbolinks-track': 'reload'
= Gon::Base.render_data(camel_case: true, init: true)
= Gon::Base.render_data(camel_case: true, init: true, nonce: request.content_security_policy_nonce)
- if Rails.env.development?
= stylesheet_link_tag :xray

View file

@ -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

View file

@ -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

View file

@ -45,6 +45,9 @@ Rails.application.configure do
protocol: :http
}
# Use Content-Security-Policy-Report-Only instead of Content-Security-Policy
config.content_security_policy_report_only = true
config.active_job.queue_adapter = :test
config.active_storage.service = :test

View file

@ -0,0 +1,23 @@
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 "https://e30e0ed9c14194254481124271b34a72.report-uri.com/r/d/csp/reportOnly"
# Whitelist image
policy.img_src :self, "https://*.openstreetmap.org"
# Whitelist JS: nous, sendinblue et matomo, et… miniprofiler :(
if Rails.env.development?
# https://github.com/MiniProfiler/rack-mini-profiler/issues/327
policy.script_src :self, "https://sibautomation.com", "//stats.data.gouv.fr", :unsafe_eval, :unsafe_inline
else
policy.script_src :self, "https://sibautomation.com", "//stats.data.gouv.fr"
end
# Génération d'un nonce pour les balises script inline qu'on maitrise (Gon)
Rails.application.config.content_security_policy_nonce_generator = -> _request { SecureRandom.base64(16) }
# Pour les CSS, on a beaucoup de style inline et quelques balises <style>
# c'est trop compliqué pour être rectifié immédiatement (et sans valeur ajoutée:
# c'est hardcodé dans les vues, donc pas injectable).
policy.style_src :self, :unsafe_inline
# Pour tout le reste, par défaut on accepte uniquement ce qui vient de chez nous
# et dans la notification on inclue la source de l'erreur
policy.default_src :self, :data, :report_sample
end