contrast-agent 3.13.1 → 4.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (251) 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 +18 -16
  11. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.h +1 -0
  12. data/ext/cs__assess_module/cs__assess_module.c +6 -6
  13. data/ext/cs__assess_regexp/cs__assess_regexp.c +4 -4
  14. data/ext/cs__assess_string/cs__assess_string.c +31 -16
  15. data/ext/cs__assess_string/cs__assess_string.h +6 -1
  16. data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +4 -2
  17. data/ext/cs__assess_yield_track/cs__assess_yield_track.c +2 -2
  18. data/ext/cs__common/cs__common.c +48 -39
  19. data/ext/cs__common/cs__common.h +16 -21
  20. data/ext/cs__contrast_patch/cs__contrast_patch.c +27 -25
  21. data/ext/cs__contrast_patch/cs__contrast_patch.h +5 -7
  22. data/ext/cs__protect_kernel/cs__protect_kernel.c +11 -12
  23. data/ext/cs__protect_kernel/cs__protect_kernel.h +2 -2
  24. data/lib/contrast-agent.rb +1 -1
  25. data/lib/contrast.rb +13 -23
  26. data/lib/contrast/agent.rb +39 -47
  27. data/lib/contrast/agent/assess.rb +12 -12
  28. data/lib/contrast/agent/assess/contrast_event.rb +151 -85
  29. data/lib/contrast/agent/assess/events/event_factory.rb +2 -2
  30. data/lib/contrast/agent/assess/events/source_event.rb +3 -3
  31. data/lib/contrast/agent/assess/finalizers/freeze.rb +15 -0
  32. data/lib/contrast/agent/assess/finalizers/hash.rb +97 -0
  33. data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +11 -4
  34. data/lib/contrast/agent/assess/policy/patcher.rb +6 -6
  35. data/lib/contrast/agent/assess/policy/policy.rb +9 -11
  36. data/lib/contrast/agent/assess/policy/policy_node.rb +17 -12
  37. data/lib/contrast/agent/assess/policy/policy_scanner.rb +21 -5
  38. data/lib/contrast/agent/assess/policy/preshift.rb +13 -7
  39. data/lib/contrast/agent/assess/policy/propagation_method.rb +64 -44
  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/append.rb +8 -5
  43. data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
  44. data/lib/contrast/agent/assess/policy/propagator/center.rb +9 -5
  45. data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
  46. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +6 -4
  47. data/lib/contrast/agent/assess/policy/propagator/insert.rb +7 -4
  48. data/lib/contrast/agent/assess/policy/propagator/keep.rb +4 -1
  49. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +7 -9
  50. data/lib/contrast/agent/assess/policy/propagator/next.rb +7 -5
  51. data/lib/contrast/agent/assess/policy/propagator/prepend.rb +13 -5
  52. data/lib/contrast/agent/assess/policy/propagator/remove.rb +8 -4
  53. data/lib/contrast/agent/assess/policy/propagator/replace.rb +5 -2
  54. data/lib/contrast/agent/assess/policy/propagator/reverse.rb +7 -5
  55. data/lib/contrast/agent/assess/policy/propagator/select.rb +13 -7
  56. data/lib/contrast/agent/assess/policy/propagator/splat.rb +10 -9
  57. data/lib/contrast/agent/assess/policy/propagator/split.rb +27 -22
  58. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +52 -35
  59. data/lib/contrast/agent/assess/policy/propagator/trim.rb +11 -5
  60. data/lib/contrast/agent/assess/policy/rewriter_patch.rb +5 -5
  61. data/lib/contrast/agent/assess/policy/source_method.rb +90 -72
  62. data/lib/contrast/agent/assess/policy/source_validation/cross_site_validator.rb +1 -1
  63. data/lib/contrast/agent/assess/policy/source_validation/source_validation.rb +1 -1
  64. data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +16 -12
  65. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +2 -2
  66. data/lib/contrast/agent/assess/policy/trigger_method.rb +81 -33
  67. data/lib/contrast/agent/assess/policy/trigger_node.rb +41 -46
  68. data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -1
  69. data/lib/contrast/agent/assess/policy/trigger_validation/trigger_validation.rb +2 -2
  70. data/lib/contrast/agent/assess/properties.rb +15 -5
  71. data/lib/contrast/agent/assess/property/evented.rb +7 -20
  72. data/lib/contrast/agent/assess/property/tagged.rb +13 -7
  73. data/lib/contrast/agent/assess/property/updated.rb +131 -0
  74. data/lib/contrast/agent/assess/rule.rb +2 -2
  75. data/lib/contrast/agent/assess/rule/base.rb +3 -4
  76. data/lib/contrast/agent/assess/rule/provider.rb +3 -3
  77. data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +58 -5
  78. data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +24 -9
  79. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +85 -16
  80. data/lib/contrast/agent/assess/tag.rb +1 -1
  81. data/lib/contrast/agent/assess/tracker.rb +66 -0
  82. data/lib/contrast/agent/at_exit_hook.rb +6 -6
  83. data/lib/contrast/agent/class_reopener.rb +14 -11
  84. data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +1 -1
  85. data/lib/contrast/agent/deadzone/policy/policy.rb +2 -2
  86. data/lib/contrast/agent/disable_reaction.rb +1 -1
  87. data/lib/contrast/agent/exclusion_matcher.rb +1 -1
  88. data/lib/contrast/agent/inventory.rb +15 -0
  89. data/lib/contrast/agent/inventory/dependencies.rb +50 -0
  90. data/lib/contrast/agent/inventory/dependency_analysis.rb +37 -0
  91. data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +104 -0
  92. data/lib/contrast/agent/inventory/gemfile_digest_cache.rb +38 -0
  93. data/lib/contrast/agent/inventory/policy/datastores.rb +2 -2
  94. data/lib/contrast/agent/inventory/policy/policy.rb +3 -3
  95. data/lib/contrast/agent/inventory/policy/trigger_node.rb +1 -1
  96. data/lib/contrast/agent/middleware.rb +33 -34
  97. data/lib/contrast/agent/patching/policy/after_load_patch.rb +9 -9
  98. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +23 -22
  99. data/lib/contrast/agent/patching/policy/module_policy.rb +11 -11
  100. data/lib/contrast/agent/patching/policy/patch.rb +15 -15
  101. data/lib/contrast/agent/patching/policy/patcher.rb +43 -44
  102. data/lib/contrast/agent/patching/policy/policy.rb +23 -12
  103. data/lib/contrast/agent/patching/policy/policy_node.rb +1 -1
  104. data/lib/contrast/agent/patching/policy/trigger_node.rb +2 -2
  105. data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +6 -8
  106. data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +2 -2
  107. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -2
  108. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +7 -6
  109. data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +2 -2
  110. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +4 -4
  111. data/lib/contrast/agent/protect/policy/policy.rb +8 -8
  112. data/lib/contrast/agent/protect/policy/rule_applicator.rb +1 -1
  113. data/lib/contrast/agent/protect/policy/trigger_node.rb +1 -1
  114. data/lib/contrast/agent/protect/rule.rb +18 -18
  115. data/lib/contrast/agent/protect/rule/base.rb +4 -3
  116. data/lib/contrast/agent/protect/rule/base_service.rb +1 -1
  117. data/lib/contrast/agent/protect/rule/cmd_injection.rb +5 -5
  118. data/lib/contrast/agent/protect/rule/deserialization.rb +1 -1
  119. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +1 -1
  120. data/lib/contrast/agent/protect/rule/no_sqli.rb +1 -1
  121. data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +1 -0
  122. data/lib/contrast/agent/protect/rule/path_traversal.rb +4 -5
  123. data/lib/contrast/agent/protect/rule/sqli.rb +2 -2
  124. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +1 -1
  125. data/lib/contrast/agent/protect/rule/xss.rb +1 -1
  126. data/lib/contrast/agent/protect/rule/xxe.rb +3 -5
  127. data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +2 -2
  128. data/lib/contrast/agent/railtie.rb +1 -1
  129. data/lib/contrast/agent/reaction_processor.rb +2 -2
  130. data/lib/contrast/agent/request.rb +45 -43
  131. data/lib/contrast/agent/request_context.rb +10 -6
  132. data/lib/contrast/agent/request_handler.rb +1 -1
  133. data/lib/contrast/agent/response.rb +23 -12
  134. data/lib/contrast/agent/rewriter.rb +6 -9
  135. data/lib/contrast/agent/service_heartbeat.rb +2 -2
  136. data/lib/contrast/agent/static_analysis.rb +9 -9
  137. data/lib/contrast/agent/thread.rb +1 -1
  138. data/lib/contrast/agent/thread_watcher.rb +2 -2
  139. data/lib/contrast/agent/tracepoint_hook.rb +2 -2
  140. data/lib/contrast/agent/version.rb +1 -1
  141. data/lib/contrast/api.rb +4 -4
  142. data/lib/contrast/api/communication.rb +9 -9
  143. data/lib/contrast/api/communication/messaging_queue.rb +3 -6
  144. data/lib/contrast/api/communication/response_processor.rb +1 -1
  145. data/lib/contrast/api/communication/socket_client.rb +41 -6
  146. data/lib/contrast/api/communication/speedracer.rb +1 -1
  147. data/lib/contrast/api/communication/tcp_socket.rb +1 -1
  148. data/lib/contrast/api/communication/unix_socket.rb +1 -1
  149. data/lib/contrast/api/decorators.rb +17 -14
  150. data/lib/contrast/api/decorators/address.rb +20 -20
  151. data/lib/contrast/api/decorators/application_settings.rb +3 -2
  152. data/lib/contrast/api/decorators/application_update.rb +7 -8
  153. data/lib/contrast/api/decorators/http_request.rb +13 -12
  154. data/lib/contrast/api/decorators/input_analysis.rb +3 -2
  155. data/lib/contrast/api/decorators/library.rb +53 -0
  156. data/lib/contrast/api/decorators/library_usage_update.rb +30 -0
  157. data/lib/contrast/api/decorators/message.rb +4 -2
  158. data/lib/contrast/api/decorators/rasp_rule_sample.rb +2 -1
  159. data/lib/contrast/api/decorators/route_coverage.rb +3 -2
  160. data/lib/contrast/api/decorators/server_features.rb +3 -2
  161. data/lib/contrast/api/decorators/trace_event.rb +28 -25
  162. data/lib/contrast/api/decorators/trace_event_object.rb +6 -5
  163. data/lib/contrast/api/decorators/trace_event_signature.rb +5 -4
  164. data/lib/contrast/api/decorators/trace_taint_range.rb +4 -3
  165. data/lib/contrast/api/decorators/user_input.rb +4 -4
  166. data/lib/contrast/common_agent_configuration.rb +2 -2
  167. data/lib/contrast/components/agent.rb +8 -7
  168. data/lib/contrast/components/app_context.rb +50 -39
  169. data/lib/contrast/components/config.rb +32 -50
  170. data/lib/contrast/components/contrast_service.rb +10 -10
  171. data/lib/contrast/components/interface.rb +39 -17
  172. data/lib/contrast/components/inventory.rb +6 -1
  173. data/lib/contrast/components/logger.rb +1 -1
  174. data/lib/contrast/components/scope.rb +3 -3
  175. data/lib/contrast/components/settings.rb +20 -23
  176. data/lib/contrast/config.rb +18 -18
  177. data/lib/contrast/config/application_configuration.rb +5 -2
  178. data/lib/contrast/config/base_configuration.rb +2 -2
  179. data/lib/contrast/config/inventory_configuration.rb +2 -2
  180. data/lib/contrast/config/protect_rule_configuration.rb +1 -1
  181. data/lib/contrast/config/service_configuration.rb +8 -0
  182. data/lib/contrast/configuration.rb +93 -52
  183. data/lib/contrast/extension/assess.rb +21 -22
  184. data/lib/contrast/extension/assess/array.rb +18 -11
  185. data/lib/contrast/extension/assess/erb.rb +11 -3
  186. data/lib/contrast/extension/assess/eval_trigger.rb +7 -7
  187. data/lib/contrast/extension/assess/exec_trigger.rb +2 -2
  188. data/lib/contrast/extension/assess/fiber.rb +14 -14
  189. data/lib/contrast/extension/assess/hash.rb +7 -6
  190. data/lib/contrast/extension/assess/kernel.rb +34 -28
  191. data/lib/contrast/extension/assess/marshal.rb +67 -0
  192. data/lib/contrast/extension/assess/regexp.rb +10 -9
  193. data/lib/contrast/extension/assess/string.rb +23 -23
  194. data/lib/contrast/extension/inventory.rb +4 -4
  195. data/lib/contrast/extension/kernel.rb +1 -1
  196. data/lib/contrast/extension/module.rb +1 -1
  197. data/lib/contrast/extension/protect.rb +3 -3
  198. data/lib/contrast/extension/protect/kernel.rb +4 -4
  199. data/lib/contrast/extension/protect/psych.rb +2 -2
  200. data/lib/contrast/framework/base_support.rb +1 -1
  201. data/lib/contrast/framework/manager.rb +10 -11
  202. data/lib/contrast/framework/rack/patch/session_cookie.rb +22 -28
  203. data/lib/contrast/framework/rack/patch/support.rb +1 -1
  204. data/lib/contrast/framework/rack/support.rb +2 -2
  205. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +13 -13
  206. data/lib/contrast/framework/rails/patch/assess_configuration.rb +6 -12
  207. data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +11 -11
  208. data/lib/contrast/framework/rails/patch/support.rb +4 -4
  209. data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +11 -11
  210. data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +12 -12
  211. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +4 -4
  212. data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +12 -12
  213. data/lib/contrast/framework/rails/support.rb +67 -14
  214. data/lib/contrast/framework/sinatra/patch/base.rb +12 -12
  215. data/lib/contrast/framework/sinatra/patch/support.rb +1 -1
  216. data/lib/contrast/framework/sinatra/support.rb +6 -6
  217. data/lib/contrast/funchook/funchook.rb +1 -1
  218. data/lib/contrast/logger/application.rb +13 -5
  219. data/lib/contrast/logger/format.rb +22 -9
  220. data/lib/contrast/logger/log.rb +17 -10
  221. data/lib/contrast/logger/request.rb +30 -0
  222. data/lib/contrast/tasks/config.rb +1 -1
  223. data/lib/contrast/tasks/service.rb +2 -2
  224. data/lib/contrast/utils/assess/sampling_util.rb +2 -2
  225. data/lib/contrast/utils/assess/tracking_util.rb +49 -4
  226. data/lib/contrast/utils/class_util.rb +2 -2
  227. data/lib/contrast/utils/duck_utils.rb +0 -10
  228. data/lib/contrast/utils/env_configuration_item.rb +2 -1
  229. data/lib/contrast/utils/hash_digest.rb +2 -1
  230. data/lib/contrast/utils/heap_dump_util.rb +2 -2
  231. data/lib/contrast/utils/invalid_configuration_util.rb +21 -22
  232. data/lib/contrast/utils/inventory_util.rb +3 -10
  233. data/lib/contrast/utils/io_util.rb +1 -1
  234. data/lib/contrast/utils/os.rb +1 -1
  235. data/lib/contrast/utils/ruby_ast_rewriter.rb +1 -1
  236. data/lib/contrast/utils/sha256_builder.rb +2 -14
  237. data/lib/contrast/utils/stack_trace_utils.rb +2 -2
  238. data/lib/contrast/utils/string_utils.rb +11 -6
  239. data/resources/assess/policy.json +31 -22
  240. data/resources/deadzone/policy.json +5 -0
  241. data/ruby-agent.gemspec +21 -19
  242. data/service_executables/VERSION +1 -1
  243. data/service_executables/linux/contrast-service +0 -0
  244. data/service_executables/mac/contrast-service +0 -0
  245. metadata +73 -30
  246. data/lib/contrast/agent/assess/insulator.rb +0 -49
  247. data/lib/contrast/agent/require_state.rb +0 -61
  248. data/lib/contrast/extension/assess/assess_extension.rb +0 -147
  249. data/lib/contrast/utils/boolean_util.rb +0 -30
  250. data/lib/contrast/utils/freeze_util.rb +0 -32
  251. data/lib/contrast/utils/gemfile_reader.rb +0 -193
@@ -1,36 +1,36 @@
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 'monitor'
4
+ require 'monitor'
5
5
 
6
6
  # base
7
- cs__scoped_require 'contrast/agent/patching/policy/patch_status'
8
- cs__scoped_require 'contrast/agent/patching/policy/method_policy'
9
- cs__scoped_require 'contrast/agent/patching/policy/module_policy'
10
- cs__scoped_require 'contrast/components/interface'
11
- cs__scoped_require 'contrast/utils/class_util'
7
+ require 'contrast/agent/patching/policy/patch_status'
8
+ require 'contrast/agent/patching/policy/method_policy'
9
+ require 'contrast/agent/patching/policy/module_policy'
10
+ require 'contrast/components/interface'
11
+ require 'contrast/utils/class_util'
12
12
 
13
13
  # assess
14
- cs__scoped_require 'contrast/agent/assess/policy/policy'
15
- cs__scoped_require 'contrast/agent/assess/policy/policy_scanner'
16
- cs__scoped_require 'contrast/agent/assess/policy/rewriter_patch'
17
- cs__scoped_require 'contrast/agent/assess/policy/source_method'
18
- cs__scoped_require 'contrast/agent/assess/policy/trigger_method'
14
+ require 'contrast/agent/assess/policy/policy'
15
+ require 'contrast/agent/assess/policy/policy_scanner'
16
+ require 'contrast/agent/assess/policy/rewriter_patch'
17
+ require 'contrast/agent/assess/policy/source_method'
18
+ require 'contrast/agent/assess/policy/trigger_method'
19
19
 
20
20
  # deadzone
21
- cs__scoped_require 'contrast/agent/deadzone/policy/policy'
21
+ require 'contrast/agent/deadzone/policy/policy'
22
22
 
23
23
  # inventory
24
- cs__scoped_require 'contrast/agent/inventory/policy/policy'
24
+ require 'contrast/agent/inventory/policy/policy'
25
25
 
26
26
  # protect
27
- cs__scoped_require 'contrast/agent/protect/policy/policy'
27
+ require 'contrast/agent/protect/policy/policy'
28
28
 
29
29
  # patch
30
- cs__scoped_require 'contrast/agent/patching/policy/patch'
30
+ require 'contrast/agent/patching/policy/patch'
31
31
 
32
32
  # after load patched
33
- cs__scoped_require 'contrast/agent/patching/policy/after_load_patcher'
33
+ require 'contrast/agent/patching/policy/after_load_patcher'
34
34
 
35
35
  module Contrast
36
36
  module Agent
@@ -77,19 +77,21 @@ module Contrast
77
77
  # This method is called by TracePointHook to instrument a specific class during a require
78
78
  # or eval of dynamic class definition
79
79
  def patch_specific_module mod
80
- mod_name = mod.cs__name
81
- return unless Contrast::Utils::ClassUtil.truly_defined?(mod_name)
82
- return if AGENT.skip_instrumentation?(mod_name)
80
+ with_contrast_scope do
81
+ mod_name = mod.cs__name
82
+ return unless Contrast::Utils::ClassUtil.truly_defined?(mod_name)
83
+ return if AGENT.skip_instrumentation?(mod_name)
83
84
 
84
- load_patches_for_module(mod_name)
85
+ load_patches_for_module(mod_name)
85
86
 
86
- return unless all_module_names.any? { |name| name == mod_name }
87
+ return unless all_module_names.any? { |name| name == mod_name }
87
88
 
88
- module_data = Contrast::Agent::ModuleData.new(mod, mod_name)
89
- patch_into_module(module_data)
90
- all_module_names.delete(mod_name) if status_type.get_status(mod).patched?
91
- rescue StandardError => e
92
- logger.error('Unable to patch module', e, module: mod_name)
89
+ module_data = Contrast::Agent::ModuleData.new(mod, mod_name)
90
+ patch_into_module(module_data)
91
+ all_module_names.delete(mod_name) if status_type.get_status(mod).patched?
92
+ rescue StandardError => e
93
+ logger.error('Unable to patch module', e, module: mod_name)
94
+ end
93
95
  end
94
96
 
95
97
  # We did it, team. We found a patcher(s) that applies to the given
@@ -186,7 +188,7 @@ module Contrast
186
188
  clazz = module_data.mod
187
189
 
188
190
  status.patching!
189
- patched = include_module(module_data)
191
+ patched = false
190
192
 
191
193
  counts = 0
192
194
  # Monkey patch any methods in this class that have matching nodes in the policy
@@ -219,17 +221,6 @@ module Contrast
219
221
  module_data.mod).patch_status)
220
222
  end
221
223
 
222
- # Includes the given module with the
223
- # Contrast::Extension::Assess::AssessExtension
224
- # @param module_data [Contrast::Agent::ModuleData] the module, and
225
- # its name, that's being patched into
226
- def include_module module_data
227
- return false unless Contrast::Agent::Assess::Policy::Policy.instance.tracked_classes.include?(module_data.name)
228
-
229
- module_data.mod.send(:include, Contrast::Extension::Assess::AssessExtension)
230
- true
231
- end
232
-
233
224
  # Get all of the instance methods on the given module, excluding
234
225
  # those from super classes. this list will always include the
235
226
  # initialize method
@@ -247,6 +238,14 @@ module Contrast
247
238
  instance_methods.concat(mod.private_instance_methods(false)) if private
248
239
  # initialize is an exception to the inheritance rule.
249
240
  instance_methods << :initialize unless instance_methods.include?(:initialize)
241
+ # Object owns these, but we don't want to patch every :dup or
242
+ # :clone, just the ones on String, so we'll special case this.
243
+ # This breaks the norm, where we usually instrument the lowest
244
+ # method possible.
245
+ if mod == String
246
+ instance_methods << :clone
247
+ instance_methods << :dup
248
+ end
250
249
  instance_methods
251
250
  end
252
251
 
@@ -298,10 +297,10 @@ module Contrast
298
297
  end
299
298
 
300
299
  # core extensions
301
- cs__scoped_require 'contrast/extension/module'
302
- cs__scoped_require 'contrast/extension/assess'
303
- cs__scoped_require 'contrast/extension/inventory'
304
- cs__scoped_require 'contrast/extension/protect'
305
- cs__scoped_require 'contrast/extension/protect/kernel'
300
+ require 'contrast/extension/module'
301
+ require 'contrast/extension/assess'
302
+ require 'contrast/extension/inventory'
303
+ require 'contrast/extension/protect'
304
+ require 'contrast/extension/protect/kernel'
306
305
 
307
- cs__scoped_require 'cs__contrast_patch/cs__contrast_patch'
306
+ require 'cs__contrast_patch/cs__contrast_patch'
@@ -1,13 +1,13 @@
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 'json'
5
- cs__scoped_require 'singleton'
4
+ require 'json'
5
+ require 'singleton'
6
6
 
7
- cs__scoped_require 'contrast'
8
- cs__scoped_require 'contrast/components/interface'
9
- cs__scoped_require 'contrast/agent/patching/policy/module_policy'
10
- cs__scoped_require 'contrast/agent/patching/policy/method_policy'
7
+ require 'contrast'
8
+ require 'contrast/components/interface'
9
+ require 'contrast/agent/patching/policy/module_policy'
10
+ require 'contrast/agent/patching/policy/method_policy'
11
11
 
12
12
  module Contrast
13
13
  module Agent
@@ -37,13 +37,12 @@ module Contrast
37
37
 
38
38
  access_component :analysis, :logging
39
39
 
40
- attr_reader :sources, :propagators, :triggers, :providers, :tracked_classes
40
+ attr_reader :sources, :propagators, :triggers, :providers
41
41
 
42
42
  SOURCES_KEY = 'sources'
43
43
  PROPAGATION_KEY = 'propagators'
44
44
  RULES_KEY = 'rules'
45
45
  TRIGGERS_KEY = 'triggers'
46
- TRACKED_CLASSES_KEY = 'tracked_classes'
47
46
 
48
47
  def self.policy_json
49
48
  File.join(policy_folder, 'policy.json').cs__freeze
@@ -54,7 +53,6 @@ module Contrast
54
53
  @propagators = []
55
54
  @triggers = []
56
55
  @providers = {}
57
- @tracked_classes = []
58
56
 
59
57
  json = Contrast::Utils::ResourceLoader.load(cs__class.policy_json)
60
58
  from_hash_string(json)
@@ -114,7 +112,6 @@ module Contrast
114
112
  def module_names
115
113
  @_module_names ||= begin
116
114
  m = Set.new
117
- tracked_classes.each { |tracked| m << tracked }
118
115
  sources.each { |source| m << source.class_name }
119
116
  propagators.each { |propagator| m << propagator.class_name }
120
117
  triggers.each { |trigger| m << trigger.class_name }
@@ -127,12 +124,26 @@ module Contrast
127
124
  end
128
125
 
129
126
  def find_source_node class_name, method_name, instance_method
130
- sources.find { |source| source.class_name == class_name && source.method_name == method_name && source.instance_method == instance_method }
127
+ sources.find do |source|
128
+ source.class_name == class_name &&
129
+ source.method_name == method_name &&
130
+ source.instance_method == instance_method
131
+ end
132
+ end
133
+
134
+ def find_propagator_node class_name, method_name, instance_method
135
+ propagators.find do |propagator|
136
+ propagator.class_name == class_name &&
137
+ propagator.method_name == method_name &&
138
+ propagator.instance_method == instance_method
139
+ end
131
140
  end
132
141
 
133
142
  def find_node rule_id, class_name, method_name, instance_method
134
143
  find_triggers_by_rule(rule_id).find do |node|
135
- node.class_name == class_name && node.method_name == method_name && node.instance_method == instance_method
144
+ node.class_name == class_name &&
145
+ node.method_name == method_name &&
146
+ node.instance_method == instance_method
136
147
  end
137
148
  end
138
149
  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 Agent
@@ -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/extension/module'
5
- cs__scoped_require 'contrast/agent/patching/policy/policy_node'
4
+ require 'contrast/extension/module'
5
+ require 'contrast/agent/patching/policy/policy_node'
6
6
 
7
7
  module Contrast
8
8
  module Agent
@@ -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/protect/rule/cmd_injection'
5
- cs__scoped_require 'contrast/agent/protect/policy/applies_deserialization_rule'
6
- cs__scoped_require 'contrast/agent/protect/policy/rule_applicator'
4
+ require 'contrast/agent/protect/rule/cmd_injection'
5
+ require 'contrast/agent/protect/policy/applies_deserialization_rule'
6
+ require 'contrast/agent/protect/policy/rule_applicator'
7
7
 
8
8
  module Contrast
9
9
  module Agent
@@ -30,11 +30,9 @@ module Contrast
30
30
  Contrast::Agent::Protect::Policy::AppliesDeserializationRule.apply_deserialization_command_check(command)
31
31
  return if skip_analysis?
32
32
 
33
- begin
34
- clazz = object.is_a?(Module) ? object : object.cs__class
35
- class_name = clazz.cs__name
36
- rule.infilter(Contrast::Agent::REQUEST_TRACKER.current, class_name, method, command)
37
- end
33
+ clazz = object.is_a?(Module) ? object : object.cs__class
34
+ class_name = clazz.cs__name
35
+ rule.infilter(Contrast::Agent::REQUEST_TRACKER.current, class_name, method, command)
38
36
  end
39
37
 
40
38
  protected
@@ -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/protect/rule/deserialization'
5
- cs__scoped_require 'contrast/agent/protect/policy/rule_applicator'
4
+ require 'contrast/agent/protect/rule/deserialization'
5
+ require 'contrast/agent/protect/policy/rule_applicator'
6
6
 
7
7
  module Contrast
8
8
  module Agent
@@ -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/protect/rule/no_sqli'
5
- cs__scoped_require 'contrast/agent/protect/policy/rule_applicator'
4
+ require 'contrast/agent/protect/rule/no_sqli'
5
+ require 'contrast/agent/protect/policy/rule_applicator'
6
6
 
7
7
  module Contrast
8
8
  module Agent
@@ -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/protect/rule/path_traversal'
5
- cs__scoped_require 'contrast/agent/protect/policy/rule_applicator'
6
- cs__scoped_require 'contrast/utils/object_share'
4
+ require 'contrast/agent/protect/rule/path_traversal'
5
+ require 'contrast/agent/protect/policy/rule_applicator'
6
+ require 'contrast/utils/object_share'
7
7
 
8
8
  module Contrast
9
9
  module Agent
@@ -26,7 +26,7 @@ module Contrast
26
26
 
27
27
  action = properties['action']
28
28
  write_marker = write?(action, *args)
29
- possible_write = write_marker && possible_write(write_marker)
29
+ possible_write = write_marker && possible_write?(write_marker)
30
30
  path_traversal_rule(path, possible_write, object, method)
31
31
 
32
32
  # If the action was copy, we need to handle the write half of it.
@@ -48,7 +48,7 @@ module Contrast
48
48
 
49
49
  private
50
50
 
51
- def possible_write input
51
+ def possible_write? input
52
52
  input.cs__respond_to?(:to_s) &&
53
53
  input.to_s.include?(Contrast::Utils::ObjectShare::WRITE_FLAG)
54
54
  end
@@ -62,7 +62,7 @@ module Contrast
62
62
  return true if action == WRITE
63
63
 
64
64
  write_marker = args.length > 1 ? args[1] : nil
65
- write_marker && possible_write(write_marker)
65
+ write_marker && possible_write?(write_marker)
66
66
  end
67
67
 
68
68
  def path_traversal_rule path, possible_write, object, method
@@ -83,6 +83,7 @@ module Contrast
83
83
  tmp = CS__SAFER_REL_PATHS.map { |r| "#{ pwd }/#{ r }" }
84
84
  gems = ENV['GEM_PATH']
85
85
  tmp += gems.split(Contrast::Utils::ObjectShare::COLON) if gems
86
+ tmp.map!(&:downcase)
86
87
  tmp
87
88
  else
88
89
  []
@@ -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/protect/rule/sqli'
5
- cs__scoped_require 'contrast/agent/protect/policy/rule_applicator'
4
+ require 'contrast/agent/protect/rule/sqli'
5
+ require 'contrast/agent/protect/policy/rule_applicator'
6
6
 
7
7
  module Contrast
8
8
  module Agent
@@ -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/protect/rule/xxe'
5
- cs__scoped_require 'contrast/agent/protect/policy/rule_applicator'
6
- cs__scoped_require 'contrast/utils/object_share'
4
+ require 'contrast/agent/protect/rule/xxe'
5
+ require 'contrast/agent/protect/policy/rule_applicator'
6
+ require 'contrast/utils/object_share'
7
7
 
8
8
  module Contrast
9
9
  module Agent
@@ -27,7 +27,7 @@ module Contrast
27
27
  def apply_rule__io method, _exception, _properties, object, args
28
28
  need_rewind = false
29
29
  potential_xml = args[0]
30
- return unless potential_xml&.respond_to?(:rewind)
30
+ return unless potential_xml.cs__respond_to?(:rewind)
31
31
 
32
32
  xml = potential_xml.read
33
33
  need_rewind = true
@@ -1,16 +1,16 @@
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/policy'
4
+ require 'contrast/agent/patching/policy/policy'
5
5
 
6
6
  # classes required by patches in the policy
7
- cs__scoped_require 'contrast/agent/protect/policy/applies_command_injection_rule'
8
- cs__scoped_require 'contrast/agent/protect/policy/applies_deserialization_rule'
9
- cs__scoped_require 'contrast/agent/protect/policy/applies_no_sqli_rule'
10
- cs__scoped_require 'contrast/agent/protect/policy/applies_path_traversal_rule'
11
- cs__scoped_require 'contrast/agent/protect/policy/applies_sqli_rule'
12
- cs__scoped_require 'contrast/agent/protect/policy/applies_xxe_rule'
13
- cs__scoped_require 'contrast/agent/protect/policy/trigger_node'
7
+ require 'contrast/agent/protect/policy/applies_command_injection_rule'
8
+ require 'contrast/agent/protect/policy/applies_deserialization_rule'
9
+ require 'contrast/agent/protect/policy/applies_no_sqli_rule'
10
+ require 'contrast/agent/protect/policy/applies_path_traversal_rule'
11
+ require 'contrast/agent/protect/policy/applies_sqli_rule'
12
+ require 'contrast/agent/protect/policy/applies_xxe_rule'
13
+ require 'contrast/agent/protect/policy/trigger_node'
14
14
 
15
15
  module Contrast
16
16
  module Agent
@@ -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 Agent
@@ -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/trigger_node'
4
+ require 'contrast/agent/patching/policy/trigger_node'
5
5
 
6
6
  module Contrast
7
7
  module Agent
@@ -15,39 +15,39 @@ module Contrast
15
15
  end
16
16
 
17
17
  # The classes required for All Rasp Rules
18
- cs__scoped_require 'contrast/agent/protect/rule/base'
19
- cs__scoped_require 'contrast/agent/protect/rule/base_service'
18
+ require 'contrast/agent/protect/rule/base'
19
+ require 'contrast/agent/protect/rule/base_service'
20
20
 
21
21
  # The classes required for the XSS Rasp Rule
22
- cs__scoped_require 'contrast/agent/protect/rule/xss'
22
+ require 'contrast/agent/protect/rule/xss'
23
23
 
24
24
  # The classes required for the SQLI
25
- cs__scoped_require 'contrast/agent/protect/rule/default_scanner'
26
- cs__scoped_require 'contrast/agent/protect/rule/sqli'
27
- cs__scoped_require 'contrast/agent/protect/rule/sqli/default_sql_scanner'
28
- cs__scoped_require 'contrast/agent/protect/rule/sqli/mysql_sql_scanner'
29
- cs__scoped_require 'contrast/agent/protect/rule/sqli/postgres_sql_scanner'
30
- cs__scoped_require 'contrast/agent/protect/rule/sqli/sqlite_sql_scanner'
25
+ require 'contrast/agent/protect/rule/default_scanner'
26
+ require 'contrast/agent/protect/rule/sqli'
27
+ require 'contrast/agent/protect/rule/sqli/default_sql_scanner'
28
+ require 'contrast/agent/protect/rule/sqli/mysql_sql_scanner'
29
+ require 'contrast/agent/protect/rule/sqli/postgres_sql_scanner'
30
+ require 'contrast/agent/protect/rule/sqli/sqlite_sql_scanner'
31
31
 
32
32
  # The classes required for Path Traversal
33
- cs__scoped_require 'contrast/agent/protect/rule/path_traversal'
33
+ require 'contrast/agent/protect/rule/path_traversal'
34
34
 
35
35
  # The classes required for Command Injection
36
- cs__scoped_require 'contrast/agent/protect/rule/cmd_injection'
36
+ require 'contrast/agent/protect/rule/cmd_injection'
37
37
 
38
38
  # The classes required for XXE
39
- cs__scoped_require 'contrast/agent/protect/rule/xxe'
40
- cs__scoped_require 'contrast/agent/protect/rule/xxe/entity_wrapper'
39
+ require 'contrast/agent/protect/rule/xxe'
40
+ require 'contrast/agent/protect/rule/xxe/entity_wrapper'
41
41
 
42
42
  # The classes required for Untrusted Deserialization
43
- cs__scoped_require 'contrast/agent/protect/rule/deserialization'
43
+ require 'contrast/agent/protect/rule/deserialization'
44
44
 
45
45
  # The classes required for the NoSQLi
46
- cs__scoped_require 'contrast/agent/protect/rule/no_sqli'
47
- cs__scoped_require 'contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner'
46
+ require 'contrast/agent/protect/rule/no_sqli'
47
+ require 'contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner'
48
48
 
49
49
  # The classes required for Http Method Tampering
50
- cs__scoped_require 'contrast/agent/protect/rule/http_method_tampering'
50
+ require 'contrast/agent/protect/rule/http_method_tampering'
51
51
 
52
52
  # The classes required for Unsafe File Upload
53
- cs__scoped_require 'contrast/agent/protect/rule/unsafe_file_upload'
53
+ require 'contrast/agent/protect/rule/unsafe_file_upload'