]> git.openstreetmap.org Git - rails.git/blob - config/initializers/secure_headers.rb
ba9aa496f4468601293db2a7bd13abed81e404a5
[rails.git] / config / initializers / secure_headers.rb
1 if defined?(CSP_REPORT_URL)
2   csp_policy = {
3     :preserve_schemes => true,
4     :default_src => %w['self'],
5     :child_src => %w['self'],
6     :connect_src => %w['self'],
7     :font_src => %w['none'],
8     :form_action => %w['self'],
9     :frame_ancestors => %w['self'],
10     :frame_src => %w['self'],
11     :img_src => %w['self' data: www.gravatar.com *.wp.com *.tile.openstreetmap.org *.tile.thunderforest.com *.openstreetmap.fr],
12     :media_src => %w['none'],
13     :object_src => %w['self'],
14     :plugin_types => %w[],
15     :script_src => %w['self'],
16     :style_src => %w['self'],
17     :report_uri => [CSP_REPORT_URL]
18   }
19
20   csp_policy[:connect_src] << PIWIK["location"] if defined?(PIWIK)
21   csp_policy[:img_src] << PIWIK["location"] if defined?(PIWIK)
22   csp_policy[:script_src] << PIWIK["location"] if defined?(PIWIK)
23 else
24   csp_policy = SecureHeaders::OPT_OUT
25 end
26
27 cookie_policy = {
28   :secure => SecureHeaders::OPT_OUT,
29   :httponly => SecureHeaders::OPT_OUT
30 }
31
32 SecureHeaders::Configuration.default do |config|
33   config.hsts = SecureHeaders::OPT_OUT
34   config.csp = SecureHeaders::OPT_OUT
35   config.csp_report_only = csp_policy
36   config.cookies = cookie_policy
37 end