dial 0.2.3 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: edead8fe405ee09b2ece6be004f6200ddd9394707a41da3509cbd168f3b88c67
4
- data.tar.gz: 506f4b258c2b0acf117b1f4885ede6cf93ec739c1f21e0dc82b1f3da086f9a2c
3
+ metadata.gz: c21506e3c567f79104e394c2ab2fc1c29d433ef9e9e27f201d8fe3e6bdc2227f
4
+ data.tar.gz: 5a8a65aa3fcdd52d59508ebac6bb12bfa156d6f577793f7c05ac8eb14d5409b3
5
5
  SHA512:
6
- metadata.gz: c8f6c3705814f0cc0ae49bddf462741cf74d6de0733bd08280f6b01123368afb6ad46a1f7bf09329ee1c16c53a1d651c34b39d7277efce651f72550cd8e06557
7
- data.tar.gz: 22236134d9731d47eacbc6d931ed2484b4e5451c875e554dcd5fc5fea3db84e3aaaf429db3f318939de30d52aa49ff49251f5300fc8243bf41e247d40c11c555
6
+ metadata.gz: c20d37444e2d186490ea5e75d30c2a6940d56adbff21c91d01a448d96b4b7b6baa0ead5da5305a1398dcd8e916f5a9dab60c2d0d101404a1377a998fe2d2d91c
7
+ data.tar.gz: 525eef47d8136c0c34ddc0c8460637370e87ea13d43c8d83e1c3b4c9dc992b192414f570a0258a9ffd16206a235611a5450982c3a9cf474f12552c16ef646613
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.4] - 2025-03-03
4
+
5
+ - Add configuration option for setting script CSP nonce (thanks @matthaigh27)
6
+
3
7
  ## [0.2.3] - 2025-02-28
4
8
 
5
9
  - Add configuration API
data/README.md CHANGED
@@ -39,12 +39,21 @@ mount Dial::Engine, at: "/" if Rails.env.development?
39
39
  # config/initializers/dial.rb
40
40
 
41
41
  Dial.configure do |config|
42
- config.vernier_interval = 100 # default: 200
43
- config.vernier_allocation_interval = 10_000 # default: 20_000
44
- config.prosopite_ignore_queries += [/pg_sleep/i] # default: [/schema_migrations/i]
42
+ config.vernier_interval = 100
43
+ config.vernier_allocation_interval = 10_000
44
+ config.prosopite_ignore_queries += [/pg_sleep/i]
45
45
  end
46
46
  ```
47
47
 
48
+ ### Options
49
+
50
+ Option | Description | Default
51
+ - | - | -
52
+ `vernier_interval` | Sets the `interval` option for vernier. | `200`
53
+ `vernier_allocation_interval` | Sets the `allocation_interval` option for vernier. | `20_000`
54
+ `prosopite_ignore_queries` | Sets the `ignore_queries` option for prosopite. | `[/schema_migrations/i]`
55
+ `content_security_policy_nonce` | Sets the content security policy nonce to use when inserting Dial's script. Can be a string, or a Proc which receives `env` and response `headers` as arguments and returns the nonce. | Rails generated nonce or `nil`
56
+
48
57
  ## Development
49
58
 
50
59
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake test` to run the
@@ -15,14 +15,15 @@ module Dial
15
15
  vernier_interval: VERNIER_INTERVAL,
16
16
  vernier_allocation_interval: VERNIER_ALLOCATION_INTERVAL,
17
17
  prosopite_ignore_queries: PROSOPITE_IGNORE_QUERIES,
18
+ content_security_policy_nonce: -> (env, _headers) { env[NONCE] || "" },
18
19
  }
19
20
 
20
21
  @options.keys.each do |key|
21
- define_singleton_method(key) do
22
+ define_singleton_method key do
22
23
  @options[key]
23
24
  end
24
25
 
25
- define_singleton_method("#{key}=") do |value|
26
+ define_singleton_method "#{key}=" do |value|
26
27
  @options[key] = value
27
28
  end
28
29
  end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "rack"
4
+ require "action_dispatch"
4
5
 
5
6
  require_relative "version"
6
7
 
@@ -10,6 +11,7 @@ module Dial
10
11
  HTTP_ACCEPT = "HTTP_ACCEPT"
11
12
  CONTENT_TYPE = ::Rack::CONTENT_TYPE
12
13
  CONTENT_LENGTH = ::Rack::CONTENT_LENGTH
14
+ NONCE = ::ActionDispatch::ContentSecurityPolicy::Request::NONCE
13
15
  REQUEST_TIMING = "dial_request_timing"
14
16
 
15
17
  FILE_STALE_SECONDS = 60 * 60
@@ -5,7 +5,7 @@ require "uri"
5
5
  module Dial
6
6
  class Panel
7
7
  class << self
8
- def html env, profile_out_filename, query_logs, ruby_vm_stat, gc_stat, gc_stat_heap, server_timing
8
+ def html env, headers, profile_out_filename, query_logs, ruby_vm_stat, gc_stat, gc_stat_heap, server_timing
9
9
  <<~HTML
10
10
  <style>#{style}</style>
11
11
 
@@ -69,7 +69,9 @@ module Dial
69
69
  </div>
70
70
  </div>
71
71
 
72
- <script>#{script}</script>
72
+ <script nonce="#{configured_nonce env, headers}">
73
+ #{script}
74
+ </script>
73
75
  HTML
74
76
  end
75
77
 
@@ -171,7 +173,7 @@ module Dial
171
173
  end
172
174
 
173
175
  def formatted_rails_route_info env
174
- rails_route_info = begin
176
+ begin
175
177
  ::Rails.application.routes.recognize_path env[::Rack::PATH_INFO], method: env[::Rack::REQUEST_METHOD]
176
178
  rescue ::ActionController::RoutingError
177
179
  {}
@@ -253,6 +255,15 @@ module Dial
253
255
  HTML
254
256
  end.join
255
257
  end
258
+
259
+ def configured_nonce env, headers
260
+ config_nonce = Dial._configuration.content_security_policy_nonce
261
+ if config_nonce.instance_of? Proc
262
+ config_nonce.call env, headers
263
+ else
264
+ config_nonce
265
+ end
266
+ end
256
267
  end
257
268
  end
258
269
  end
@@ -27,7 +27,7 @@ module Dial
27
27
  def stat_diff before, after, no_diff: []
28
28
  after.except(*no_diff).each_with_object({}) do |(key, value), diff|
29
29
  diff[key] = value - before[key]
30
- end.merge after.slice *no_diff
30
+ end.merge after.slice(*no_diff)
31
31
  end
32
32
  end
33
33
  end
@@ -51,10 +51,12 @@ module Dial
51
51
  body = String.new.tap do |str|
52
52
  rack_body.each { |chunk| str << chunk }
53
53
  rack_body.close if rack_body.respond_to? :close
54
- end.sub "</body>", <<~HTML
55
- #{Panel.html env, profile_out_filename, query_logs, ruby_vm_stat, gc_stat, gc_stat_heap, server_timing}
56
- </body>
57
- HTML
54
+
55
+ str.sub! "</body>", <<~HTML
56
+ #{Panel.html env, headers, profile_out_filename, query_logs, ruby_vm_stat, gc_stat, gc_stat_heap, server_timing}
57
+ </body>
58
+ HTML
59
+ end
58
60
 
59
61
  headers[CONTENT_LENGTH] = body.bytesize.to_s
60
62
 
@@ -86,7 +88,7 @@ module Dial
86
88
 
87
89
  def clear_query_logs!
88
90
  [].tap do |query_logs|
89
- File.open("#{query_log_dir_pathname}/#{PROSOPITE_LOG_FILENAME}", "r+") do |file|
91
+ File.open "#{query_log_dir_pathname}/#{PROSOPITE_LOG_FILENAME}", "r+" do |file|
90
92
  entry = section = count = nil
91
93
  file.each_line do |line|
92
94
  entry, section, count = process_query_log_line line, entry, section, count
data/lib/dial/railtie.rb CHANGED
@@ -48,7 +48,6 @@ module Dial
48
48
  app.config.after_initialize do
49
49
  Dial._configuration.freeze
50
50
 
51
- # set static configuration options
52
51
  ::Prosopite.ignore_queries = Dial._configuration.prosopite_ignore_queries
53
52
  end
54
53
  end
data/lib/dial/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dial
4
- VERSION = "0.2.3"
4
+ VERSION = "0.2.4"
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dial
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Young
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-02-28 00:00:00.000000000 Z
10
+ date: 2025-03-03 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: railties