handle Gon + add report-uri URL
This commit is contained in:
parent
8582b08a98
commit
64b858ef19
2 changed files with 14 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -1,21 +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 "/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
|
||||
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?
|
||||
#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
|
||||
# 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"
|
||||
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 hardocodé dans les vues, donc pas injectable).
|
||||
policy.style_src :self, :unsafe_inline
|
||||
# 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
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue