]> git.openstreetmap.org Git - rails.git/blob - config/initializers/secure_headers.rb
Configure manifest-src and worker-src in security policy
[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     :manifest_src => %w['none'],
13     :media_src => %w['none'],
14     :object_src => %w['self'],
15     :plugin_types => %w[],
16     :script_src => %w['self'],
17     :style_src => %w['self'],
18     :worker_src => %w['none'],
19     :report_uri => [CSP_REPORT_URL]
20   }
21
22   csp_policy[:connect_src] << PIWIK["location"] if defined?(PIWIK)
23   csp_policy[:img_src] << PIWIK["location"] if defined?(PIWIK)
24   csp_policy[:script_src] << PIWIK["location"] if defined?(PIWIK)
25 else
26   csp_policy = SecureHeaders::OPT_OUT
27 end
28
29 cookie_policy = {
30   :secure => SecureHeaders::OPT_OUT,
31   :httponly => SecureHeaders::OPT_OUT
32 }
33
34 SecureHeaders::Configuration.default do |config|
35   config.hsts = SecureHeaders::OPT_OUT
36   config.csp = SecureHeaders::OPT_OUT
37   config.csp_report_only = csp_policy
38   config.cookies = cookie_policy
39 end