contrast-agent 3.13.2 → 3.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (211) hide show
  1. checksums.yaml +4 -4
  2. data/exe/contrast_service +1 -7
  3. data/ext/cs__assess_active_record_named/cs__active_record_named.c +8 -7
  4. data/ext/cs__assess_array/cs__assess_array.c +6 -5
  5. data/ext/cs__assess_basic_object/cs__assess_basic_object.c +5 -5
  6. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +2 -1
  7. data/ext/cs__assess_hash/cs__assess_hash.c +18 -17
  8. data/ext/cs__assess_hash/cs__assess_hash.h +2 -1
  9. data/ext/cs__assess_kernel/cs__assess_kernel.c +7 -8
  10. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +4 -5
  11. data/ext/cs__assess_module/cs__assess_module.c +6 -6
  12. data/ext/cs__assess_regexp/cs__assess_regexp.c +4 -4
  13. data/ext/cs__assess_string/cs__assess_string.c +20 -4
  14. data/ext/cs__assess_string/cs__assess_string.h +4 -1
  15. data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +4 -2
  16. data/ext/cs__assess_yield_track/cs__assess_yield_track.c +2 -2
  17. data/ext/cs__common/cs__common.c +44 -37
  18. data/ext/cs__common/cs__common.h +15 -20
  19. data/ext/cs__contrast_patch/cs__contrast_patch.c +27 -25
  20. data/ext/cs__contrast_patch/cs__contrast_patch.h +5 -7
  21. data/ext/cs__protect_kernel/cs__protect_kernel.c +11 -12
  22. data/ext/cs__protect_kernel/cs__protect_kernel.h +2 -2
  23. data/lib/contrast-agent.rb +1 -1
  24. data/lib/contrast.rb +13 -23
  25. data/lib/contrast/agent.rb +39 -39
  26. data/lib/contrast/agent/assess.rb +11 -12
  27. data/lib/contrast/agent/assess/contrast_event.rb +11 -9
  28. data/lib/contrast/agent/assess/events/event_factory.rb +2 -2
  29. data/lib/contrast/agent/assess/events/source_event.rb +2 -2
  30. data/lib/contrast/agent/assess/finalizers/finalize.rb +21 -0
  31. data/lib/contrast/agent/assess/finalizers/freeze.rb +13 -0
  32. data/lib/contrast/agent/assess/finalizers/hash.rb +53 -0
  33. data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +1 -1
  34. data/lib/contrast/agent/assess/policy/patcher.rb +5 -5
  35. data/lib/contrast/agent/assess/policy/policy.rb +9 -9
  36. data/lib/contrast/agent/assess/policy/policy_node.rb +2 -2
  37. data/lib/contrast/agent/assess/policy/policy_scanner.rb +3 -3
  38. data/lib/contrast/agent/assess/policy/preshift.rb +15 -5
  39. data/lib/contrast/agent/assess/policy/propagation_method.rb +25 -22
  40. data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -2
  41. data/lib/contrast/agent/assess/policy/propagator.rb +18 -18
  42. data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
  43. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +1 -1
  44. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +3 -2
  45. data/lib/contrast/agent/assess/policy/propagator/prepend.rb +5 -0
  46. data/lib/contrast/agent/assess/policy/propagator/split.rb +4 -4
  47. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +5 -4
  48. data/lib/contrast/agent/assess/policy/rewriter_patch.rb +5 -5
  49. data/lib/contrast/agent/assess/policy/source_method.rb +5 -14
  50. data/lib/contrast/agent/assess/policy/source_validation/cross_site_validator.rb +1 -1
  51. data/lib/contrast/agent/assess/policy/source_validation/source_validation.rb +1 -1
  52. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +1 -1
  53. data/lib/contrast/agent/assess/policy/trigger_method.rb +5 -5
  54. data/lib/contrast/agent/assess/policy/trigger_node.rb +3 -3
  55. data/lib/contrast/agent/assess/policy/trigger_validation/trigger_validation.rb +2 -2
  56. data/lib/contrast/agent/assess/properties.rb +13 -5
  57. data/lib/contrast/agent/assess/property/evented.rb +2 -2
  58. data/lib/contrast/agent/assess/property/tagged.rb +4 -4
  59. data/lib/contrast/agent/assess/rule.rb +2 -2
  60. data/lib/contrast/agent/assess/rule/base.rb +3 -4
  61. data/lib/contrast/agent/assess/rule/provider.rb +3 -3
  62. data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +1 -1
  63. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +2 -2
  64. data/lib/contrast/agent/at_exit_hook.rb +1 -1
  65. data/lib/contrast/agent/class_reopener.rb +7 -6
  66. data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +1 -1
  67. data/lib/contrast/agent/deadzone/policy/policy.rb +2 -2
  68. data/lib/contrast/agent/disable_reaction.rb +1 -1
  69. data/lib/contrast/agent/exclusion_matcher.rb +1 -1
  70. data/lib/contrast/agent/inventory/policy/datastores.rb +2 -2
  71. data/lib/contrast/agent/inventory/policy/policy.rb +3 -3
  72. data/lib/contrast/agent/inventory/policy/trigger_node.rb +1 -1
  73. data/lib/contrast/agent/middleware.rb +33 -32
  74. data/lib/contrast/agent/patching/policy/after_load_patch.rb +4 -4
  75. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +6 -5
  76. data/lib/contrast/agent/patching/policy/module_policy.rb +1 -1
  77. data/lib/contrast/agent/patching/policy/patch.rb +15 -15
  78. data/lib/contrast/agent/patching/policy/patcher.rb +30 -22
  79. data/lib/contrast/agent/patching/policy/policy.rb +6 -6
  80. data/lib/contrast/agent/patching/policy/policy_node.rb +1 -1
  81. data/lib/contrast/agent/patching/policy/trigger_node.rb +2 -2
  82. data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +3 -3
  83. data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +2 -2
  84. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -2
  85. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +3 -3
  86. data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +2 -2
  87. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +3 -3
  88. data/lib/contrast/agent/protect/policy/policy.rb +8 -8
  89. data/lib/contrast/agent/protect/policy/rule_applicator.rb +1 -1
  90. data/lib/contrast/agent/protect/policy/trigger_node.rb +1 -1
  91. data/lib/contrast/agent/protect/rule.rb +18 -18
  92. data/lib/contrast/agent/protect/rule/base.rb +4 -3
  93. data/lib/contrast/agent/protect/rule/base_service.rb +1 -1
  94. data/lib/contrast/agent/protect/rule/cmd_injection.rb +5 -5
  95. data/lib/contrast/agent/protect/rule/deserialization.rb +1 -1
  96. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +1 -1
  97. data/lib/contrast/agent/protect/rule/no_sqli.rb +1 -1
  98. data/lib/contrast/agent/protect/rule/path_traversal.rb +4 -5
  99. data/lib/contrast/agent/protect/rule/sqli.rb +2 -2
  100. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +1 -1
  101. data/lib/contrast/agent/protect/rule/xss.rb +1 -1
  102. data/lib/contrast/agent/protect/rule/xxe.rb +3 -5
  103. data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +2 -2
  104. data/lib/contrast/agent/railtie.rb +1 -1
  105. data/lib/contrast/agent/reaction_processor.rb +2 -2
  106. data/lib/contrast/agent/request.rb +11 -9
  107. data/lib/contrast/agent/request_context.rb +10 -6
  108. data/lib/contrast/agent/response.rb +6 -6
  109. data/lib/contrast/agent/rewriter.rb +5 -6
  110. data/lib/contrast/agent/service_heartbeat.rb +2 -2
  111. data/lib/contrast/agent/static_analysis.rb +3 -3
  112. data/lib/contrast/agent/thread.rb +1 -1
  113. data/lib/contrast/agent/thread_watcher.rb +2 -2
  114. data/lib/contrast/agent/tracepoint_hook.rb +1 -1
  115. data/lib/contrast/agent/version.rb +1 -1
  116. data/lib/contrast/api.rb +4 -4
  117. data/lib/contrast/api/communication.rb +9 -9
  118. data/lib/contrast/api/communication/messaging_queue.rb +2 -2
  119. data/lib/contrast/api/communication/response_processor.rb +1 -1
  120. data/lib/contrast/api/communication/socket_client.rb +5 -5
  121. data/lib/contrast/api/communication/speedracer.rb +1 -1
  122. data/lib/contrast/api/communication/tcp_socket.rb +1 -1
  123. data/lib/contrast/api/communication/unix_socket.rb +1 -1
  124. data/lib/contrast/api/decorators.rb +14 -14
  125. data/lib/contrast/api/decorators/address.rb +7 -6
  126. data/lib/contrast/api/decorators/application_settings.rb +3 -2
  127. data/lib/contrast/api/decorators/application_update.rb +5 -4
  128. data/lib/contrast/api/decorators/http_request.rb +13 -12
  129. data/lib/contrast/api/decorators/input_analysis.rb +3 -2
  130. data/lib/contrast/api/decorators/message.rb +3 -2
  131. data/lib/contrast/api/decorators/rasp_rule_sample.rb +2 -1
  132. data/lib/contrast/api/decorators/route_coverage.rb +3 -2
  133. data/lib/contrast/api/decorators/server_features.rb +3 -2
  134. data/lib/contrast/api/decorators/trace_event.rb +3 -2
  135. data/lib/contrast/api/decorators/trace_event_object.rb +6 -5
  136. data/lib/contrast/api/decorators/trace_event_signature.rb +5 -4
  137. data/lib/contrast/api/decorators/trace_taint_range.rb +4 -3
  138. data/lib/contrast/api/decorators/user_input.rb +4 -4
  139. data/lib/contrast/common_agent_configuration.rb +2 -2
  140. data/lib/contrast/components/agent.rb +2 -2
  141. data/lib/contrast/components/app_context.rb +1 -1
  142. data/lib/contrast/components/config.rb +4 -4
  143. data/lib/contrast/components/contrast_service.rb +1 -1
  144. data/lib/contrast/components/interface.rb +15 -15
  145. data/lib/contrast/components/logger.rb +1 -1
  146. data/lib/contrast/components/scope.rb +3 -3
  147. data/lib/contrast/config.rb +18 -18
  148. data/lib/contrast/config/base_configuration.rb +2 -2
  149. data/lib/contrast/config/protect_rule_configuration.rb +1 -1
  150. data/lib/contrast/configuration.rb +5 -5
  151. data/lib/contrast/extension/assess.rb +22 -21
  152. data/lib/contrast/extension/assess/array.rb +4 -4
  153. data/lib/contrast/extension/assess/assess_extension.rb +27 -29
  154. data/lib/contrast/extension/assess/eval_trigger.rb +3 -3
  155. data/lib/contrast/extension/assess/exec_trigger.rb +1 -1
  156. data/lib/contrast/extension/assess/fiber.rb +3 -3
  157. data/lib/contrast/extension/assess/hash.rb +5 -3
  158. data/lib/contrast/extension/assess/kernel.rb +7 -6
  159. data/lib/contrast/extension/assess/marshal.rb +62 -0
  160. data/lib/contrast/extension/assess/regexp.rb +3 -3
  161. data/lib/contrast/extension/assess/string.rb +5 -5
  162. data/lib/contrast/extension/inventory.rb +4 -4
  163. data/lib/contrast/extension/kernel.rb +1 -1
  164. data/lib/contrast/extension/module.rb +1 -1
  165. data/lib/contrast/extension/protect.rb +3 -3
  166. data/lib/contrast/extension/protect/kernel.rb +2 -2
  167. data/lib/contrast/extension/protect/psych.rb +2 -2
  168. data/lib/contrast/framework/manager.rb +7 -8
  169. data/lib/contrast/framework/rack/patch/session_cookie.rb +1 -1
  170. data/lib/contrast/framework/rack/patch/support.rb +1 -1
  171. data/lib/contrast/framework/rack/support.rb +2 -2
  172. data/lib/contrast/framework/rails/patch/assess_configuration.rb +2 -2
  173. data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +1 -1
  174. data/lib/contrast/framework/rails/patch/support.rb +3 -3
  175. data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +2 -2
  176. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +2 -2
  177. data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +2 -2
  178. data/lib/contrast/framework/rails/support.rb +62 -14
  179. data/lib/contrast/framework/sinatra/patch/base.rb +1 -1
  180. data/lib/contrast/framework/sinatra/patch/support.rb +1 -1
  181. data/lib/contrast/framework/sinatra/support.rb +2 -2
  182. data/lib/contrast/funchook/funchook.rb +1 -1
  183. data/lib/contrast/logger/application.rb +2 -2
  184. data/lib/contrast/logger/format.rb +22 -9
  185. data/lib/contrast/logger/log.rb +10 -8
  186. data/lib/contrast/logger/request.rb +30 -0
  187. data/lib/contrast/tasks/config.rb +1 -1
  188. data/lib/contrast/tasks/service.rb +2 -2
  189. data/lib/contrast/utils/assess/sampling_util.rb +2 -2
  190. data/lib/contrast/utils/assess/tracking_util.rb +1 -1
  191. data/lib/contrast/utils/boolean_util.rb +1 -1
  192. data/lib/contrast/utils/class_util.rb +2 -2
  193. data/lib/contrast/utils/freeze_util.rb +1 -1
  194. data/lib/contrast/utils/gemfile_reader.rb +5 -5
  195. data/lib/contrast/utils/hash_digest.rb +2 -1
  196. data/lib/contrast/utils/heap_dump_util.rb +2 -2
  197. data/lib/contrast/utils/invalid_configuration_util.rb +1 -1
  198. data/lib/contrast/utils/inventory_util.rb +4 -4
  199. data/lib/contrast/utils/io_util.rb +1 -1
  200. data/lib/contrast/utils/os.rb +1 -1
  201. data/lib/contrast/utils/ruby_ast_rewriter.rb +1 -1
  202. data/lib/contrast/utils/sha256_builder.rb +2 -2
  203. data/lib/contrast/utils/stack_trace_utils.rb +2 -2
  204. data/lib/contrast/utils/string_utils.rb +1 -1
  205. data/ruby-agent.gemspec +5 -5
  206. data/service_executables/VERSION +1 -1
  207. data/service_executables/linux/contrast-service +0 -0
  208. data/service_executables/mac/contrast-service +0 -0
  209. metadata +22 -19
  210. data/lib/contrast/agent/assess/insulator.rb +0 -49
  211. data/lib/contrast/agent/require_state.rb +0 -61
@@ -1,8 +1,8 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/agent/assess/policy/propagation_node'
5
- cs__scoped_require 'contrast/components/interface'
4
+ require 'contrast/agent/assess/policy/propagation_node'
5
+ require 'contrast/components/interface'
6
6
 
7
7
  module Contrast
8
8
  module Extension
@@ -70,7 +70,7 @@ module Contrast
70
70
 
71
71
  def instrument_regexp_track
72
72
  @_instrument_regexp_track ||= begin
73
- cs__scoped_require 'cs__assess_regexp/cs__assess_regexp'
73
+ require 'cs__assess_regexp/cs__assess_regexp'
74
74
  true
75
75
  end
76
76
  rescue StandardError, LoadError => e
@@ -1,9 +1,9 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/agent/assess/policy/propagation_node'
5
- cs__scoped_require 'contrast/components/interface'
6
- cs__scoped_require 'contrast/extension/assess/assess_extension'
4
+ require 'contrast/agent/assess/policy/propagation_node'
5
+ require 'contrast/components/interface'
6
+ require 'contrast/extension/assess/assess_extension'
7
7
 
8
8
  # This patch installs our extension as early as possible. The alternative is to
9
9
  # litter our code with Contrast::Utils::DuckUtils.trackable? checks.
@@ -54,7 +54,7 @@ module Contrast
54
54
 
55
55
  def instrument_string
56
56
  @_instrument_string ||= begin
57
- cs__scoped_require 'cs__assess_string/cs__assess_string'
57
+ require 'cs__assess_string/cs__assess_string'
58
58
  true
59
59
  end
60
60
  rescue StandardError, LoadError => e
@@ -66,7 +66,7 @@ module Contrast
66
66
  if @_instrument_string_interpolation.nil?
67
67
  @_instrument_string_interpolation = begin
68
68
  if AGENT.patch_interpolation? && Funchook.available?
69
- cs__scoped_require 'cs__assess_string_interpolation26/cs__assess_string_interpolation26'
69
+ require 'cs__assess_string_interpolation26/cs__assess_string_interpolation26'
70
70
  end
71
71
  true
72
72
  rescue StandardError, LoadError => e
@@ -11,11 +11,11 @@ module Contrast
11
11
  # relevant given the move to C based patching and the lessons learned
12
12
  # therein.
13
13
  module Inventory
14
- cs__scoped_require 'contrast/security_exception'
14
+ require 'contrast/security_exception'
15
15
  # patching
16
- cs__scoped_require 'contrast/agent/inventory/policy/trigger_node'
17
- cs__scoped_require 'contrast/agent/inventory/policy/policy'
18
- cs__scoped_require 'contrast/agent/patching/policy/patcher'
16
+ require 'contrast/agent/inventory/policy/trigger_node'
17
+ require 'contrast/agent/inventory/policy/policy'
18
+ require 'contrast/agent/patching/policy/patcher'
19
19
  end
20
20
  end
21
21
  end
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/components/scope'
4
+ require 'contrast/components/scope'
5
5
 
6
6
  # This is a reasonable place for the Kernel#catch hook to live.
7
7
  # No current plans for component re-design, but if we had some kind of
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/utils/object_share'
4
+ require 'contrast/utils/object_share'
5
5
 
6
6
  # Some developers override various methods on Module, which can often involve
7
7
  # changing expected method parity/behavior which in turn prevents us from being
@@ -11,10 +11,10 @@ module Contrast
11
11
  # relevant given the move to C based patching and the lessons learned
12
12
  # therein.
13
13
  module Protect
14
- cs__scoped_require 'contrast/security_exception'
14
+ require 'contrast/security_exception'
15
15
  # patching
16
- cs__scoped_require 'contrast/agent/protect/policy/trigger_node'
17
- cs__scoped_require 'contrast/agent/protect/policy/policy'
16
+ require 'contrast/agent/protect/policy/trigger_node'
17
+ require 'contrast/agent/protect/policy/policy'
18
18
  end
19
19
  end
20
20
  end
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/components/interface'
4
+ require 'contrast/components/interface'
5
5
 
6
6
  module Contrast
7
7
  module Extension
@@ -30,7 +30,7 @@ module Contrast
30
30
 
31
31
  def instrument
32
32
  @_instrument ||= begin
33
- cs__scoped_require 'cs__protect_kernel/cs__protect_kernel'
33
+ require 'cs__protect_kernel/cs__protect_kernel'
34
34
  true
35
35
  end
36
36
  rescue StandardError, LoadError => e
@@ -2,6 +2,6 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  if defined?(Psych)
5
- cs__scoped_require 'contrast/agent/protect/policy/applies_deserialization_rule'
6
- cs__scoped_require 'cs__patched_psych/cs__patched_psych'
5
+ require 'contrast/agent/protect/policy/applies_deserialization_rule'
6
+ require 'cs__patched_psych/cs__patched_psych'
7
7
  end
@@ -1,12 +1,12 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/framework/platform_version'
5
- cs__scoped_require 'contrast/framework/rack/support'
6
- cs__scoped_require 'contrast/framework/rails/support'
7
- cs__scoped_require 'contrast/framework/sinatra/support'
8
- cs__scoped_require 'contrast/components/interface'
9
- cs__scoped_require 'contrast/utils/class_util'
4
+ require 'contrast/framework/platform_version'
5
+ require 'contrast/framework/rack/support'
6
+ require 'contrast/framework/rails/support'
7
+ require 'contrast/framework/sinatra/support'
8
+ require 'contrast/components/interface'
9
+ require 'contrast/utils/class_util'
10
10
 
11
11
  module Contrast
12
12
  module Framework
@@ -128,10 +128,9 @@ module Contrast
128
128
  # @param method_name [Symbol] the method to call on each FrameworkSupport class
129
129
  # @return [Array]
130
130
  def data_for_all_frameworks method_name
131
- data = @_frameworks.flat_map do |framework|
131
+ @_frameworks.flat_map do |framework|
132
132
  framework.send(method_name)
133
133
  end.compact
134
- data
135
134
  end
136
135
 
137
136
  # This returns a single object from the first framework to successfully respond
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/components/interface'
4
+ require 'contrast/components/interface'
5
5
 
6
6
  module Contrast
7
7
  module Framework
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/agent/patching/policy/after_load_patch'
4
+ require 'contrast/agent/patching/policy/after_load_patch'
5
5
 
6
6
  module Contrast
7
7
  module Framework
@@ -1,8 +1,8 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/framework/base_support'
5
- cs__scoped_require 'contrast/framework/rack/patch/support'
4
+ require 'contrast/framework/base_support'
5
+ require 'contrast/framework/rack/patch/support'
6
6
 
7
7
  module Contrast
8
8
  module Framework
@@ -1,8 +1,8 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/components/interface'
5
- cs__scoped_require 'contrast/utils/invalid_configuration_util'
4
+ require 'contrast/components/interface'
5
+ require 'contrast/utils/invalid_configuration_util'
6
6
 
7
7
  module Contrast
8
8
  module Framework
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/framework/rails/patch/assess_configuration'
4
+ require 'contrast/framework/rails/patch/assess_configuration'
5
5
  module Contrast
6
6
  module Framework
7
7
  module Rails
@@ -1,8 +1,8 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/framework/rails/patch/rails_application_configuration'
5
- cs__scoped_require 'contrast/agent/patching/policy/after_load_patch'
4
+ require 'contrast/framework/rails/patch/rails_application_configuration'
5
+ require 'contrast/agent/patching/policy/after_load_patch'
6
6
 
7
7
  module Contrast
8
8
  module Framework
@@ -20,7 +20,7 @@ module Contrast
20
20
  # (i.e., where we normally patch) we will miss the configuration
21
21
  # and will never be able to report session misconfiguration rules.
22
22
  Contrast::Framework::Rails::Patch::RailsApplicationConfiguration.instrument
23
- cs__scoped_require 'contrast/agent/railtie' if ::Rails::VERSION::MAJOR.to_i >= 3
23
+ require 'contrast/agent/railtie' if ::Rails::VERSION::MAJOR.to_i >= 3
24
24
  end
25
25
 
26
26
  # (See BaseSupport#after_load_patches)
@@ -17,9 +17,9 @@ module Contrast
17
17
  @_instrument ||= begin
18
18
  ::ActionController::Railties::Helpers.class_eval do
19
19
  alias_method :cs__patched_helper_inherited, :inherited
20
- def inherited klass
20
+ def inherited klass # rubocop:disable Lint/MissingSuper
21
21
  klass&.instance_variable_set(:@cs__defining_class, true)
22
- cs__patched_helper_inherited(klass)
22
+ cs__patched_helper_inherited(klass) # This calls the original inherited, which should handle super as needed.
23
23
  ensure
24
24
  klass&.instance_variable_set(:@cs__defining_class, false)
25
25
  end
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/components/interface'
4
+ require 'contrast/components/interface'
5
5
 
6
6
  module Contrast
7
7
  module Framework
@@ -58,7 +58,7 @@ module Contrast
58
58
 
59
59
  def instrument
60
60
  @_instrument_named_track ||= begin
61
- cs__scoped_require 'cs__assess_active_record_named/cs__assess_active_record_named'
61
+ require 'cs__assess_active_record_named/cs__assess_active_record_named'
62
62
  true
63
63
  end
64
64
  rescue StandardError, LoadError => e
@@ -16,9 +16,9 @@ module Contrast
16
16
  private
17
17
 
18
18
  alias_method :cs__patched_inherited, :inherited
19
- def inherited klass
19
+ def inherited klass # rubocop:disable Lint/MissingSuper
20
20
  klass&.instance_variable_set(:@cs__defining_class, true)
21
- cs__patched_inherited(klass)
21
+ cs__patched_inherited(klass) # This calls the original inherited, which should handle super as needed.
22
22
  ensure
23
23
  klass&.instance_variable_set(:@cs__defining_class, false)
24
24
  end
@@ -1,10 +1,10 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/api/dtm.pb'
5
- cs__scoped_require 'contrast/framework/base_support'
6
- cs__scoped_require 'contrast/framework/rails/patch/support'
7
- cs__scoped_require 'contrast/utils/string_utils'
4
+ require 'contrast/api/dtm.pb'
5
+ require 'contrast/framework/base_support'
6
+ require 'contrast/framework/rails/patch/support'
7
+ require 'contrast/utils/string_utils'
8
8
 
9
9
  module Contrast
10
10
  module Framework
@@ -42,10 +42,7 @@ module Contrast
42
42
  end
43
43
 
44
44
  def collect_routes
45
- routes = ::Rails.application.routes.routes.map do |route|
46
- Contrast::Api::Dtm::RouteCoverage.from_action_dispatch_journey(route)
47
- end
48
- routes
45
+ find_all_routes(::Rails.application, [])
49
46
  end
50
47
 
51
48
  def current_route request
@@ -59,13 +56,17 @@ module Contrast
59
56
  full_routes = ::Rails.application.routes.router.send(:find_routes, request.rack_request)
60
57
  return if full_routes.empty?
61
58
 
62
- full_route = full_routes[0] # [match_data, path_parameters, route]
63
- return unless full_route
64
-
65
- route = full_route[2] # route w/ highest precedence
66
- return unless route
59
+ full_route = full_routes[0]
67
60
 
68
- Contrast::Api::Dtm::RouteCoverage.from_action_dispatch_journey(route)
61
+ # the route is directly implemented within the application
62
+ if direct_route?(full_route)
63
+ route = full_route[2] # route w/ highest precedence
64
+ Contrast::Api::Dtm::RouteCoverage.from_action_dispatch_journey(route)
65
+ else
66
+ engine_route(full_route, request)
67
+ end
68
+ rescue StandardError => _e
69
+ nil
69
70
  end
70
71
 
71
72
  def retrieve_request env
@@ -79,6 +80,53 @@ module Contrast
79
80
 
80
81
  env[AC_INSTANCE].cs__class.included_modules.include?(::ActionController::Live)
81
82
  end
83
+
84
+ private
85
+
86
+ # route is not mounted within an engine
87
+ def direct_route? full_route
88
+ full_route[2]&.app&.cs__class == ActionDispatch::Routing::RouteSet::Dispatcher ||
89
+ (full_route[2].cs__class == ActionDispatch::Journey::Route && full_route[2]&.app&.cs__class == ActionDispatch::Routing::Mapper::Constraints)
90
+ end
91
+
92
+ def engine_route full_route, request
93
+ engine_route = full_route[2] # supposed route - but actually an Engine mount point
94
+ return unless engine_route
95
+
96
+ engine_mount_name = engine_route.name
97
+ return unless engine_mount_name
98
+
99
+ engine_path_segments = request.rack_request.path_info.split(engine_mount_name)
100
+ return if engine_path_segments.empty?
101
+
102
+ path_within_engine = engine_path_segments[-1]
103
+ return unless path_within_engine
104
+
105
+ engine_router = engine_route.app&.app&.routes&.router
106
+ return unless engine_router
107
+
108
+ # Get all routes regardless of http method
109
+ matching_routes = engine_router.send(:filter_routes, path_within_engine)
110
+ return unless matching_routes
111
+
112
+ # filter for current http method
113
+ reportable_routes = engine_router.send(:match_routes, matching_routes, request.rack_request)
114
+ return if reportable_routes.empty?
115
+
116
+ Contrast::Api::Dtm::RouteCoverage.from_action_dispatch_journey(reportable_routes[0])
117
+ end
118
+
119
+ # Rails engine routes need to be detected by inspecting Engine class route set
120
+ def find_all_routes app, route_list
121
+ app.routes.routes.each do |route|
122
+ if route.cs__respond_to?(:app) && route.app.cs__class == ActionDispatch::Routing::RouteSet::Dispatcher
123
+ route_list << Contrast::Api::Dtm::RouteCoverage.from_action_dispatch_journey(route)
124
+ elsif route.app.app.cs__respond_to?(:routes)
125
+ route_list += find_all_routes(route.app.app, [])
126
+ end
127
+ end
128
+ route_list
129
+ end
82
130
  end
83
131
  end
84
132
  end
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/framework/sinatra/support'
4
+ require 'contrast/framework/sinatra/support'
5
5
 
6
6
  module Contrast
7
7
  module Framework
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/agent/patching/policy/after_load_patch'
4
+ require 'contrast/agent/patching/policy/after_load_patch'
5
5
 
6
6
  module Contrast
7
7
  module Framework
@@ -1,8 +1,8 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/framework/base_support'
5
- cs__scoped_require 'contrast/framework/sinatra/patch/support'
4
+ require 'contrast/framework/base_support'
5
+ require 'contrast/framework/sinatra/patch/support'
6
6
 
7
7
  module Contrast
8
8
  module Framework
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/components/interface'
4
+ require 'contrast/components/interface'
5
5
  # This module is used to find funchook library and determine availability
6
6
  module Funchook
7
7
  include Contrast::Components::Interface
@@ -1,11 +1,11 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/components/interface'
4
+ require 'contrast/components/interface'
5
5
 
6
6
  module Contrast
7
7
  module Logger
8
- # # Our decorator for the Ougai logger allowing for the logging of the
8
+ # Our decorator for the Ougai logger allowing for the logging of the
9
9
  # application environment, used to provide context during troubleshooting.
10
10
  module Application
11
11
  include Contrast::Components::Interface
@@ -1,8 +1,9 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'ougai'
5
- cs__scoped_require 'contrast/utils/thread_tracker'
4
+ require 'ougai'
5
+ require 'contrast/utils/object_share'
6
+ require 'contrast/utils/thread_tracker'
6
7
 
7
8
  module Contrast
8
9
  module Logger
@@ -31,21 +32,33 @@ module Contrast
31
32
 
32
33
  private
33
34
 
34
- # The extra values to add to the Bunyan hash. Because this is unique per
35
- # thread, we'll create it once and then store it, rather than create a
36
- # new hash on every log call.
35
+ # The extra values to add to the Bunyan hash.
37
36
  # @return [Hash{Symbol => Object}] the extra data to log
38
- # tid: current thread id
39
37
  def format_hash
40
- hash = LOG_TRACKER.get(:thread_id_hash)
38
+ thread_hash.merge(request_hash)
39
+ end
40
+
41
+ # Because this is unique per thread, we'll create it once and then store
42
+ # it, rather than create a new hash on every log call during the request.
43
+ def thread_hash
44
+ hash = LOG_TRACKER.get(:logging_hash)
41
45
  unless hash
42
46
  hash = {
43
- tid: Thread.current.object_id
47
+ thread_id: Thread.current.object_id
44
48
  }
45
- LOG_TRACKER.set(:thread_id_hash, hash)
49
+ LOG_TRACKER.set(:logging_hash, hash)
46
50
  end
47
51
  hash
48
52
  end
53
+
54
+ NO_REQUEST_HASH = { request_id: -1 }.cs__freeze
55
+ def request_hash
56
+ @request_tracker_defined ||= defined?(Contrast::Agent) &&
57
+ defined?(Contrast::Agent::REQUEST_TRACKER)
58
+ return NO_REQUEST_HASH unless @request_tracker_defined
59
+
60
+ Contrast::Agent::REQUEST_TRACKER&.current&.logging_hash || NO_REQUEST_HASH
61
+ end
49
62
  end
50
63
  end
51
64
  end