add security policy
This commit is contained in:
parent
58c71ddee6
commit
8582b08a98
3 changed files with 26 additions and 0 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
21
config/initializers/content_security_policy.rb
Normal file
21
config/initializers/content_security_policy.rb
Normal file
|
@ -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 <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
|
||||
# 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
|
Loading…
Reference in a new issue