sqreen 1.18.5 → 1.19.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (180) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +22 -0
  3. data/lib/sqreen/actions.rb +2 -0
  4. data/lib/sqreen/actions/actions_index.rb +16 -0
  5. data/lib/sqreen/actions/base.rb +4 -10
  6. data/lib/sqreen/actions/block_ip.rb +2 -0
  7. data/lib/sqreen/actions/block_user.rb +2 -0
  8. data/lib/sqreen/actions/ip_range_indexed_action_class.rb +4 -24
  9. data/lib/sqreen/actions/ip_ranges_index.rb +32 -11
  10. data/lib/sqreen/actions/redirect_ip.rb +2 -0
  11. data/lib/sqreen/actions/redirect_user.rb +2 -0
  12. data/lib/sqreen/actions/repository.rb +27 -8
  13. data/lib/sqreen/actions/unknown_action_type.rb +4 -0
  14. data/lib/sqreen/actions/user_action_class.rb +5 -30
  15. data/lib/sqreen/actions/users_index.rb +35 -0
  16. data/lib/sqreen/agent.rb +2 -1
  17. data/lib/sqreen/attack_blocked.rb +2 -0
  18. data/lib/sqreen/backport.rb +2 -0
  19. data/lib/sqreen/backport/clock_gettime.rb +74 -0
  20. data/lib/sqreen/backport/original_name.rb +2 -0
  21. data/lib/sqreen/binding_accessor.rb +2 -0
  22. data/lib/sqreen/binding_accessor/path_elem.rb +2 -0
  23. data/lib/sqreen/binding_accessor/transforms.rb +8 -1
  24. data/lib/sqreen/call_countable.rb +2 -0
  25. data/lib/sqreen/capped_queue.rb +2 -0
  26. data/lib/sqreen/cb.rb +2 -0
  27. data/lib/sqreen/cb_tree.rb +2 -0
  28. data/lib/sqreen/condition_evaluator.rb +2 -0
  29. data/lib/sqreen/conditionable.rb +2 -0
  30. data/lib/sqreen/configuration.rb +14 -0
  31. data/lib/sqreen/context.rb +2 -0
  32. data/lib/sqreen/default_cb.rb +2 -0
  33. data/lib/sqreen/deferred_logger.rb +2 -0
  34. data/lib/sqreen/deliveries.rb +2 -0
  35. data/lib/sqreen/deliveries/batch.rb +2 -0
  36. data/lib/sqreen/deliveries/simple.rb +2 -0
  37. data/lib/sqreen/dependency.rb +3 -1
  38. data/lib/sqreen/dependency/detector.rb +22 -14
  39. data/lib/sqreen/dependency/libsqreen.rb +4 -0
  40. data/lib/sqreen/dependency/new_relic.rb +2 -0
  41. data/lib/sqreen/dependency/rack.rb +10 -5
  42. data/lib/sqreen/dependency/rails.rb +4 -0
  43. data/lib/sqreen/dependency/sentry.rb +2 -0
  44. data/lib/sqreen/dependency/sinatra.rb +12 -1
  45. data/lib/sqreen/encoding_sanitizer.rb +2 -0
  46. data/lib/sqreen/error_handling_middleware.rb +2 -0
  47. data/lib/sqreen/event.rb +2 -0
  48. data/lib/sqreen/events/attack.rb +2 -0
  49. data/lib/sqreen/events/remote_exception.rb +2 -0
  50. data/lib/sqreen/events/request_record.rb +2 -0
  51. data/lib/sqreen/exception.rb +2 -0
  52. data/lib/sqreen/formatter_with_tid.rb +2 -0
  53. data/lib/sqreen/framework_cb.rb +2 -0
  54. data/lib/sqreen/frameworks.rb +2 -0
  55. data/lib/sqreen/frameworks/generic.rb +2 -0
  56. data/lib/sqreen/frameworks/rails.rb +1 -0
  57. data/lib/sqreen/frameworks/rails3.rb +2 -0
  58. data/lib/sqreen/frameworks/request_recorder.rb +2 -0
  59. data/lib/sqreen/frameworks/sinatra.rb +2 -0
  60. data/lib/sqreen/frameworks/sqreen_test.rb +2 -0
  61. data/lib/sqreen/graft.rb +12 -0
  62. data/lib/sqreen/graft/call.rb +150 -0
  63. data/lib/sqreen/{dependency → graft}/callback.rb +12 -4
  64. data/lib/sqreen/graft/hook.rb +316 -0
  65. data/lib/sqreen/{dependency → graft}/hook_point.rb +152 -33
  66. data/lib/sqreen/graft/hook_point_error.rb +10 -0
  67. data/lib/sqreen/invalid_signature_exception.rb +2 -0
  68. data/lib/sqreen/js.rb +2 -0
  69. data/lib/sqreen/js/call_context.rb +2 -0
  70. data/lib/sqreen/js/context_pool.rb +2 -0
  71. data/lib/sqreen/js/exec_js_runnable.rb +2 -0
  72. data/lib/sqreen/js/execjs_adapter.rb +2 -0
  73. data/lib/sqreen/js/executable_js.rb +2 -0
  74. data/lib/sqreen/js/js_service.rb +2 -0
  75. data/lib/sqreen/js/js_service_adapter.rb +2 -0
  76. data/lib/sqreen/js/mini_racer_adapter.rb +2 -0
  77. data/lib/sqreen/js/mini_racer_executable_js.rb +2 -0
  78. data/lib/sqreen/js/thread_local_exec_js_runnable.rb +2 -0
  79. data/lib/sqreen/legacy.rb +8 -0
  80. data/lib/sqreen/{instrumentation.rb → legacy/instrumentation.rb} +31 -2
  81. data/lib/sqreen/log.rb +2 -0
  82. data/lib/sqreen/log/loggable.rb +28 -0
  83. data/lib/sqreen/logger.rb +2 -0
  84. data/lib/sqreen/metrics.rb +2 -0
  85. data/lib/sqreen/metrics/average.rb +2 -0
  86. data/lib/sqreen/metrics/base.rb +2 -0
  87. data/lib/sqreen/metrics/binning.rb +2 -0
  88. data/lib/sqreen/metrics/collect.rb +2 -0
  89. data/lib/sqreen/metrics/sum.rb +2 -0
  90. data/lib/sqreen/metrics_store.rb +2 -0
  91. data/lib/sqreen/metrics_store/already_registered_metric.rb +2 -0
  92. data/lib/sqreen/metrics_store/unknown_metric.rb +2 -0
  93. data/lib/sqreen/metrics_store/unregistered_metric.rb +2 -0
  94. data/lib/sqreen/middleware.rb +2 -0
  95. data/lib/sqreen/mono_time.rb +2 -0
  96. data/lib/sqreen/node.rb +2 -0
  97. data/lib/sqreen/not_implemented_yet.rb +2 -0
  98. data/lib/sqreen/null_logger.rb +2 -0
  99. data/lib/sqreen/payload_creator.rb +2 -0
  100. data/lib/sqreen/payload_creator/header_section.rb +2 -0
  101. data/lib/sqreen/performance_notifications.rb +2 -0
  102. data/lib/sqreen/performance_notifications/binned_metrics.rb +2 -0
  103. data/lib/sqreen/performance_notifications/log.rb +2 -0
  104. data/lib/sqreen/performance_notifications/log_performance.rb +2 -0
  105. data/lib/sqreen/performance_notifications/metrics.rb +2 -0
  106. data/lib/sqreen/performance_notifications/newrelic.rb +2 -0
  107. data/lib/sqreen/prefix.rb +2 -0
  108. data/lib/sqreen/rails_middleware.rb +2 -0
  109. data/lib/sqreen/remote_command.rb +2 -0
  110. data/lib/sqreen/remote_command/failure_output.rb +5 -0
  111. data/lib/sqreen/rules.rb +2 -0
  112. data/lib/sqreen/rules/attrs.rb +2 -0
  113. data/lib/sqreen/rules/auth_track_cb.rb +2 -0
  114. data/lib/sqreen/rules/binding_accessor_matcher_cb.rb +2 -0
  115. data/lib/sqreen/rules/binding_accessor_metrics.rb +2 -0
  116. data/lib/sqreen/rules/blacklist_ips_cb.rb +2 -0
  117. data/lib/sqreen/rules/count_http_codes.rb +2 -0
  118. data/lib/sqreen/rules/crawler_user_agent_matches_cb.rb +2 -0
  119. data/lib/sqreen/rules/crawler_user_agent_matches_metrics_cb.rb +2 -0
  120. data/lib/sqreen/rules/custom_error_cb.rb +2 -0
  121. data/lib/sqreen/rules/devise_auth_track_cb.rb +2 -0
  122. data/lib/sqreen/rules/devise_signup_track_cb.rb +2 -0
  123. data/lib/sqreen/rules/execjs_cb.rb +2 -0
  124. data/lib/sqreen/rules/headers_insert_cb.rb +7 -0
  125. data/lib/sqreen/rules/matcher_rule.rb +2 -0
  126. data/lib/sqreen/rules/not_found_cb.rb +7 -0
  127. data/lib/sqreen/rules/rails_parameters_cb.rb +2 -0
  128. data/lib/sqreen/rules/record_request_context.rb +2 -0
  129. data/lib/sqreen/rules/regexp_rule_cb.rb +2 -0
  130. data/lib/sqreen/rules/rule_cb.rb +2 -0
  131. data/lib/sqreen/rules/run_req_start_actions.rb +3 -1
  132. data/lib/sqreen/rules/run_user_actions.rb +3 -1
  133. data/lib/sqreen/rules/shell_env_cb.rb +2 -0
  134. data/lib/sqreen/rules/signup_track_cb.rb +2 -0
  135. data/lib/sqreen/rules/update_request_context.rb +2 -0
  136. data/lib/sqreen/rules/url_matches_cb.rb +2 -0
  137. data/lib/sqreen/rules/user_agent_matches_cb.rb +2 -0
  138. data/lib/sqreen/rules/waf_cb.rb +28 -5
  139. data/lib/sqreen/rules/xss_cb.rb +2 -0
  140. data/lib/sqreen/run_when_called_cb.rb +2 -0
  141. data/lib/sqreen/runner.rb +25 -7
  142. data/lib/sqreen/runtime_infos.rb +2 -0
  143. data/lib/sqreen/safe_json.rb +2 -0
  144. data/lib/sqreen/sdk.rb +4 -0
  145. data/lib/sqreen/sensitive_data_redactor.rb +2 -0
  146. data/lib/sqreen/serializer.rb +2 -0
  147. data/lib/sqreen/session.rb +2 -0
  148. data/lib/sqreen/shared_storage.rb +2 -0
  149. data/lib/sqreen/shared_storage23.rb +2 -0
  150. data/lib/sqreen/shrink_wrap.rb +16 -0
  151. data/lib/sqreen/signature_verifier.rb +2 -0
  152. data/lib/sqreen/sinatra_middleware.rb +2 -0
  153. data/lib/sqreen/sqreen_signed_verifier.rb +2 -0
  154. data/lib/sqreen/token_invalid_exception.rb +2 -0
  155. data/lib/sqreen/token_not_found_exception.rb +2 -0
  156. data/lib/sqreen/trie.rb +2 -0
  157. data/lib/sqreen/unauthorized.rb +2 -0
  158. data/lib/sqreen/util.rb +5 -0
  159. data/lib/sqreen/util/capped_array.rb +2 -0
  160. data/lib/sqreen/util/capped_hash.rb +2 -0
  161. data/lib/sqreen/util/capped_string.rb +2 -0
  162. data/lib/sqreen/util/capper.rb +2 -0
  163. data/lib/sqreen/version.rb +3 -1
  164. data/lib/sqreen/waf_error.rb +2 -0
  165. data/lib/sqreen/weave.rb +12 -0
  166. data/lib/sqreen/weave/hardcoded.rb +19 -0
  167. data/lib/sqreen/weave/instrumentor.rb +48 -0
  168. data/lib/sqreen/weave/legacy.rb +12 -0
  169. data/lib/sqreen/weave/legacy/instrumentation.rb +406 -0
  170. data/lib/sqreen/web_server.rb +2 -0
  171. data/lib/sqreen/web_server/generic.rb +2 -0
  172. data/lib/sqreen/web_server/passenger.rb +2 -0
  173. data/lib/sqreen/web_server/puma.rb +2 -0
  174. data/lib/sqreen/web_server/rainbows.rb +2 -0
  175. data/lib/sqreen/web_server/thin.rb +2 -0
  176. data/lib/sqreen/web_server/unicorn.rb +2 -0
  177. data/lib/sqreen/web_server/webrick.rb +2 -0
  178. data/lib/sqreen/worker.rb +2 -0
  179. metadata +28 -9
  180. data/lib/sqreen/dependency/hook.rb +0 -102
@@ -1,3 +1,5 @@
1
+ # typed: false
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -1,3 +1,5 @@
1
+ # typed: false
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -1,3 +1,5 @@
1
+ # typed: true
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -1,3 +1,5 @@
1
+ # typed: true
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -19,7 +21,8 @@ module Sqreen
19
21
  next unless seen.add?(val.object_id)
20
22
  case val
21
23
  when Hash
22
- keys.concat(val.keys)
24
+ # convert symbols are converted to strings (ARB-60)
25
+ keys.concat(val.keys.map { |x| sym_to_s(x) })
23
26
  look_into.concat(val.values)
24
27
  when Array
25
28
  look_into.concat(val)
@@ -75,6 +78,10 @@ module Sqreen
75
78
 
76
79
  private
77
80
 
81
+ def sym_to_s(value)
82
+ value.is_a?(Symbol) ? value.to_s : value
83
+ end
84
+
78
85
  def descend(value, max_iter = 1000)
79
86
  seen = Set.new
80
87
  look_into = [value]
@@ -1,3 +1,5 @@
1
+ # typed: false
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -1,3 +1,5 @@
1
+ # typed: true
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -1,3 +1,5 @@
1
+ # typed: true
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -1,3 +1,5 @@
1
+ # typed: ignore
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -1,3 +1,5 @@
1
+ # typed: false
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -1,3 +1,5 @@
1
+ # typed: false
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -1,3 +1,5 @@
1
+ # typed: ignore
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -36,6 +38,10 @@ module Sqreen
36
38
  :default => false, :convert => :to_bool },
37
39
  { :env => :SQREEN_LIBSQREEN, :name => :libsqreen,
38
40
  :default => true, :convert => :to_bool },
41
+ { :env => :SQREEN_WEAVE, :name => :weave,
42
+ :default => false, :convert => :to_bool },
43
+ { :env => :SQREEN_WEAVE_STRATEGY, :name => :weave_strategy,
44
+ :default => :chain, :convert => :to_sym },
39
45
  { :env => :SQREEN_URL, :name => :url,
40
46
  :default => 'https://back.sqreen.io' },
41
47
  { :env => :SQREEN_TOKEN, :name => :token,
@@ -83,6 +89,10 @@ module Sqreen
83
89
  str.to_i
84
90
  end
85
91
 
92
+ def self.to_sym(value)
93
+ value.to_sym
94
+ end
95
+
86
96
  # Class to access configurations variables
87
97
  # This try to load environment by different ways.
88
98
  # 1. By file:
@@ -206,5 +216,9 @@ module Sqreen
206
216
  def to_int(value)
207
217
  Sqreen::to_int(value)
208
218
  end
219
+
220
+ def to_sym(value)
221
+ Sqreen::to_sym(value)
222
+ end
209
223
  end
210
224
  end
@@ -1,3 +1,5 @@
1
+ # typed: true
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -1,3 +1,5 @@
1
+ # typed: true
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -1,3 +1,5 @@
1
+ # typed: false
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -1,3 +1,5 @@
1
+ # typed: strong
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -1,3 +1,5 @@
1
+ # typed: true
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -1,3 +1,5 @@
1
+ # typed: true
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -1,3 +1,5 @@
1
+ # typed: true
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -12,7 +14,7 @@ module Sqreen
12
14
  def self.resolve_const(name)
13
15
  raise ArgumentError if name.nil? || name.empty?
14
16
 
15
- name.to_s.split('::').inject(Object) { |a, e| a.const_get(e) }
17
+ name.to_s.split('::').inject(Object) { |a, e| a.const_get(e, false) }
16
18
  end
17
19
  end
18
20
  end
@@ -1,7 +1,9 @@
1
+ # typed: ignore
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
4
- require 'sqreen/dependency/hook'
6
+ require 'sqreen/graft/hook'
5
7
  require 'sqreen/dependency/rails'
6
8
  require 'sqreen/dependency/sinatra'
7
9
  require 'sqreen/dependency/rack'
@@ -32,28 +34,34 @@ module Sqreen
32
34
  Sqreen::Dependency::Rails.insert_sqreen_middlewares
33
35
  end if Sqreen::Dependency::Rails.required?
34
36
 
35
- Sqreen::Dependency::Hook.add('Rack::Builder#to_app') do
37
+ Sqreen::Graft::Hook.add('Rack::Builder#to_app') do
36
38
  after do
37
39
  Sqreen::Dependency::Rails.inspect_middlewares
38
40
  end
39
41
  end if Sqreen::Dependency::Rails.required?
40
42
 
41
- Sqreen::Dependency::Hook.add('Sinatra::Base.setup_middleware') do
42
- after do |_, _, _, args|
43
+ Sqreen::Graft::Hook.add('Sinatra::Base.setup_middleware') do
44
+ after do |call|
45
+ args = call.args
46
+
43
47
  Sqreen::Dependency::Sinatra.insert_sqreen_middlewares(args.first)
44
48
  end
45
49
  end.install if Sqreen::Dependency::Sinatra.required?
46
50
 
47
- Sqreen::Dependency::Hook.add('Rack::Builder#to_app') do
48
- after do |_, builder|
51
+ Sqreen::Graft::Hook.add('Rack::Builder#to_app') do
52
+ after do |call|
53
+ builder = call.instance
54
+
49
55
  Sqreen::Dependency::Sinatra.inspect_middlewares(builder)
50
56
  end
51
57
  end if Sqreen::Dependency::Sinatra.required?
52
58
 
53
59
  # ensure startup of thread in request handling processes
54
60
 
55
- Sqreen::Dependency::Hook.add('Rack::Builder#to_app') do
56
- after do |callback, *|
61
+ Sqreen::Graft::Hook.add('Rack::Builder#to_app') do
62
+ after do |call|
63
+ callback = call.callback
64
+
57
65
  Sqreen.log.debug "[#{Process.pid}] Start mode #{Sqreen::Dependency::Detector.start_mode}"
58
66
  if Sqreen::Dependency::Detector.start_mode == :rails || Sqreen::Dependency::Detector.start_mode == :rackup
59
67
 
@@ -61,7 +69,7 @@ module Sqreen
61
69
  Sqreen::Dependency::Rack.on_run(handler) do
62
70
  case handler.name
63
71
  when 'Rack::Handler::Puma'
64
- Sqreen::Dependency::Hook.add('Puma::Launcher#run') do
72
+ Sqreen::Graft::Hook.add('Puma::Launcher#run') do
65
73
  before do
66
74
  # HACK: Puma master? hack falls apart when not preloading
67
75
  # it would think master is not, triggering startup
@@ -73,12 +81,12 @@ module Sqreen
73
81
  end
74
82
  end
75
83
  end
76
- Sqreen::Dependency::Hook['Puma::Launcher#run'].install
84
+ Sqreen::Graft::Hook['Puma::Launcher#run'].install
77
85
  when 'Rack::Handler::PhusionPassenger'
78
86
  # noop, passenger will start his own separate process
79
87
  Sqreen.log.debug "[#{Process.pid}] Passenger will start in standalone process"
80
88
  when 'Rack::Handler::Unicorn' # unicorn-rails
81
- Sqreen::Dependency::Hook.add('Unicorn::HttpServer.new') do
89
+ Sqreen::Graft::Hook.add('Unicorn::HttpServer.new') do
82
90
  before do
83
91
  # BUG: detects single process...
84
92
  end
@@ -97,12 +105,12 @@ module Sqreen
97
105
  end
98
106
  end
99
107
 
100
- Sqreen::Dependency::Hook['Rack::Builder#to_app'].install
108
+ Sqreen::Graft::Hook['Rack::Builder#to_app'].install
101
109
 
102
- # Sqreen::Dependency::Hook.add('Rails::Server#start') do
110
+ # Sqreen::Graft::Hook.add('Rails::Server#start') do
103
111
  # before { }
104
112
  # end
105
- # Sqreen::Dependency::Hook['Rails::Server#start'].install
113
+ # Sqreen::Graft::Hook['Rails::Server#start'].install
106
114
  # /!\ double instrument Rails < Rack => Rails.start_with -> Rails.start_without -> super -> Rack.start_with -> Rails.start_without
107
115
  end
108
116
  end
@@ -1,6 +1,10 @@
1
+ # typed: ignore
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
6
+ require 'sqreen/dependency'
7
+
4
8
  module Sqreen
5
9
  module Dependency
6
10
  module LibSqreen
@@ -1,3 +1,5 @@
1
+ # typed: ignore
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -1,3 +1,5 @@
1
+ # typed: ignore
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -7,23 +9,26 @@ module Sqreen
7
9
  module_function
8
10
 
9
11
  def find_handler(&block)
10
- Sqreen::Dependency::Hook.add('Rack::Server#server') do
11
- after do |callback, _, server, _|
12
+ Sqreen::Graft::Hook.add('Rack::Server#server') do
13
+ after do |call|
14
+ callback = call.callback
15
+ server = call.returned
16
+
12
17
  block.call(server)
13
18
  callback.disable # do this once, :server is a lazy init accessor
14
19
  end
15
20
  end
16
- Sqreen::Dependency::Hook['Rack::Server#server'].install
21
+ Sqreen::Graft::Hook['Rack::Server#server'].install
17
22
  end
18
23
 
19
24
  def on_run(handler, &block)
20
25
  Sqreen.log.debug "[#{Process.pid}] #{handler.inspect}"
21
26
  hookpoint_name = "#{handler.name}.run"
22
27
 
23
- Sqreen::Dependency::Hook.add(hookpoint_name) do
28
+ Sqreen::Graft::Hook.add(hookpoint_name) do
24
29
  before { block.call(handler) }
25
30
  end
26
- Sqreen::Dependency::Hook[hookpoint_name].install
31
+ Sqreen::Graft::Hook[hookpoint_name].install
27
32
  end
28
33
 
29
34
  def rackup?
@@ -1,6 +1,9 @@
1
+ # typed: ignore
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
6
+ require 'sqreen/shrink_wrap'
4
7
  require 'sqreen/middleware'
5
8
  require 'sqreen/error_handling_middleware'
6
9
  require 'sqreen/rails_middleware'
@@ -27,6 +30,7 @@ module Sqreen
27
30
  def insert_sqreen_middlewares
28
31
  Sqreen.log.debug { 'Inserting Sqreen middlewares for Rails' }
29
32
  app = ::Rails.application
33
+ app.middleware.insert(0, Sqreen::ShrinkWrap)
30
34
  app.middleware.insert_after(::Rack::Runtime, Sqreen::Middleware)
31
35
  app.middleware.insert_after(::ActionDispatch::DebugExceptions, Sqreen::RailsMiddleware)
32
36
  app.middleware.insert_after(::ActionDispatch::DebugExceptions, Sqreen::ErrorHandlingMiddleware)
@@ -1,3 +1,5 @@
1
+ # typed: ignore
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -1,6 +1,9 @@
1
+ # typed: ignore
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
6
+ require 'sqreen/shrink_wrap'
4
7
  require 'sqreen/middleware'
5
8
  require 'sqreen/error_handling_middleware'
6
9
  require 'sqreen/sinatra_middleware'
@@ -33,7 +36,7 @@ module Sqreen
33
36
  end
34
37
  end
35
38
 
36
- insert_middleware(builder, Sqreen::Middleware, args, block) do |p, u|
39
+ insert_middleware(builder, Sqreen::ShrinkWrap, args, block) do |p, u|
37
40
  if (i = middlewares(builder).index(::Sinatra::ExtendedRack))
38
41
  u.insert(i, p)
39
42
  else
@@ -41,6 +44,14 @@ module Sqreen
41
44
  end
42
45
  end
43
46
 
47
+ insert_middleware(builder, Sqreen::Middleware, args, block) do |p, u|
48
+ if (i = middlewares(builder).index(::Sinatra::ExtendedRack))
49
+ u.insert(i, p)
50
+ else
51
+ u.insert(1, p)
52
+ end
53
+ end
54
+
44
55
  insert_middleware(builder, Sqreen::SinatraMiddleware, args, block) do |p, u|
45
56
  if ::Sqreen::Dependency.const_exist?('Rack::PostBodyContentTypeParser') && (i = middlewares(builder).index(::Rack::PostBodyContentTypeParser))
46
57
  u.insert(i + 1, p)
@@ -1,3 +1,5 @@
1
+ # typed: true
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -1,3 +1,5 @@
1
+ # typed: false
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -1,3 +1,5 @@
1
+ # typed: true
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -1,3 +1,5 @@
1
+ # typed: true
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -1,3 +1,5 @@
1
+ # typed: true
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -1,3 +1,5 @@
1
+ # typed: false
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -1,3 +1,5 @@
1
+ # typed: false
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -1,3 +1,5 @@
1
+ # typed: true
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5
 
@@ -1,3 +1,5 @@
1
+ # typed: true
2
+
1
3
  # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
4
  # Please refer to our terms for more information: https://www.sqreen.com/terms.html
3
5