]> git.openstreetmap.org Git - rails.git/blob - config/initializers/secure_headers.rb
Merge remote-tracking branch 'upstream/pull/1950'
[rails.git] / config / initializers / secure_headers.rb
1 csp_policy = {
2   :preserve_schemes => true,
3   :default_src => %w['self'],
4   :child_src => %w['self'],
5   :connect_src => %w['self'],
6   :font_src => %w['none'],
7   :form_action => %w['self'],
8   :frame_ancestors => %w['self'],
9   :frame_src => %w['self'],
10   :img_src => %w['self' data: www.gravatar.com *.wp.com *.tile.openstreetmap.org *.tile.thunderforest.com *.openstreetmap.fr],
11   :manifest_src => %w['none'],
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   :worker_src => %w['none'],
18   :report_uri => []
19 }
20
21 csp_policy[:connect_src] << PIWIK["location"] if defined?(PIWIK)
22 csp_policy[:img_src] << PIWIK["location"] if defined?(PIWIK)
23 csp_policy[:script_src] << PIWIK["location"] if defined?(PIWIK)
24 csp_policy[:report_uri] << CSP_REPORT_URL if defined?(CSP_REPORT_URL)
25
26 cookie_policy = {
27   :secure => SecureHeaders::OPT_OUT,
28   :httponly => SecureHeaders::OPT_OUT
29 }
30
31 SecureHeaders::Configuration.default do |config|
32   config.hsts = SecureHeaders::OPT_OUT
33
34   if CSP_ENFORCE
35     config.csp = csp_policy
36     config.csp_report_only = SecureHeaders::OPT_OUT
37   elsif defined?(CSP_REPORT_URL)
38     config.csp = SecureHeaders::OPT_OUT
39     config.csp_report_only = csp_policy
40   else
41     config.csp = SecureHeaders::OPT_OUT
42     config.csp_report_only = SecureHeaders::OPT_OUT
43   end
44
45   config.cookies = cookie_policy
46 end