slimmer 18.0.0 → 18.1.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: a7a260effd72ec2553063c010694a0486e5990b664e5934332630b40586933a1
4
- data.tar.gz: 70ebd575e41468a07f64c9ebff2e0b168a5cd890f5f32c736bfdbd70befdb1f2
3
+ metadata.gz: 7ed01a6ffcd005b8c3c535e3c470111fc7fbc8616fa8cb4de03c167ac76c91e9
4
+ data.tar.gz: 630246d90121b56ebe60511dd04a1f2fbf83ef7bf124bbd17be473d49976c599
5
5
  SHA512:
6
- metadata.gz: 62607015532688137712ead664e2948e7581c739d6ecfc58b31164d1f63a8a15b652f8e750a2af23e4b0a5439e4a5d139862e8d0bc3cf3c3535c8d93b387a898
7
- data.tar.gz: 6bd6af1f703e2d4ec1ce04dc2a883fbb7f208e9d24a3819e257e2d109fc067d0472ed96001d9e873385beab1a3a1aff41db781561d37ac2d383a817fac5b761c
6
+ metadata.gz: 2a2e20be60419f1aecb3630bc1d26029ad2c216b30f3b1308a56a6779d8e7d420e9e1b68adb24ccf4a5b8fed8efbe86c75a4ab8b6e8572e310305a4ae3c09456
7
+ data.tar.gz: 2ae4731e6714cf0ebb47706b8a6723ae113e86fae9cafdd293e6b5c817a7df1faae9163a82f87539897a67c78b9f3c274e8491cd5bd5f7d1190e7cab15a14e4b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 18.1.0
2
+
3
+ * Decorate inline script elements with nonce attribute for appropriately configured Rails requests
4
+
1
5
  # 18.0.0
2
6
 
3
7
  * BREAKING: Drop support for determining Rails < 6 application names
@@ -0,0 +1,21 @@
1
+ module Slimmer::Processors
2
+ class NonceInserter
3
+ def initialize(env)
4
+ # As Rails is an optional dependency of this gem quietly do nothing if Rails
5
+ # classes don't exist.
6
+ @nonce = if defined?(ActionDispatch::Request)
7
+ ActionDispatch::Request.new(env).content_security_policy_nonce
8
+ end
9
+ end
10
+
11
+ def filter(_src, dest)
12
+ return unless @nonce
13
+
14
+ # Add the nonce attribute to script elements that don't have a src attribute
15
+ # we expect those with src to be on a CSP host allow list
16
+ dest.css("script:not([src])").each do |script|
17
+ script["nonce"] = @nonce
18
+ end
19
+ end
20
+ end
21
+ end
data/lib/slimmer/skin.rb CHANGED
@@ -104,6 +104,7 @@ module Slimmer
104
104
  template_wrapper_id = "wrapper" # All templates in Static use `#wrapper`
105
105
 
106
106
  processors = [
107
+ Processors::NonceInserter.new(source_request.env), # for security, this needs to be run before any application HTML is inserted
107
108
  Processors::TitleInserter.new,
108
109
  Processors::TagMover.new,
109
110
  Processors::ConditionalCommentMover.new,
@@ -1,3 +1,3 @@
1
1
  module Slimmer
2
- VERSION = "18.0.0".freeze
2
+ VERSION = "18.1.0".freeze
3
3
  end
data/lib/slimmer.rb CHANGED
@@ -38,6 +38,7 @@ module Slimmer
38
38
  autoload :ConditionalCommentMover, "slimmer/processors/conditional_comment_mover"
39
39
  autoload :FeedbackURLSwapper, "slimmer/processors/feedback_url_swapper"
40
40
  autoload :MetadataInserter, "slimmer/processors/metadata_inserter"
41
+ autoload :NonceInserter, "slimmer/processors/nonce_inserter"
41
42
  autoload :HeaderContextInserter, "slimmer/processors/header_context_inserter"
42
43
  autoload :InsideHeaderInserter, "slimmer/processors/inside_header_inserter"
43
44
  autoload :SearchPathSetter, "slimmer/processors/search_path_setter"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slimmer
3
3
  version: !ruby/object:Gem::Version
4
- version: 18.0.0
4
+ version: 18.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GOV.UK Dev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-21 00:00:00.000000000 Z
11
+ date: 2023-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -170,14 +170,14 @@ dependencies:
170
170
  requirements:
171
171
  - - '='
172
172
  - !ruby/object:Gem::Version
173
- version: 4.7.0
173
+ version: 4.9.0
174
174
  type: :development
175
175
  prerelease: false
176
176
  version_requirements: !ruby/object:Gem::Requirement
177
177
  requirements:
178
178
  - - '='
179
179
  - !ruby/object:Gem::Version
180
- version: 4.7.0
180
+ version: 4.9.0
181
181
  - !ruby/object:Gem::Dependency
182
182
  name: webmock
183
183
  requirement: !ruby/object:Gem::Requirement
@@ -216,6 +216,7 @@ files:
216
216
  - lib/slimmer/processors/header_context_inserter.rb
217
217
  - lib/slimmer/processors/inside_header_inserter.rb
218
218
  - lib/slimmer/processors/metadata_inserter.rb
219
+ - lib/slimmer/processors/nonce_inserter.rb
219
220
  - lib/slimmer/processors/search_parameter_inserter.rb
220
221
  - lib/slimmer/processors/search_path_setter.rb
221
222
  - lib/slimmer/processors/search_remover.rb
@@ -250,7 +251,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
250
251
  - !ruby/object:Gem::Version
251
252
  version: '0'
252
253
  requirements: []
253
- rubygems_version: 3.3.24
254
+ rubygems_version: 3.4.4
254
255
  signing_key:
255
256
  specification_version: 4
256
257
  summary: Thinner than the skinner