govuk_app_config 4.12.0 → 5.0.0

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: 7906015f743285fadae37a3b4c0754fcb3ef5d6c6d59ff5b8f67d0f0b43ce970
4
- data.tar.gz: da302c7be0424e4b4b476669468e8cbb1b6a3f5b38a017ddac4999ec14e0b622
3
+ metadata.gz: 0bc71cc5bd08fd8564de90311775a22d6c9b6a11bfbda2924c8782be3c265ff9
4
+ data.tar.gz: 6d28205894b18a2b5ceaaed55967d8a55aaf7ab4e375979b1366cf42fbcd98c7
5
5
  SHA512:
6
- metadata.gz: fac4b8128b250e74a9e71f165e6ca5eb431bd3f364a2efea18ceb696ce55d9e772fe73a04020811d6cbdd68341bd711fe07bc99e3f37d4ad371ea57b5446360d
7
- data.tar.gz: adef9932375e8c63f002a99ef759e1a301fdfbd1f4ad21a7b089fcda8b33acf83dcb4b6c658e5ccf9872171fac6cf58c2e0a0bbfd2a31dd2fbf7323669ea746b
6
+ metadata.gz: 87122fbe05b408cb3578e3b983e99451f5fe0898316f31f8e87107d4a09b50f0205ea803620af3a40dc2a0459015fcb67a898359a66aa998b092a9c2d143b2cd
7
+ data.tar.gz: b4fe9f24dfe1f98efd3d5988f46f147b48bf869eb3e3901634efc4ceb6089d9735588d92a4574d822c68bfe9e8c219a572d69cab971c688a864b2f4e640d2052
@@ -6,7 +6,7 @@ jobs:
6
6
  fail-fast: false
7
7
  matrix:
8
8
  # Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
9
- ruby: [2.7, '3.0', 3.1]
9
+ ruby: [2.7, '3.0', 3.1, 3.2]
10
10
  runs-on: ubuntu-latest
11
11
  steps:
12
12
  - uses: actions/checkout@v3
@@ -30,6 +30,6 @@ jobs:
30
30
  if: ${{ github.ref == 'refs/heads/main' }}
31
31
  permissions:
32
32
  contents: write
33
- uses: alphagov/govuk-infrastructure/.github/workflows/publish-rubygem.yaml@main
33
+ uses: alphagov/govuk-infrastructure/.github/workflows/publish-rubygem.yml@main
34
34
  secrets:
35
35
  GEM_HOST_API_KEY: ${{ secrets.ALPHAGOV_RUBYGEMS_API_KEY }}
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ # 5.0.0
2
+
3
+ * Forbid base elements in the Content Security Policy
4
+ * BREAKING: Content Security Policy forbids unsafe-inline script-src and data: image-src. It provides a nonce generator. Apps that can't support this will need to amend their CSP configuration in an initializer, see [example](https://github.com/alphagov/signon/commit/ddcf31f5c30b8fd334e4aea74986b24bf2b0e9be) in signon. Any apps that still use jQuery 1.x will need unsafe-inline for Firefox compatibility.
5
+
6
+ # 4.13.0
7
+
8
+ * Flush log writes to stdout immediately so that structured (JSON) logs are not lost on crash or delayed indefinitely.
9
+
1
10
  # 4.12.0
2
11
 
3
12
  * Allow `https://img.youtube.com` as a CSP image source
@@ -9,148 +18,149 @@
9
18
 
10
19
  # 4.11.1
11
20
 
12
- - Remove govuk_i18n plural rules file
21
+ * Remove govuk_i18n plural rules file
13
22
 
14
23
  # 4.11.0
15
24
 
16
- - Update Plek support to allow version 5
17
- - Add I18n plural rules for Welsh (cy), Maltese (mt) and Chinese (zh) since Rails-I18n has [dropped support](https://github.com/svenfuchs/rails-i18n/pull/1017) for them in 7.0.6 ([#266](https://github.com/alphagov/govuk_app_config/pull/266))
25
+ * Update Plek support to allow version 5
26
+ * Add I18n plural rules for Welsh (cy), Maltese (mt) and Chinese (zh) since Rails-I18n has [dropped support](https://github.com/svenfuchs/rails-i18n/pull/1017) for them in 7.0.6 ([#266](https://github.com/alphagov/govuk_app_config/pull/266))
18
27
 
19
28
  # 4.10.1
20
29
 
21
- - Fix an object ownership/sharing bug where the Rails log level was erroneously being set to `WARN` when initialising Sentry.
30
+ * Fix an object ownership/sharing bug where the Rails log level was erroneously being set to `WARN` when initialising Sentry.
22
31
 
23
32
  # 4.10.0
24
33
 
25
- - Reduce log level for the Sentry gem from `INFO` to `WARN` to avoid polluting logs with uninformative messages. This only affects log messages from the Sentry gem itself, which go to `stdout`.
34
+ * Reduce log level for the Sentry gem from `INFO` to `WARN` to avoid polluting logs with uninformative messages. This only affects log messages from the Sentry gem itself, which go to `stdout`.
26
35
 
27
36
  # 4.9.0
28
37
 
29
- - Add GovukProxy::StaticProxy to forward Static asset requests by setting `GOVUK_PROXY_STATIC_ENABLED=true`.([#261](https://github.com/alphagov/govuk_app_config/pull/261))
38
+ * Add GovukProxy::StaticProxy to forward Static asset requests by setting `GOVUK_PROXY_STATIC_ENABLED=true`.([#261](https://github.com/alphagov/govuk_app_config/pull/261))
30
39
 
31
40
  # 4.8.0
32
41
 
33
- - Enables Sentry environment names for EKS versions of integration, staging and production.([#260](https://github.com/alphagov/govuk_app_config/pull/260))
42
+ * Enables Sentry environment names for EKS versions of integration, staging and production.([#260](https://github.com/alphagov/govuk_app_config/pull/260))
34
43
 
35
44
  # 4.7.1
36
45
 
37
- - Fix the ability to open the Rails console (`bundle exec rails c`) when running inside a container ([#257](https://github.com/alphagov/govuk_app_config/pull/257)).
46
+ * Fix the ability to open the Rails console (`bundle exec rails c`) when running inside a container ([#257](https://github.com/alphagov/govuk_app_config/pull/257)).
38
47
 
39
48
  # 4.7.0
40
49
 
41
- - Adds Prometheus Sidekiq monitoring ([#255](https://github.com/alphagov/govuk_app_config/pull/255))
50
+ * Adds Prometheus Sidekiq monitoring ([#255](https://github.com/alphagov/govuk_app_config/pull/255))
42
51
 
43
52
  # 4.6.3
44
53
 
45
- - Adds `region1.google-analytics.com` to the security policy for GA ([#250](https://github.com/alphagov/govuk_app_config/pull/250))
54
+ * Adds `region1.google-analytics.com` to the security policy for GA ([#250](https://github.com/alphagov/govuk_app_config/pull/250))
46
55
 
47
56
  # 4.6.2
48
57
 
49
- - Adds a new domain to the security policy for GA ([#248](https://https://github.com/alphagov/govuk_app_config/pull/248))
58
+ * Adds a new domain to the security policy for GA ([#248](https://https://github.com/alphagov/govuk_app_config/pull/248))
50
59
 
51
60
  # 4.6.1
52
61
 
53
- - Fixes warning message to refer to correct Sidekiq gem dependency name ([#243](https://github.com/alphagov/govuk_app_config/pull/243)).
62
+ * Fixes warning message to refer to correct Sidekiq gem dependency name ([#243](https://github.com/alphagov/govuk_app_config/pull/243)).
54
63
 
55
64
  # 4.6.0
56
65
 
57
- - Add a warning for apps using GovukError with Sidekiq that don't have sentry-sidekiq installed ([#241](https://github.com/alphagov/govuk_app_config/pull/241)).
58
- - Add internal Sidekiq exception "Sidekiq::JobRetry::Skip" to excluded exceptions ([#241](https://github.com/alphagov/govuk_app_config/pull/241)).
66
+ * Add a warning for apps using GovukError with Sidekiq that don't have sentry-sidekiq installed ([#241](https://github.com/alphagov/govuk_app_config/pull/241)).
67
+ * Add internal Sidekiq exception "Sidekiq::JobRetry::Skip" to excluded exceptions ([#241](https://github.com/alphagov/govuk_app_config/pull/241)).
59
68
 
60
69
  # 4.5.0
61
70
 
62
- - Add lux.speedcurve.com to connect_src for GOV.UK Content Security Policy ([#232](https://github.com/alphagov/govuk_app_config/pull/232))
63
- - Fix prometheus_exporter to only be enabled when the GOVUK_PROMETHEUS_EXPORTER env var is set to "true" ([#231](https://github.com/alphagov/govuk_app_config/pull/231)).
64
- - Add Prometheus monitoring for EKS section to README.md ([#231](https://github.com/alphagov/govuk_app_config/pull/231)).
65
- - Fix govuk_error being incompatible with Ruby >= 3 ([#233](https://github.com/alphagov/govuk_app_config/pull/233))
66
- - Require Ruby 2.7 as the minimum supported Ruby version ([#233](https://github.com/alphagov/govuk_app_config/pull/233))
67
- - Require Sentry 5 and Unicorn 6 major versions ([#237](https://github.com/alphagov/govuk_app_config/pull/237))
68
- - Prevent sentry-rails logger warnings when govuk_error is used with non-Rails apps ([#234](https://github.com/alphagov/govuk_app_config/pull/234))
71
+ * Add lux.speedcurve.com to connect_src for GOV.UK Content Security Policy ([#232](https://github.com/alphagov/govuk_app_config/pull/232))
72
+ * Fix prometheus_exporter to only be enabled when the GOVUK_PROMETHEUS_EXPORTER env var is set to "true" ([#231](https://github.com/alphagov/govuk_app_config/pull/231)).
73
+ * Add Prometheus monitoring for EKS section to README.md ([#231](https://github.com/alphagov/govuk_app_config/pull/231)).
74
+ * Fix govuk_error being incompatible with Ruby >= 3 ([#233](https://github.com/alphagov/govuk_app_config/pull/233))
75
+ * Require Ruby 2.7 as the minimum supported Ruby version ([#233](https://github.com/alphagov/govuk_app_config/pull/233))
76
+ * Require Sentry 5 and Unicorn 6 major versions ([#237](https://github.com/alphagov/govuk_app_config/pull/237))
77
+ * Prevent sentry-rails logger warnings when govuk_error is used with non-Rails apps ([#234](https://github.com/alphagov/govuk_app_config/pull/234))
69
78
 
70
79
  # 4.4.3
71
80
 
72
- - Update prometheus exporter server to 0.0.0.0 from localhost ([#227](https://github.com/alphagov/govuk_app_config/pull/227)).
81
+ * Update prometheus exporter server to 0.0.0.0 from localhost ([#227](https://github.com/alphagov/govuk_app_config/pull/227)).
73
82
 
74
83
  # 4.4.2
75
84
 
76
- - Update HMPO webchat address in security policy ([#225](https://github.com/alphagov/govuk_app_config/pull/225)).
85
+ * Update HMPO webchat address in security policy ([#225](https://github.com/alphagov/govuk_app_config/pull/225)).
77
86
 
78
87
  # 4.4.1
79
88
 
80
- - Fix issue where GovukPrometheusExporter module prevented the gem to load due to missing constant "PrometheusExporter" ([#224](https://github.com/alphagov/govuk_app_config/pull/224)).
81
- - Lazy load the prometheus_exporter dependency for only apps that use GovukPrometheusExporter ([#224](https://github.com/alphagov/govuk_app_config/pull/224)).
89
+ * Fix issue where GovukPrometheusExporter module prevented the gem to load due to missing constant "PrometheusExporter" ([#224](https://github.com/alphagov/govuk_app_config/pull/224)).
90
+ * Lazy load the prometheus_exporter dependency for only apps that use GovukPrometheusExporter ([#224](https://github.com/alphagov/govuk_app_config/pull/224)).
82
91
 
83
92
  # 4.4.0
84
93
 
85
- - Add GovukPrometheusModule, to allow for export of prometheus metrics ([#223](https://github.com/alphagov/govuk_app_config/pull/223)).
94
+ * Add GovukPrometheusModule, to allow for export of prometheus metrics ([#223](https://github.com/alphagov/govuk_app_config/pull/223)).
86
95
 
87
96
  # 4.3.0
88
97
 
89
- - Remove Speedcurve's LUX from the connect-src policy ([#216](https://github.com/alphagov/govuk_app_config/pull/216)).
98
+ * Remove Speedcurve's LUX from the connect-src policy ([#216](https://github.com/alphagov/govuk_app_config/pull/216)).
90
99
 
91
100
  # 4.2.0
92
101
 
93
- - Add pluralisation rules for Azerbaijani, Persian, Georgian, and Turkish. ([#219](https://github.com/alphagov/govuk_app_config/pull/219))
102
+ * Add pluralisation rules for Azerbaijani, Persian, Georgian, and Turkish. ([#219](https://github.com/alphagov/govuk_app_config/pull/219))
94
103
 
95
104
  # 4.1.0
96
105
 
97
- - Add Puma to dependencies ([#214](https://github.com/alphagov/govuk_app_config/pull/214)).
106
+ * Add Puma to dependencies ([#214](https://github.com/alphagov/govuk_app_config/pull/214)).
98
107
 
99
108
  # 4.0.1
100
109
 
101
- - Update Content Security Policy with new klick2contact.com subdomain ([#213](https://github.com/alphagov/govuk_app_config/pull/213)).
110
+ * Update Content Security Policy with new klick2contact.com subdomain ([#213](https://github.com/alphagov/govuk_app_config/pull/213)).
102
111
 
103
112
  # 4.0.0
104
113
 
105
- - BREAKING: replaces deprecated `sentry-raven` with `sentry-ruby` and `sentry-rails`. Follow the **[migration guide](https://docs.sentry.io/platforms/ruby/migration/)** before upgrading to this version of govuk_app_config to ensure full compatibility with the new gems.
106
- - BREAKING: `GovukError.configure` can only be called once, and non-Rails apps will have to manually call `GovukError.configure` in order to initialise Sentry.
107
- - BREAKING: apps will no longer increment the `error_reports_failed` statsd if events fail to get sent to Sentry.
108
- - BREAKING: the behaviour of `before_send` has changed, and the `should_capture` method is deprecated.
109
- - See pre-release notes below for details.
110
- - PR: [#212](https://github.com/alphagov/govuk_app_config/pull/212)
114
+ * BREAKING: replaces deprecated `sentry-raven` with `sentry-ruby` and `sentry-rails`. Follow the **[migration guide](https://docs.sentry.io/platforms/ruby/migration/)** before upgrading to this version of govuk_app_config to ensure full compatibility with the new gems.
115
+ * BREAKING: `GovukError.configure` can only be called once, and non-Rails apps will have to manually call `GovukError.configure` in order to initialise Sentry.
116
+ * BREAKING: apps will no longer increment the `error_reports_failed` statsd if events fail to get sent to Sentry.
117
+ * BREAKING: the behaviour of `before_send` has changed, and the `should_capture` method is deprecated.
118
+ * See pre-release notes below for details.
119
+ * PR: [#212](https://github.com/alphagov/govuk_app_config/pull/212)
111
120
 
112
121
  # 4.0.0.pre.4
113
122
 
114
- - Fix Sentry client initialisation ([#205](https://github.com/alphagov/govuk_app_config/pull/205)).
115
- - BREAKING: non-Rails apps will need to manually call `GovukError.configure` in order to initialise Sentry.
116
- - BREAKING: `GovukError.configure` can only be called once by the downstream application.
123
+ * Fix Sentry client initialisation ([#205](https://github.com/alphagov/govuk_app_config/pull/205)).
124
+ * BREAKING: non-Rails apps will need to manually call `GovukError.configure` in order to initialise Sentry.
125
+ * BREAKING: `GovukError.configure` can only be called once by the downstream application.
117
126
 
118
127
  # 4.0.0.pre.3
119
128
 
120
- - Include [sentry-rails](https://github.com/getsentry/sentry-ruby/tree/master/sentry-rails) by default ([#203](https://github.com/alphagov/govuk_app_config/pull/203)).
129
+ * Include [sentry-rails](https://github.com/getsentry/sentry-ruby/tree/master/sentry-rails) by default ([#203](https://github.com/alphagov/govuk_app_config/pull/203)).
121
130
 
122
131
  # 4.0.0.pre.2
123
132
 
124
- - Fix default Sentry configuration ([#202](https://github.com/alphagov/govuk_app_config/pull/202)).
125
- - BREAKING: this means no more `silence_ready` or `transport_failure_callback` options.
133
+ * Fix default Sentry configuration ([#202](https://github.com/alphagov/govuk_app_config/pull/202)).
134
+ * BREAKING: this means no more `silence_ready` or `transport_failure_callback` options.
126
135
 
127
136
  # 4.0.0.pre.1
128
137
 
129
- - BREAKING: upgrades Sentry gem from `sentry-raven` to `sentry-ruby` ([#199](https://github.com/alphagov/govuk_app_config/pull/199)). There is a **[migration guide](https://docs.sentry.io/platforms/ruby/migration/)** you should follow before upgrading to this version of govuk_app_config.
130
- - This release also fixes the `data_sync_excluded_exceptions` behaviour that was broken in v3.1.0 (later fixed in v3.3.0, which was released after 4.0.0.pre.1).
131
- - Released as a pre-release to identify and fix any problems before a wider rollout.
138
+ * BREAKING: upgrades Sentry gem from `sentry-raven` to `sentry-ruby` ([#199](https://github.com/alphagov/govuk_app_config/pull/199)). There is a **[migration guide](https://docs.sentry.io/platforms/ruby/migration/)** you should follow before upgrading to this version of govuk_app_config.
139
+ * This release also fixes the `data_sync_excluded_exceptions` behaviour that was broken in v3.1.0 (later fixed in v3.3.0, which was released after 4.0.0.pre.1).
140
+ * Released as a pre-release to identify and fix any problems before a wider rollout.
132
141
 
133
142
  # 3.3.0
134
143
 
135
- - Revert the `should_capture`/`before_send` consolidation introduced in 3.1.0. This fixes the `data_sync_excluded_exceptions` behaviour that has been broken since v3.1.0. ([#211](https://github.com/alphagov/govuk_app_config/pull/211))
144
+ * Revert the `should_capture`/`before_send` consolidation introduced in 3.1.0. This fixes the `data_sync_excluded_exceptions` behaviour that has been broken since v3.1.0. ([#211](https://github.com/alphagov/govuk_app_config/pull/211))
136
145
 
137
146
  # 3.2.0
138
147
 
139
- - Add Speedcurve's LUX to connect-src policy ([#206](https://github.com/alphagov/govuk_app_config/pull/206))
148
+ * Add Speedcurve's LUX to connect-src policy ([#206](https://github.com/alphagov/govuk_app_config/pull/206))
140
149
 
141
150
  # 3.1.1
142
151
 
143
- - Fix the new before_send behaviour & tests, and add documentation ([#197](https://github.com/alphagov/govuk_app_config/pull/197))
152
+ * Fix the new before_send behaviour & tests, and add documentation ([#197](https://github.com/alphagov/govuk_app_config/pull/197))
144
153
 
145
154
  # 3.1.0
146
155
 
147
- - Remove support for `should_capture` callbacks in favour of `before_send` ([#196](https://github.com/alphagov/govuk_app_config/pull/196))
156
+ * Remove support for `should_capture` callbacks in favour of `before_send` ([#196](https://github.com/alphagov/govuk_app_config/pull/196))
148
157
 
149
158
  # 3.0.0
150
159
 
151
160
  * BREAKING: Implement RFC 141 - remove unsuitable healthchecks and return a 500 on healthcheck failure ([#193](https://github.com/alphagov/govuk_app_config/pull/193))
152
161
 
153
162
  # 2.10.0
163
+
154
164
  * Allow LUX domain on img-src policy ([#191](https://github.com/alphagov/govuk_app_config/pull/191))
155
165
 
156
166
  # 2.9.1
@@ -28,13 +28,12 @@ module GovukContentSecurityPolicy
28
28
  # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/default-src
29
29
  policy.default_src :self
30
30
 
31
+ # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/base-uri
32
+ policy.base_uri :none
33
+
31
34
  # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/img-src
35
+ # Note: we purposely don't include `data:` here because it produces a security risk.
32
36
  policy.img_src :self,
33
- # This allows Base64 encoded images, but is a security
34
- # risk as it can embed third party resources.
35
- # As of December 2022, we intend to remove this prior
36
- # to making the CSP live.
37
- :data,
38
37
  *GOVUK_DOMAINS,
39
38
  *GOOGLE_ANALYTICS_DOMAINS, # Tracking pixels
40
39
  # Speedcurve real user monitoring (RUM) - as per: https://support.speedcurve.com/docs/add-rum-to-your-csp
@@ -45,25 +44,28 @@ module GovukContentSecurityPolicy
45
44
  "https://img.youtube.com"
46
45
 
47
46
  # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/script-src
47
+ # Note: we purposely don't include `data:`, `unsafe-inline` or `unsafe-eval` because
48
+ # they are security risks, if you need them for a legacy app please only apply them at
49
+ # an app level.
48
50
  policy.script_src :self,
49
51
  *GOOGLE_ANALYTICS_DOMAINS,
50
52
  *GOOGLE_STATIC_DOMAINS,
51
53
  # Allow YouTube Embeds (Govspeak turns YouTube links into embeds)
52
54
  "*.ytimg.com",
53
55
  "www.youtube.com",
54
- "www.youtube-nocookie.com",
55
- # This allows inline scripts and thus is a XSS risk.
56
- # As of December 2022, we intend to work towards removing
57
- # this from apps that don't use jQuery 1.12 (which needs
58
- # this) once we've set up nonces.
59
- :unsafe_inline
56
+ "www.youtube-nocookie.com"
60
57
 
61
58
  # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/style-src
59
+ # Note: we purposely don't include `data:` or `unsafe-eval` because
60
+ # they are security risks, if you need them for a legacy app please only apply them at
61
+ # an app level.
62
62
  policy.style_src :self,
63
63
  *GOOGLE_STATIC_DOMAINS,
64
- # This allows style="" attributes and style elements.
65
- # As of December 2022, we intend to remove this prior
66
- # to making the CSP live due to the security risks it has.
64
+ # This allows `style=""` attributes and `<style>` elements.
65
+ # As of January 2023 our intentions to remove this were scuppered
66
+ # by Govspeak [1] using inline styles on tables. Until that
67
+ # is resolved we'll keep unsafe_inline
68
+ # [1]: https://github.com/alphagov/govspeak/blob/5642fcc4231f215d1c58ad7feb30ca42fb8cfb91/lib/govspeak/html_sanitizer.rb#L72-L73
67
69
  :unsafe_inline
68
70
 
69
71
  # https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/font-src
@@ -91,6 +93,20 @@ module GovukContentSecurityPolicy
91
93
  def self.configure
92
94
  Rails.application.config.content_security_policy_report_only = ENV.include?("GOVUK_CSP_REPORT_ONLY")
93
95
 
96
+ # Sets a nonce per request that can be set on script-src and style-src
97
+ # directives depending on the value of Rails.application.config.content_security_policy_nonce_directives
98
+ #
99
+ # Note: if an application needs to set unsafe-inline they will need to
100
+ # unset this generator (by setting this config option to nil in their application)
101
+ Rails.application.config.content_security_policy_nonce_generator = ->(_request) { SecureRandom.base64(16) }
102
+
103
+ # This only applies the nonce generator to the script-src directive. We need this to
104
+ # use unsafe-inline for style-src as a nonce will override it.
105
+ #
106
+ # When we want to apply it to style-src we can remove this line as the Rails default
107
+ # is for both script-src and style-src
108
+ Rails.application.config.content_security_policy_nonce_directives = %w[script-src]
109
+
94
110
  policy = Rails.application.config.content_security_policy(&method(:build_policy))
95
111
 
96
112
  # # allow apps to customise the CSP by passing a block e.g:
@@ -12,36 +12,37 @@ module GovukLogging
12
12
  # `Rails.logger` calls or 'puts' statements. However these are not in a
13
13
  # JSON format which causes problems for the log file parsers.
14
14
  #
15
- # To resolve this we've directed stdout to stderr, to cover any Rails
15
+ # To resolve this we redirect stdout to stderr, to cover any Rails
16
16
  # writing. This frees up the normal stdout for the logstasher logs.
17
+ #
18
+ # We also disable buffering, so that logs aren't lost on crash or delayed
19
+ # indefinitely while troubleshooting.
17
20
 
18
21
  # rubocop:disable Style/GlobalVars
19
22
  $real_stdout = $stdout.clone
23
+ $real_stdout.sync = true
20
24
  $stdout.reopen($stderr)
25
+ $stdout.sync = true
21
26
  # rubocop:enable Style/GlobalVars
22
27
 
23
28
  # Send Rails' logs to STDERR because they're not JSON formatted.
24
29
  Rails.logger = ActiveSupport::TaggedLogging.new(Logger.new($stderr, level: Rails.logger.level))
25
30
 
26
- # Custom that will be added to the Rails request logs
27
31
  LogStasher.add_custom_fields do |fields|
28
- # Mirrors Nginx request logging, e.g GET /path/here HTTP/1.1
32
+ # Mirrors Nginx request logging, e.g. GET /path/here HTTP/1.1
29
33
  fields[:request] = "#{request.request_method} #{request.fullpath} #{request.headers['SERVER_PROTOCOL']}"
30
34
 
31
- # Pass request Id to logging
32
35
  fields[:govuk_request_id] = request.headers["GOVUK-Request-Id"]
33
-
34
36
  fields[:varnish_id] = request.headers["X-Varnish"]
35
-
36
37
  fields[:govuk_app_config] = GovukAppConfig::VERSION
37
38
  end
38
39
 
39
40
  Rails.application.config.logstasher.enabled = true
40
41
 
41
- # Log controller actions so that we can graph response times
42
+ # Log controller actions so that we can graph response times.
42
43
  Rails.application.config.logstasher.controller_enabled = true
43
44
 
44
- # The other loggers are not that interesting in production
45
+ # The other loggers are not that interesting in production.
45
46
  Rails.application.config.logstasher.mailer_enabled = false
46
47
  Rails.application.config.logstasher.record_enabled = false
47
48
  Rails.application.config.logstasher.view_enabled = false
@@ -59,11 +60,9 @@ module GovukLogging
59
60
  if defined?(GdsApi::Base)
60
61
  GdsApi::Base.default_options ||= {}
61
62
 
62
- # The GDS API Adapters gem logs JSON to describe the requests it
63
- # makes and the responses it gets, so direct this to the
64
- # logstasher logger
65
- GdsApi::Base.default_options[:logger] =
66
- Rails.application.config.logstasher.logger
63
+ # The gds-api-adapters gem logs JSON to describe the requests it makes and
64
+ # the responses it gets, so direct this to the logstasher logger.
65
+ GdsApi::Base.default_options[:logger] = Rails.application.config.logstasher.logger
67
66
  end
68
67
 
69
68
  RailsExt::ActionDispatch.monkey_patch_log_error if RailsExt::ActionDispatch.should_monkey_patch_log_error?
@@ -1,3 +1,3 @@
1
1
  module GovukAppConfig
2
- VERSION = "4.12.0".freeze
2
+ VERSION = "5.0.0".freeze
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: 4.12.0
4
+ version: 5.0.0
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: 2023-01-03 00:00:00.000000000 Z
11
+ date: 2023-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: logstasher
@@ -336,7 +336,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
336
336
  - !ruby/object:Gem::Version
337
337
  version: '0'
338
338
  requirements: []
339
- rubygems_version: 3.4.2
339
+ rubygems_version: 3.4.5
340
340
  signing_key:
341
341
  specification_version: 4
342
342
  summary: Base configuration for GOV.UK applications