govuk_app_config 1.17.0 → 1.18.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fe5e846bb45a6b28512d6dc2dd01794106ebe653d739855b564491290b8a6e31
4
- data.tar.gz: '05335490c4278b67b1ab0404712b91cd9fc4be44f08887cad5453313e0cfb502'
3
+ metadata.gz: a50c0d77a0aae41136b1099a036a761c3e1a965ecb0184879f8f722d40786108
4
+ data.tar.gz: 87d38200558b9f2b945910ee6447cb150d53e83ad06005e0fa5c439ef70eb79d
5
5
  SHA512:
6
- metadata.gz: aba550d1c915e3f2ede8424ac30f1c5ea35de88c4c68a744075a6cc19c65ffdda3ffdd7ae7bcebc178f9fb5bedba291ec4d585f09a0cff764baf2efe0587bf52
7
- data.tar.gz: 54cbb007d3e933986a5d0af504d0c57042267d22375e7784c043a3022b10a7935bb7b550be181ded92a0769680861344077656bef6886857aa50e13293341fa6
6
+ metadata.gz: af87829f8bf53a26b7df8b612e3a113c5d14ac0b3f09609bb62751c8376b20c81b37958702f43a9829d5c20ccaaf784c2b0e09ad9a5da034e323e2db228af7b2
7
+ data.tar.gz: 7786abef8b8319af18b79779e98f721c3526947d804534ef6f78c4b47b14e380997052de3f3fa10e8d4d4f661855fce1fa466894b7d8eab447ea54d12f75ad82
@@ -1,3 +1,12 @@
1
+ # 1.18.1
2
+
3
+ * Fix incorrect report_uri= method usage in content security policy
4
+
5
+ # 1.18.0
6
+
7
+ * Use Rails DSL to configure content security policy, allowing apps to modify
8
+ the policy and use nonce features.
9
+
1
10
  # 1.17.0
2
11
 
3
12
  * Tweak our CSP to work with 'dev.gov.uk'
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_dependency "unicorn", "~> 5.4.0"
29
29
 
30
30
  spec.add_development_dependency "bundler", "~> 1.15"
31
+ spec.add_development_dependency "rails", "~> 5"
31
32
  spec.add_development_dependency "rake", "~> 10.0"
32
33
  spec.add_development_dependency "rspec", "~> 3.6.0"
33
34
  spec.add_development_dependency "rspec-its", "~> 1.2.0"
@@ -1,5 +1,4 @@
1
1
  require "govuk_app_config/version"
2
- require "govuk_app_config/govuk_content_security_policy"
3
2
  require "govuk_app_config/govuk_statsd"
4
3
  require "govuk_app_config/govuk_error"
5
4
  require "govuk_app_config/govuk_logging"
@@ -9,4 +8,8 @@ require "govuk_app_config/govuk_healthcheck"
9
8
  require "govuk_app_config/govuk_unicorn"
10
9
  require "govuk_app_config/govuk_xray"
11
10
  require "govuk_app_config/configure"
12
- require "govuk_app_config/railtie" if defined?(Rails)
11
+
12
+ if defined?(Rails)
13
+ require "govuk_app_config/railtie"
14
+ require "govuk_app_config/govuk_content_security_policy"
15
+ end
@@ -1,9 +1,6 @@
1
1
  module GovukContentSecurityPolicy
2
2
  # Generate a Content Security Policy (CSP) directive.
3
3
  #
4
- #
5
- # Extracted in a separate module to allow comments.
6
- #
7
4
  # See https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP for more CSP info.
8
5
  #
9
6
  # The resulting policy should be checked with:
@@ -12,131 +9,75 @@ module GovukContentSecurityPolicy
12
9
  # - https://cspvalidator.org
13
10
 
14
11
  GOVUK_DOMAINS = [
15
- "'self'",
16
12
  '*.publishing.service.gov.uk',
17
13
  "*.#{ENV['GOVUK_APP_DOMAIN_EXTERNAL'] || ENV['GOVUK_APP_DOMAIN'] || 'dev.gov.uk'}"
18
- ].uniq.join(" ").freeze
19
-
20
- GOOGLE_ANALYTICS_DOMAINS = "www.google-analytics.com ssl.google-analytics.com stats.g.doubleclick.net".freeze
14
+ ].uniq.freeze
21
15
 
22
- def self.build
23
- policies = []
16
+ GOOGLE_ANALYTICS_DOMAINS = %w(www.google-analytics.com
17
+ ssl.google-analytics.com
18
+ stats.g.doubleclick.net).freeze
24
19
 
25
- # By default, only allow HTTPS connections, and allow loading things from
26
- # the publishing domain
27
- #
20
+ def self.build_policy(policy)
28
21
  # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/default-src
29
- policies << [
30
- "default-src https",
31
- GOVUK_DOMAINS
32
- ]
22
+ policy.default_src :https, :self, *GOVUK_DOMAINS
33
23
 
34
- # Allow images from the current domain, Google Analytics (the tracking pixel),
35
- # and publishing domains.
36
24
  # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/img-src
37
- policies << [
38
- "img-src",
39
-
40
- # Allow `data:` images for Base64-encoded images in CSS like:
41
- #
42
- # https://github.com/alphagov/service-manual-frontend/blob/1db99ed48de0dfc794b9686a98e6c62f8435ae80/app/assets/stylesheets/modules/_search.scss#L106
43
- "data:",
44
-
45
- GOVUK_DOMAINS,
46
- GOOGLE_ANALYTICS_DOMAINS,
25
+ policy.img_src :self,
26
+ :data, # Base64 encoded images
27
+ *GOVUK_DOMAINS,
28
+ *GOOGLE_ANALYTICS_DOMAINS, # Tracking pixels
29
+ # Some content still links to an old domain we used to use
30
+ "assets.digital.cabinet-office.gov.uk"
47
31
 
48
- # Some content still links to an old domain we used to use
49
- "assets.digital.cabinet-office.gov.uk",
50
- ]
51
-
52
- # script-src determines the scripts that the browser can load
53
- #
54
32
  # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src
55
- policies << [
56
- # Allow scripts from publishing domains
57
- "script-src",
58
- GOVUK_DOMAINS,
59
- GOOGLE_ANALYTICS_DOMAINS,
60
-
61
- # Allow JSONP call to Verify to check whether the user is logged in
62
- # https://www.staging.publishing.service.gov.uk/log-in-file-self-assessment-tax-return/sign-in/prove-identity
63
- # https://github.com/alphagov/government-frontend/blob/71aca4df9b74366618a5a93acdb5cd2715f94f49/app/assets/javascripts/modules/track-radio-group.js
64
- "www.signin.service.gov.uk",
65
-
66
- # Allow YouTube Embeds (Govspeak turns YouTube links into embeds)
67
- "*.ytimg.com",
68
- "www.youtube.com",
69
-
70
- # Allow all inline scripts until we can conclusively document all the inline scripts we use,
71
- # and there's a better way to filter out junk reports
72
- "'unsafe-inline'"
73
- ]
33
+ policy.script_src :self,
34
+ *GOVUK_DOMAINS,
35
+ *GOOGLE_ANALYTICS_DOMAINS,
36
+ # Allow JSONP call to Verify to check whether the user is logged in
37
+ "www.signin.service.gov.uk",
38
+ # Allow YouTube Embeds (Govspeak turns YouTube links into embeds)
39
+ "*.ytimg.com",
40
+ "www.youtube.com",
41
+ # Allow all inline scripts until we can conclusively
42
+ # document all the inline scripts we use,
43
+ # and there's a better way to filter out junk reports
44
+ :unsafe_inline
74
45
 
75
- # Allow styles from own domain and publishing domains.
76
- #
77
46
  # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/style-src
78
- policies << [
79
- "style-src",
80
- GOVUK_DOMAINS,
81
-
82
- # Also allow "unsafe-inline" styles, because we use the `style=""` attribute on some HTML elements
83
- "'unsafe-inline'"
84
- ]
47
+ policy.style_src :self,
48
+ *GOVUK_DOMAINS,
49
+ # We use the `style=""` attribute on some HTML elements
50
+ :unsafe_inline
85
51
 
86
- # Allow fonts to be loaded from data-uri's (this is the old way of doing things)
87
- # or from the publishing asset domains.
88
- #
89
- # https://www.staging.publishing.service.gov.uk/apply-for-a-licence/test-licence/westminster/apply-1
90
- #
91
52
  # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/font-src
92
- policies << [
93
- "font-src data:",
94
- GOVUK_DOMAINS
95
- ]
53
+ policy.font_src :self,
54
+ *GOVUK_DOMAINS,
55
+ :data # Used by some legacy fonts
96
56
 
97
57
  # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/connect-src
98
- policies << [
99
- # Scripts can only load data using Ajax from Google Analytics and the publishing domains
100
- "connect-src",
101
- GOVUK_DOMAINS,
102
- GOOGLE_ANALYTICS_DOMAINS,
103
-
104
- # Allow connecting to web chat from HMRC contact pages like
105
- # https://www.staging.publishing.service.gov.uk/government/organisations/hm-revenue-customs/contact/child-benefit
106
- "www.tax.service.gov.uk",
107
-
108
- # Allow connecting to Verify to check whether the user is logged in
109
- # https://github.com/alphagov/government-frontend/blob/71aca4df9b74366618a5a93acdb5cd2715f94f49/app/assets/javascripts/modules/track-radio-group.js
110
- # https://www.staging.publishing.service.gov.uk/log-in-file-self-assessment-tax-return/sign-in/prove-identity
111
- "www.signin.service.gov.uk",
112
- ]
58
+ policy.connect_src :self,
59
+ *GOVUK_DOMAINS,
60
+ *GOOGLE_ANALYTICS_DOMAINS,
61
+ # Allow connecting to web chat from HMRC contact pages
62
+ "www.tax.service.gov.uk",
63
+ # Allow connecting to Verify to check whether the user is logged in
64
+ "www.signin.service.gov.uk"
113
65
 
114
66
  # Disallow all <object>, <embed>, and <applet> elements
115
67
  #
116
68
  # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/object-src
117
- policies << [
118
- "object-src 'none'"
119
- ]
120
-
121
- policies << [
122
- "frame-src",
69
+ policy.object_src :none
123
70
 
124
- # Allow YouTube embeds
125
- "www.youtube.com",
126
- ]
71
+ # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-src
72
+ policy.frame_src :self, *GOVUK_DOMAINS, "www.youtube.com" # Allow youtube embeds
127
73
 
128
- policies.map { |str| str.join(" ") }.join("; ") + ";"
74
+ # AWS Lambda function that filters out junk reports.
75
+ policy.report_uri "https://jhpno0hk6b.execute-api.eu-west-2.amazonaws.com/production" if Rails.env.production?
129
76
  end
130
77
 
131
78
  def self.configure
132
- # In test and development, use CSP for real to find issues. In production we only
133
- # report violations to Sentry (https://sentry.io/govuk/govuk-frontend-csp) via an
134
- # AWS Lambda function that filters out junk reports.
135
- if Rails.env.production?
136
- reporting = "report-uri https://jhpno0hk6b.execute-api.eu-west-2.amazonaws.com/production"
137
- Rails.application.config.action_dispatch.default_headers['Content-Security-Policy-Report-Only'] = self.build + " " + reporting
138
- else
139
- Rails.application.config.action_dispatch.default_headers['Content-Security-Policy'] = self.build
140
- end
79
+ Rails.application.config.content_security_policy_report_only = true if Rails.env.production?
80
+
81
+ Rails.application.config.content_security_policy(&method(:build_policy))
141
82
  end
142
83
  end
@@ -1,3 +1,3 @@
1
1
  module GovukAppConfig
2
- VERSION = "1.17.0"
2
+ VERSION = "1.18.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: govuk_app_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.17.0
4
+ version: 1.18.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-05-29 00:00:00.000000000 Z
11
+ date: 2019-06-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-xray-sdk
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '1.15'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rails
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '5'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '5'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rake
99
113
  requirement: !ruby/object:Gem::Requirement