contrast-agent 3.10.0 → 3.12.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (318) hide show
  1. checksums.yaml +4 -4
  2. data/.flayignore +1 -0
  3. data/.simplecov +5 -2
  4. data/ext/build_funchook.rb +12 -7
  5. data/ext/cs__assess_active_record_named/cs__active_record_named.c +12 -14
  6. data/ext/cs__assess_active_record_named/cs__active_record_named.h +1 -0
  7. data/ext/cs__assess_active_record_named/extconf.rb +3 -0
  8. data/ext/cs__assess_array/cs__assess_array.c +5 -6
  9. data/ext/cs__assess_array/cs__assess_array.h +1 -0
  10. data/ext/cs__assess_array/extconf.rb +3 -0
  11. data/ext/cs__assess_basic_object/cs__assess_basic_object.c +13 -11
  12. data/ext/cs__assess_basic_object/cs__assess_basic_object.h +2 -1
  13. data/ext/cs__assess_basic_object/extconf.rb +3 -0
  14. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +4 -3
  15. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.h +3 -3
  16. data/ext/cs__assess_fiber_track/extconf.rb +3 -0
  17. data/ext/cs__assess_hash/cs__assess_hash.c +40 -17
  18. data/ext/cs__assess_hash/cs__assess_hash.h +4 -6
  19. data/ext/cs__assess_hash/extconf.rb +3 -0
  20. data/ext/cs__assess_kernel/cs__assess_kernel.c +11 -9
  21. data/ext/cs__assess_kernel/cs__assess_kernel.h +1 -0
  22. data/ext/cs__assess_kernel/extconf.rb +3 -0
  23. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +3 -6
  24. data/ext/cs__assess_marshal_module/extconf.rb +3 -0
  25. data/ext/cs__assess_module/cs__assess_module.c +16 -14
  26. data/ext/cs__assess_module/cs__assess_module.h +3 -0
  27. data/ext/cs__assess_module/extconf.rb +3 -0
  28. data/ext/cs__assess_regexp/cs__assess_regexp.c +13 -9
  29. data/ext/cs__assess_regexp/cs__assess_regexp.h +1 -0
  30. data/ext/cs__assess_regexp/extconf.rb +3 -0
  31. data/ext/cs__assess_string/cs__assess_string.c +5 -8
  32. data/ext/cs__assess_string/cs__assess_string.h +2 -1
  33. data/ext/cs__assess_string/extconf.rb +3 -0
  34. data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +2 -2
  35. data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.h +3 -3
  36. data/ext/cs__assess_string_interpolation26/extconf.rb +3 -0
  37. data/ext/cs__assess_yield_track/cs__assess_yield_track.h +1 -1
  38. data/ext/cs__assess_yield_track/extconf.rb +3 -0
  39. data/ext/cs__common/cs__common.c +80 -1
  40. data/ext/cs__common/cs__common.h +34 -0
  41. data/ext/cs__common/extconf.rb +9 -8
  42. data/ext/cs__contrast_patch/cs__contrast_patch.h +1 -6
  43. data/ext/cs__contrast_patch/extconf.rb +3 -0
  44. data/ext/cs__protect_kernel/cs__protect_kernel.c +23 -12
  45. data/ext/cs__protect_kernel/cs__protect_kernel.h +1 -0
  46. data/ext/cs__protect_kernel/extconf.rb +3 -0
  47. data/ext/extconf_common.rb +10 -8
  48. data/funchook/autom4te.cache/requests +45 -45
  49. data/funchook/config.log +4 -4
  50. data/lib/contrast.rb +1 -1
  51. data/lib/contrast/agent.rb +32 -29
  52. data/lib/contrast/agent/assess.rb +1 -11
  53. data/lib/contrast/agent/assess/adjusted_span.rb +3 -1
  54. data/lib/contrast/agent/assess/contrast_event.rb +16 -62
  55. data/lib/contrast/agent/assess/events/event_factory.rb +25 -0
  56. data/lib/contrast/agent/assess/events/source_event.rb +83 -0
  57. data/lib/contrast/agent/assess/insulator.rb +0 -4
  58. data/lib/contrast/agent/assess/policy/patcher.rb +6 -2
  59. data/lib/contrast/agent/assess/policy/policy_node.rb +1 -8
  60. data/lib/contrast/agent/assess/policy/policy_scanner.rb +2 -2
  61. data/lib/contrast/agent/assess/policy/preshift.rb +1 -1
  62. data/lib/contrast/agent/assess/policy/propagation_method.rb +68 -33
  63. data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -1
  64. data/lib/contrast/agent/assess/policy/propagator.rb +1 -0
  65. data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
  66. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +1 -3
  67. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +80 -0
  68. data/lib/contrast/agent/assess/policy/propagator/select.rb +35 -22
  69. data/lib/contrast/agent/assess/policy/propagator/split.rb +26 -6
  70. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +2 -0
  71. data/lib/contrast/agent/assess/policy/rewriter_patch.rb +37 -26
  72. data/lib/contrast/agent/assess/policy/source_method.rb +20 -20
  73. data/lib/contrast/agent/assess/policy/source_node.rb +0 -15
  74. data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +90 -0
  75. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +57 -0
  76. data/lib/contrast/agent/assess/policy/trigger_method.rb +30 -45
  77. data/lib/contrast/agent/assess/policy/trigger_node.rb +7 -7
  78. data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -31
  79. data/lib/contrast/agent/assess/properties.rb +5 -3
  80. data/lib/contrast/agent/assess/rule/base.rb +1 -20
  81. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +23 -6
  82. data/lib/contrast/agent/assess/rule/redos.rb +4 -5
  83. data/lib/contrast/agent/assess/tag.rb +24 -14
  84. data/lib/contrast/agent/at_exit_hook.rb +16 -13
  85. data/lib/contrast/agent/class_reopener.rb +23 -8
  86. data/lib/contrast/agent/deadzone/policy/policy.rb +2 -2
  87. data/lib/contrast/agent/disable_reaction.rb +3 -4
  88. data/lib/contrast/agent/exclusion_matcher.rb +7 -48
  89. data/lib/contrast/agent/inventory/policy/datastores.rb +54 -0
  90. data/lib/contrast/agent/inventory/policy/policy.rb +1 -1
  91. data/lib/contrast/agent/middleware.rb +101 -260
  92. data/lib/contrast/agent/module_data.rb +2 -1
  93. data/lib/contrast/agent/patching/policy/after_load_patch.rb +13 -3
  94. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +59 -47
  95. data/lib/contrast/agent/patching/policy/method_policy.rb +3 -3
  96. data/lib/contrast/agent/patching/policy/module_policy.rb +0 -25
  97. data/lib/contrast/agent/patching/policy/patch.rb +97 -23
  98. data/lib/contrast/agent/patching/policy/patcher.rb +28 -30
  99. data/lib/contrast/agent/patching/policy/policy.rb +7 -7
  100. data/lib/contrast/agent/patching/policy/policy_node.rb +3 -11
  101. data/lib/contrast/agent/patching/policy/trigger_node.rb +2 -5
  102. data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +63 -0
  103. data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +52 -0
  104. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +68 -0
  105. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +117 -0
  106. data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +54 -0
  107. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +129 -0
  108. data/lib/contrast/agent/protect/policy/policy.rb +6 -6
  109. data/lib/contrast/agent/protect/policy/rule_applicator.rb +51 -0
  110. data/lib/contrast/agent/protect/rule.rb +0 -5
  111. data/lib/contrast/agent/protect/rule/base.rb +19 -37
  112. data/lib/contrast/agent/protect/rule/base_service.rb +3 -1
  113. data/lib/contrast/agent/protect/rule/cmd_injection.rb +12 -15
  114. data/lib/contrast/agent/protect/rule/default_scanner.rb +0 -13
  115. data/lib/contrast/agent/protect/rule/deserialization.rb +2 -0
  116. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +2 -2
  117. data/lib/contrast/agent/protect/rule/no_sqli.rb +4 -4
  118. data/lib/contrast/agent/protect/rule/path_traversal.rb +6 -10
  119. data/lib/contrast/agent/protect/rule/sqli.rb +5 -4
  120. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +2 -0
  121. data/lib/contrast/agent/protect/rule/xss.rb +2 -0
  122. data/lib/contrast/agent/protect/rule/xxe.rb +10 -4
  123. data/lib/contrast/agent/railtie.rb +3 -8
  124. data/lib/contrast/agent/reaction_processor.rb +5 -5
  125. data/lib/contrast/agent/request.rb +11 -18
  126. data/lib/contrast/agent/request_context.rb +16 -19
  127. data/lib/contrast/agent/request_handler.rb +35 -0
  128. data/lib/contrast/agent/response.rb +39 -86
  129. data/lib/contrast/agent/rewriter.rb +22 -10
  130. data/lib/contrast/agent/rule_set.rb +49 -0
  131. data/lib/contrast/agent/scope.rb +0 -6
  132. data/lib/contrast/agent/service_heartbeat.rb +3 -4
  133. data/lib/contrast/agent/socket_client.rb +25 -19
  134. data/lib/contrast/agent/static_analysis.rb +41 -0
  135. data/lib/contrast/agent/thread.rb +1 -1
  136. data/lib/contrast/agent/tracepoint_hook.rb +1 -5
  137. data/lib/contrast/agent/version.rb +1 -1
  138. data/lib/contrast/api.rb +1 -1
  139. data/lib/contrast/api/decorators.rb +14 -0
  140. data/lib/contrast/api/decorators/application_settings.rb +37 -0
  141. data/lib/contrast/api/decorators/application_update.rb +66 -0
  142. data/lib/contrast/api/decorators/input_analysis.rb +17 -0
  143. data/lib/contrast/api/decorators/server_features.rb +24 -0
  144. data/lib/contrast/api/speedracer.rb +28 -24
  145. data/lib/contrast/api/tcp_socket.rb +0 -2
  146. data/lib/contrast/components/agent.rb +34 -24
  147. data/lib/contrast/components/app_context.rb +45 -38
  148. data/lib/contrast/components/assess.rb +25 -15
  149. data/lib/contrast/components/config.rb +7 -5
  150. data/lib/contrast/components/contrast_service.rb +23 -71
  151. data/lib/contrast/components/heap_dump.rb +12 -8
  152. data/lib/contrast/components/interface.rb +15 -22
  153. data/lib/contrast/components/inventory.rb +5 -1
  154. data/lib/contrast/components/logger.rb +3 -68
  155. data/lib/contrast/components/protect.rb +40 -4
  156. data/lib/contrast/components/sampling.rb +22 -11
  157. data/lib/contrast/components/scope.rb +2 -52
  158. data/lib/contrast/components/settings.rb +42 -23
  159. data/lib/contrast/config/base_configuration.rb +1 -0
  160. data/lib/contrast/config/default_value.rb +1 -0
  161. data/lib/contrast/config/protect_rule_configuration.rb +0 -14
  162. data/lib/contrast/config/protect_rules_configuration.rb +0 -1
  163. data/lib/contrast/configuration.rb +2 -2
  164. data/lib/contrast/{extensions/ruby_core → extension}/assess.rb +12 -15
  165. data/lib/contrast/extension/assess/array.rb +77 -0
  166. data/lib/contrast/{extensions/ruby_core → extension}/assess/assess_extension.rb +29 -24
  167. data/lib/contrast/{extensions/ruby_core → extension}/assess/erb.rb +0 -8
  168. data/lib/contrast/extension/assess/eval_trigger.rb +78 -0
  169. data/lib/contrast/{extensions/ruby_core → extension}/assess/exec_trigger.rb +7 -9
  170. data/lib/contrast/extension/assess/fiber.rb +113 -0
  171. data/lib/contrast/extension/assess/hash.rb +39 -0
  172. data/lib/contrast/extension/assess/kernel.rb +110 -0
  173. data/lib/contrast/extension/assess/regexp.rb +84 -0
  174. data/lib/contrast/{extensions/ruby_core → extension}/assess/string.rb +18 -10
  175. data/lib/contrast/{extensions/ruby_core → extension}/delegator.rb +0 -0
  176. data/lib/contrast/{extensions/ruby_core → extension}/inventory.rb +2 -2
  177. data/lib/contrast/extension/kernel.rb +54 -0
  178. data/lib/contrast/{extensions/ruby_core → extension}/module.rb +0 -0
  179. data/lib/contrast/{extensions/ruby_core → extension}/protect.rb +2 -2
  180. data/lib/contrast/extension/protect/kernel.rb +44 -0
  181. data/lib/contrast/{extensions/ruby_core → extension}/protect/psych.rb +1 -1
  182. data/lib/contrast/{extensions/ruby_core → extension}/thread.rb +0 -0
  183. data/lib/contrast/framework/base_support.rb +32 -0
  184. data/lib/contrast/framework/manager.rb +59 -8
  185. data/lib/contrast/framework/platform_version.rb +1 -0
  186. data/lib/contrast/framework/rack/patch/session_cookie.rb +126 -0
  187. data/lib/contrast/framework/rack/patch/support.rb +24 -0
  188. data/lib/contrast/framework/rack/support.rb +22 -0
  189. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +43 -0
  190. data/lib/contrast/framework/rails/patch/assess_configuration.rb +103 -0
  191. data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +31 -0
  192. data/lib/contrast/framework/rails/patch/support.rb +67 -0
  193. data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +34 -0
  194. data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +39 -0
  195. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +73 -0
  196. data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +33 -0
  197. data/lib/contrast/framework/rails/support.rb +115 -0
  198. data/lib/contrast/framework/sinatra/application_helper.rb +51 -0
  199. data/lib/contrast/framework/sinatra/patch/base.rb +83 -0
  200. data/lib/contrast/framework/sinatra/patch/support.rb +27 -0
  201. data/lib/contrast/framework/sinatra/support.rb +109 -0
  202. data/lib/contrast/framework/view_technologies_descriptor.rb +1 -0
  203. data/lib/contrast/logger/application.rb +80 -0
  204. data/lib/contrast/logger/log.rb +143 -0
  205. data/lib/contrast/logger/time.rb +50 -0
  206. data/lib/contrast/tasks/config.rb +54 -0
  207. data/lib/contrast/tasks/service.rb +3 -13
  208. data/lib/contrast/utils/assess/sampling_util.rb +4 -9
  209. data/lib/contrast/utils/assess/tracking_util.rb +7 -1
  210. data/lib/contrast/utils/boolean_util.rb +2 -2
  211. data/lib/contrast/utils/cache.rb +0 -11
  212. data/lib/contrast/utils/class_util.rb +21 -2
  213. data/lib/contrast/utils/gemfile_reader.rb +7 -5
  214. data/lib/contrast/utils/hash_digest.rb +2 -11
  215. data/lib/contrast/utils/heap_dump_util.rb +12 -11
  216. data/lib/contrast/utils/invalid_configuration_util.rb +4 -4
  217. data/lib/contrast/utils/inventory_util.rb +2 -2
  218. data/lib/contrast/utils/io_util.rb +1 -11
  219. data/lib/contrast/utils/job_servers_running.rb +6 -4
  220. data/lib/contrast/utils/object_share.rb +1 -28
  221. data/lib/contrast/utils/os.rb +1 -25
  222. data/lib/contrast/utils/service_response_util.rb +36 -60
  223. data/lib/contrast/utils/service_sender_util.rb +84 -23
  224. data/lib/contrast/utils/sinatra_helper.rb +0 -6
  225. data/lib/contrast/utils/stack_trace_utils.rb +86 -182
  226. data/lib/contrast/utils/string_utils.rb +18 -2
  227. data/lib/contrast/utils/tag_util.rb +11 -1
  228. data/lib/contrast/utils/thread_tracker.rb +2 -2
  229. data/lib/contrast/utils/timer.rb +0 -40
  230. data/resources/assess/policy.json +42 -71
  231. data/resources/inventory/policy.json +2 -2
  232. data/resources/protect/policy.json +15 -15
  233. data/ruby-agent.gemspec +11 -4
  234. data/service_executables/VERSION +1 -1
  235. data/service_executables/linux/contrast-service +0 -0
  236. data/service_executables/mac/contrast-service +0 -0
  237. metadata +122 -111
  238. data/ext/cs__assess_regexp_track/cs__assess_regexp_track.c +0 -63
  239. data/ext/cs__assess_regexp_track/cs__assess_regexp_track.h +0 -29
  240. data/ext/cs__assess_regexp_track/extconf.rb +0 -2
  241. data/lib/contrast/agent/assess/frozen_properties.rb +0 -41
  242. data/lib/contrast/agent/assess/rule/csrf.rb +0 -66
  243. data/lib/contrast/agent/assess/rule/csrf/csrf_action.rb +0 -28
  244. data/lib/contrast/agent/assess/rule/csrf/csrf_applicator.rb +0 -73
  245. data/lib/contrast/agent/assess/rule/csrf/csrf_watcher.rb +0 -132
  246. data/lib/contrast/agent/assess/rule/response_scanning_rule.rb +0 -47
  247. data/lib/contrast/agent/assess/rule/response_watcher.rb +0 -36
  248. data/lib/contrast/agent/assess/rule/watcher.rb +0 -36
  249. data/lib/contrast/agent/feature_state.rb +0 -376
  250. data/lib/contrast/agent/logger_manager.rb +0 -116
  251. data/lib/contrast/agent/protect/rule/csrf.rb +0 -118
  252. data/lib/contrast/agent/protect/rule/csrf/csrf_evaluator.rb +0 -103
  253. data/lib/contrast/agent/protect/rule/csrf/csrf_token_injector.rb +0 -85
  254. data/lib/contrast/agent/settings_state.rb +0 -152
  255. data/lib/contrast/delegators.rb +0 -9
  256. data/lib/contrast/delegators/application_update.rb +0 -32
  257. data/lib/contrast/extensions/framework/rack/cookie.rb +0 -24
  258. data/lib/contrast/extensions/framework/rack/request.rb +0 -24
  259. data/lib/contrast/extensions/framework/rack/response.rb +0 -23
  260. data/lib/contrast/extensions/framework/rails/action_controller_railties_helper_inherited.rb +0 -20
  261. data/lib/contrast/extensions/framework/rails/active_record.rb +0 -26
  262. data/lib/contrast/extensions/framework/rails/active_record_named.rb +0 -53
  263. data/lib/contrast/extensions/framework/rails/active_record_time_zone_inherited.rb +0 -21
  264. data/lib/contrast/extensions/framework/rails/buffer.rb +0 -28
  265. data/lib/contrast/extensions/framework/rails/configuration.rb +0 -27
  266. data/lib/contrast/extensions/framework/sinatra/base.rb +0 -59
  267. data/lib/contrast/extensions/ruby_core/assess/array.rb +0 -59
  268. data/lib/contrast/extensions/ruby_core/assess/basic_object.rb +0 -15
  269. data/lib/contrast/extensions/ruby_core/assess/fiber.rb +0 -124
  270. data/lib/contrast/extensions/ruby_core/assess/hash.rb +0 -22
  271. data/lib/contrast/extensions/ruby_core/assess/kernel.rb +0 -95
  272. data/lib/contrast/extensions/ruby_core/assess/module.rb +0 -14
  273. data/lib/contrast/extensions/ruby_core/assess/regexp.rb +0 -206
  274. data/lib/contrast/extensions/ruby_core/assess/tilt_template_trigger.rb +0 -73
  275. data/lib/contrast/extensions/ruby_core/assess/xpath_library_trigger.rb +0 -40
  276. data/lib/contrast/extensions/ruby_core/eval_trigger.rb +0 -52
  277. data/lib/contrast/extensions/ruby_core/inventory/datastores.rb +0 -37
  278. data/lib/contrast/extensions/ruby_core/protect/applies_command_injection_rule.rb +0 -72
  279. data/lib/contrast/extensions/ruby_core/protect/applies_deserialization_rule.rb +0 -60
  280. data/lib/contrast/extensions/ruby_core/protect/applies_no_sqli_rule.rb +0 -83
  281. data/lib/contrast/extensions/ruby_core/protect/applies_path_traversal_rule.rb +0 -123
  282. data/lib/contrast/extensions/ruby_core/protect/applies_sqli_rule.rb +0 -65
  283. data/lib/contrast/extensions/ruby_core/protect/applies_xxe_rule.rb +0 -143
  284. data/lib/contrast/extensions/ruby_core/protect/kernel.rb +0 -30
  285. data/lib/contrast/framework/rails_support.rb +0 -88
  286. data/lib/contrast/framework/sinatra_application_helper.rb +0 -49
  287. data/lib/contrast/framework/sinatra_support.rb +0 -94
  288. data/lib/contrast/utils/comment_range.rb +0 -19
  289. data/lib/contrast/utils/data_store_util.rb +0 -23
  290. data/lib/contrast/utils/environment_util.rb +0 -81
  291. data/lib/contrast/utils/performs_logging.rb +0 -152
  292. data/lib/contrast/utils/rack_assess_session_cookie.rb +0 -104
  293. data/lib/contrast/utils/rails_assess_configuration.rb +0 -95
  294. data/lib/contrast/utils/random_util.rb +0 -22
  295. data/resources/csrf/inject.js +0 -44
  296. data/resources/factory-bot-spec/spec_helper.rb +0 -30
  297. data/resources/rubocops/kernel/catch_cop.rb +0 -37
  298. data/resources/rubocops/kernel/require_cop.rb +0 -37
  299. data/resources/rubocops/kernel/require_relative_cop.rb +0 -33
  300. data/resources/rubocops/module/autoload_cop.rb +0 -37
  301. data/resources/rubocops/module/const_defined_cop.rb +0 -37
  302. data/resources/rubocops/module/const_get_cop.rb +0 -37
  303. data/resources/rubocops/module/const_set_cop.rb +0 -37
  304. data/resources/rubocops/module/constants_cop.rb +0 -37
  305. data/resources/rubocops/module/name_cop.rb +0 -37
  306. data/resources/rubocops/object/class_cop.rb +0 -37
  307. data/resources/rubocops/object/freeze_cop.rb +0 -37
  308. data/resources/rubocops/object/frozen_cop.rb +0 -37
  309. data/resources/rubocops/object/is_a_cop.rb +0 -37
  310. data/resources/rubocops/object/method_cop.rb +0 -37
  311. data/resources/rubocops/object/respond_to_cop.rb +0 -37
  312. data/resources/rubocops/object/singleton_class_cop.rb +0 -37
  313. data/resources/rubocops/regexp/spelling_cop.rb +0 -44
  314. data/resources/rubocops/thread/new_cop.rb +0 -39
  315. data/resources/ruby-spec/ancestors_spec.rb +0 -70
  316. data/resources/ruby-spec/modulo_spec.rb +0 -831
  317. data/resources/ruby-spec/parameters_spec.rb +0 -261
  318. data/resources/ruby-spec/ruby_spec_spec_helper.rb +0 -35
@@ -35,7 +35,6 @@ class Contrast::Agent::Protect::Rule::DefaultScanner # rubocop:disable Style/Cla
35
35
  @_token_boundaries ||= scan_token_boundaries(query)
36
36
  end
37
37
 
38
- CANARY = "select * from tbl where bar='bar';#' and pwd='sec3r3t'; # CANARY"
39
38
  def scan_token_boundaries query
40
39
  boundaries = []
41
40
  return boundaries unless query && !query.empty?
@@ -268,24 +267,12 @@ class Contrast::Agent::Protect::Rule::DefaultScanner # rubocop:disable Style/Cla
268
267
  true
269
268
  end
270
269
 
271
- # Does this language let the user redefine the escape character
272
- # We assume no by default
273
- def redefines_escape_char?
274
- false
275
- end
276
-
277
270
  # Is the character provided an escape character?
278
271
  # By default, we'll assume
279
272
  def escape_char? char
280
273
  char == Contrast::Utils::ObjectShare::BACK_SLASH
281
274
  end
282
275
 
283
- # Does this language support string escape sequences?
284
- # We assume no by default
285
- def support_string_escape_sequence?
286
- false
287
- end
288
-
289
276
  # Is this the start of a string escape sequence?
290
277
  # Since escape sequences aren't supported, the answer is always false
291
278
  def escape_sequence_start? _char
@@ -1,6 +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/base'
5
+
4
6
  module Contrast
5
7
  module Agent
6
8
  module Protect
@@ -1,6 +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/base_service'
5
+
4
6
  module Contrast
5
7
  module Agent
6
8
  module Protect
@@ -16,8 +18,6 @@ module Contrast
16
18
 
17
19
  def postfilter context
18
20
  return unless enabled? && POSTFILTER_MODES.include?(mode)
19
-
20
- logger.debug("#{ name } postfilter...")
21
21
  return if normal_request?(context)
22
22
 
23
23
  # The only way to be here in postfilter with a result is if the rule mode was MONITOR
@@ -1,9 +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
- # This could be useful for making patterns maybe?
5
- # https://github.com/cr0hn/nosqlinjection_wordlists
6
- # https://www.owasp.org/index.php/Testing_for_NoSQL_injection
4
+ cs__scoped_require 'contrast/agent/protect/rule/base_service'
5
+
7
6
  module Contrast
8
7
  module Agent
9
8
  module Protect
@@ -70,7 +69,8 @@ module Contrast
70
69
  begin
71
70
  potential_attack_string = JSON.generate(potential_attack_string).to_s
72
71
  rescue JSON::GeneratorError
73
- logger.debug("Error in JSON::generate from input #{ potential_attack_string }")
72
+ logger.trace('Error in JSON::generate', input: potential_attack_string)
73
+ nil
74
74
  end
75
75
  end
76
76
  super(context, potential_attack_string, **kwargs)
@@ -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 'contrast/utils/stack_trace_utils'
4
+ cs__scoped_require 'contrast/agent/protect/rule/base_service'
5
5
  cs__scoped_require 'contrast/components/interface'
6
+ cs__scoped_require 'contrast/utils/stack_trace_utils'
6
7
 
7
8
  module Contrast
8
9
  module Agent
@@ -12,7 +13,7 @@ module Contrast
12
13
  # Protect rule.
13
14
  class PathTraversal < Contrast::Agent::Protect::Rule::BaseService
14
15
  include Contrast::Components::Interface
15
- access_component :logging, :agent
16
+ access_component :agent, :analysis
16
17
 
17
18
  NAME = 'path-traversal'
18
19
  SYSTEM_PATHS = %w[
@@ -28,8 +29,6 @@ module Contrast
28
29
  /windows/repair/
29
30
  ].cs__freeze
30
31
 
31
- KNOWN_SECURITY_BYPASS_MARKERS = ['::$DATA', '::$Index', '', '\x00'].cs__freeze
32
-
33
32
  def name
34
33
  NAME
35
34
  end
@@ -70,11 +69,6 @@ module Contrast
70
69
  private
71
70
 
72
71
  # Build a subclass of the RaspRuleSample if the sample matches
73
- # TODO: SPEED-? delete me when implemented in Speedracer.
74
- # this implementation duplicates logic that is moving to Speedracer
75
- # the reason it is still here is Speedracer doesn't yet have a method to correlate
76
- # and (update) attack results that are generated because the evaluation results
77
- # from REP, it can only forward the attack results are generated by the agent.
78
72
  def build_rep_sample context, path
79
73
  sample = build_base_sample(context, nil)
80
74
  sample.path_traversal_semantic = Contrast::Api::Dtm::PathTraversalSemanticAnalysisDetails.new
@@ -104,7 +98,7 @@ module Contrast
104
98
  end
105
99
 
106
100
  def custom_code_access_sysfile_enabled?
107
- AGENT.report_custom_code_sysfile_access?
101
+ PROTECT.report_custom_code_sysfile_access?
108
102
  end
109
103
 
110
104
  def custom_code_accessing_system_file? input
@@ -121,6 +115,8 @@ module Contrast
121
115
  false
122
116
  end
123
117
 
118
+ # TODO: RUBY-318
119
+ # KNOWN_SECURITY_BYPASS_MARKERS = ['::$DATA', '::$Index', '', '\x00'].cs__freeze
124
120
  def contains_known_attack_signatures? input
125
121
  utf8 = Contrast::Utils::StringUtils.force_utf8(input)
126
122
  _ = CGI.unescape(utf8)
@@ -1,7 +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/extensions/ruby_core/protect/applies_sqli_rule'
4
+ cs__scoped_require 'contrast/agent/protect/rule/base_service'
5
+ cs__scoped_require 'contrast/agent/protect/policy/applies_sqli_rule'
5
6
 
6
7
  module Contrast
7
8
  module Agent
@@ -83,11 +84,11 @@ module Contrast
83
84
 
84
85
  def select_scanner database
85
86
  @sql_scanners ||= {
86
- Contrast::CoreExtensions::Protect::AppliesSqliRule::DATABASE_MYSQL =>
87
+ Contrast::Agent::Protect::Policy::AppliesSqliRule::DATABASE_MYSQL =>
87
88
  Contrast::Agent::Protect::Rule::Sqli::MysqlSqlScanner.new,
88
- Contrast::CoreExtensions::Protect::AppliesSqliRule::DATABASE_PG =>
89
+ Contrast::Agent::Protect::Policy::AppliesSqliRule::DATABASE_PG =>
89
90
  Contrast::Agent::Protect::Rule::Sqli::PostgresSqlScanner.new,
90
- Contrast::CoreExtensions::Protect::AppliesSqliRule::DATABASE_SQLITE =>
91
+ Contrast::Agent::Protect::Policy::AppliesSqliRule::DATABASE_SQLITE =>
91
92
  Contrast::Agent::Protect::Rule::Sqli::SqliteSqlScanner.new
92
93
  }.cs__freeze
93
94
 
@@ -1,6 +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/base_service'
5
+
4
6
  module Contrast
5
7
  module Agent
6
8
  module Protect
@@ -1,6 +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/base_service'
5
+
4
6
  module Contrast
5
7
  module Agent
6
8
  module Protect
@@ -1,6 +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/protect/rule/base'
4
5
  cs__scoped_require 'contrast/utils/timer'
5
6
 
6
7
  module Contrast
@@ -11,7 +12,6 @@ module Contrast
11
12
  # of unsafe external entity resolution.
12
13
  class Xxe < Contrast::Agent::Protect::Rule::Base
13
14
  NAME = 'xxe'
14
- EXPLOIT_CHARACTERS = Contrast::Utils::ObjectShare::EMPTY_ARRAY
15
15
  BLOCK_MESSAGE = 'XXE rule triggered. Response blocked.'
16
16
  EXTERNAL_ENTITY_PATTERN = /<!ENTITY\s+[a-zA-Z0-f]+\s+(?:SYSTEM|PUBLIC)\s+(.*?)>/.cs__freeze
17
17
 
@@ -19,6 +19,14 @@ module Contrast
19
19
  NAME
20
20
  end
21
21
 
22
+ # Given an xml, evaluate it for an XXE attack.
23
+ #
24
+ # @param context [Contrast::Agent::RequestContext] the context of the
25
+ # request in which this input is evaluated.
26
+ # @param framework [Object] the name of the Parser being used.
27
+ # @param xml [Object] the container of the XML to be checked.
28
+ # @raise [Contrast::SecurityException] Security exception if an XXE
29
+ # attack is found and the rule is in block mode.
22
30
  def infilter context, framework, xml
23
31
  result = find_attacker(context, xml, framework: framework)
24
32
  return nil unless result
@@ -31,12 +39,10 @@ module Contrast
31
39
 
32
40
  protected
33
41
 
34
- def find_attacker context, xml, **kwargs
42
+ def find_attacker context, xml, **_kwargs
35
43
  return nil unless xml
36
44
  return nil if protect_excluded_by_code?
37
45
 
38
- logger.debug("checking: #{ name } in '#{ kwargs[:framework] }'")
39
-
40
46
  xxe_details, last_idx = build_details(xml)
41
47
  return nil unless xxe_details
42
48
 
@@ -12,24 +12,19 @@ module Contrast
12
12
  access_component :agent, :app_context, :logging
13
13
 
14
14
  initializer 'Contrast Ruby Agent Initializer' do |app|
15
- if defined?(Rails) && defined?(Rails.logger)
16
- Rails.logger.debug('In railtie ::')
17
- Rails.logger.debug(app.middleware.inspect)
18
- end
15
+ Rails.logger.debug("In railtie ::#{ app.middleware.inspect }") if defined?(Rails) && defined?(Rails.logger)
19
16
 
20
- # TODO: RUBY-564 This logic is not specific to Rails and should be used more broadly
21
- # with all web frameworks. Move this check to be a part of our new initialization
22
- # routine.
23
17
  if APP_CONTEXT.instrument_middleware_stack?
24
18
  AGENT.insert_middleware(app)
25
19
  else
26
20
  Rails.logger.debug('Detected a running job server, skipping Contrast middleware insertion.')
27
- logger.debug(nil, "Disabling Contrast for process #{ Process.pid }")
21
+ logger.debug('Disabling Contrast for process', p_id: Process.pid)
28
22
  end
29
23
  end
30
24
 
31
25
  rake_tasks do
32
26
  load 'contrast/tasks/service.rb'
27
+ load 'contrast/tasks/config.rb'
33
28
  end
34
29
  end
35
30
  end
@@ -25,20 +25,20 @@ module Contrast
25
25
  return nil unless application_settings&.reactions&.any?
26
26
 
27
27
  application_settings.reactions.each do |reaction|
28
- logger.debug(nil, "Received the following reaction: #{ reaction.operation }")
29
-
30
28
  # the enums are all uppercase, we need to downcase them before attempting to log
31
29
  level = reaction.log_level.nil? ? :error : reaction.log_level.downcase
32
30
 
33
- logger.with_level(nil, reaction.message, level) if reaction.message
31
+ logger.with_level(level, reaction.message) if reaction.message
34
32
 
35
33
  case reaction.operation
36
34
  when :DISABLE
37
35
  Contrast::Agent::DisableReaction.run reaction, level
38
- when :NOOP # rubocop:disable Lint/EmptyWhen
36
+ when :NOOP
39
37
  # NOOP
40
38
  else
41
- logger.warn(nil, "ReactionProcessor received a reaction with an unknown operation: #{ reaction.operation }")
39
+ logger.warn(
40
+ 'ReactionProcessor received a reaction with an unknown operation',
41
+ operation: reaction.operation)
42
42
  end
43
43
  end
44
44
  end
@@ -6,7 +6,6 @@ cs__scoped_require 'timeout'
6
6
 
7
7
  cs__scoped_require 'contrast/utils/object_share'
8
8
  cs__scoped_require 'contrast/utils/string_utils'
9
- cs__scoped_require 'contrast/utils/comment_range'
10
9
  cs__scoped_require 'contrast/utils/hash_digest'
11
10
  cs__scoped_require 'contrast/components/interface'
12
11
 
@@ -18,7 +17,7 @@ module Contrast
18
17
  # order to avoid repeatedly creating Strings & thrashing GC.
19
18
  class Request
20
19
  include Contrast::Components::Interface
21
- access_component :logging, :scope
20
+ access_component :agent, :logging, :scope
22
21
 
23
22
  extend Forwardable
24
23
 
@@ -108,7 +107,7 @@ module Contrast
108
107
  def request_method
109
108
  rack_request.get_header(Rack::REQUEST_METHOD)
110
109
  rescue StandardError => e
111
- logger.warn("Unable to extract request method: #{ e }")
110
+ logger.warn('Unable to extract request method', e)
112
111
  UNKNOWN_REQUEST_METHOD
113
112
  end
114
113
 
@@ -160,10 +159,6 @@ module Contrast
160
159
  end
161
160
  end
162
161
 
163
- def header_value key
164
- normalized_request_headers[Contrast::Utils::StringUtils.normalized_key(key)]
165
- end
166
-
167
162
  # Return a flattened hash of params with realized paths for keys, in
168
163
  # addition to a separate, valueless, entry for each nest key.
169
164
  # See RUBY-621 for more details.
@@ -209,15 +204,15 @@ module Contrast
209
204
  body = @rack_request.body
210
205
  if defined?(Rack::Multipart)
211
206
  if defined?(Rack::Multipart::UploadedFile) && body.is_a?(Rack::Multipart::UploadedFile)
212
- logger.debug("not parsing uploaded file body :: #{ body.original_filename }::#{ body.content_type }")
207
+ logger.trace("not parsing uploaded file body :: #{ body.original_filename }::#{ body.content_type }")
213
208
  @_request_body = nil
214
209
  else
215
- logger.debug("parsing body from request :: #{ body.cs__class.cs__name }")
216
- @_request_body = Contrast::Utils::StringUtils.force_utf8(read_body(body), logger)
210
+ logger.trace("parsing body from request :: #{ body.cs__class.cs__name }")
211
+ @_request_body = Contrast::Utils::StringUtils.force_utf8(read_body(body))
217
212
  end
218
213
  else
219
- logger.debug('Rack before 1.3.x does not support Rack::Multipart')
220
- @_request_body = Contrast::Utils::StringUtils.force_utf8(read_body(body), logger)
214
+ logger.trace('Rack before 1.3.x does not support Rack::Multipart')
215
+ @_request_body = Contrast::Utils::StringUtils.force_utf8(read_body(body))
221
216
  end
222
217
 
223
218
  true
@@ -336,7 +331,7 @@ module Contrast
336
331
  end
337
332
 
338
333
  def omit_body?
339
- return true if Contrast::Agent::FeatureState.instance.omit_body?
334
+ return true if AGENT.omit_body?
340
335
  return false if document_type == :XML
341
336
  return false if document_type == :JSON
342
337
 
@@ -352,10 +347,8 @@ module Contrast
352
347
  address.host = Contrast::Utils::StringUtils.force_utf8(Socket.gethostname)
353
348
  address.ip = Contrast::Utils::StringUtils.force_utf8(Resolv.getaddress(address.host))
354
349
  end
355
- rescue Timeout::Error
356
- logger.warn(nil, "Timeout resolving host or ip in #{ address }")
357
350
  rescue StandardError => e
358
- logger.warn(e, "Error resolving address for #{ address }")
351
+ logger.warn('Unable to resolve host or ip', e, address: address)
359
352
  end
360
353
  address
361
354
  end
@@ -444,8 +437,8 @@ module Contrast
444
437
  body.rewind if can_rewind
445
438
  body.read
446
439
  rescue StandardError => e
447
- logger.error("Error in attempt to read body :: #{ e.message }")
448
- logger.debug(e.backtrace.join(Contrast::Utils::ObjectShare::NEW_LINE))
440
+ logger.error('Error in attempt to read body', message: e.message)
441
+ logger.trace('With Stack', e)
449
442
  body.to_s
450
443
  ensure
451
444
  # be a good citizen and rewind
@@ -4,7 +4,6 @@
4
4
  cs__scoped_require 'contrast/utils/timer'
5
5
  cs__scoped_require 'contrast/agent/request'
6
6
  cs__scoped_require 'contrast/agent/response'
7
- cs__scoped_require 'contrast/utils/comment_range'
8
7
  cs__scoped_require 'contrast/utils/inventory_util'
9
8
  cs__scoped_require 'contrast/components/interface'
10
9
 
@@ -15,7 +14,7 @@ module Contrast
15
14
  # in a standardized and normalized format which the Agent understands.
16
15
  class RequestContext
17
16
  include Contrast::Components::Interface
18
- access_component :logging, :analysis, :scope, :contrast_service
17
+ access_component :agent, :analysis, :logging, :settings, :scope
19
18
 
20
19
  EMPTY_INPUT_ANALYSIS_PB = Contrast::Api::Settings::InputAnalysis.new
21
20
 
@@ -46,6 +45,7 @@ module Contrast
46
45
  # build analyzer
47
46
  @do_not_track = false
48
47
  @speedracer_input_analysis = EMPTY_INPUT_ANALYSIS_PB
48
+ speedracer_input_analysis.request = request
49
49
 
50
50
  # flag to indicate whether the app is fully loaded
51
51
  @app_loaded = !!app_loaded
@@ -67,10 +67,6 @@ module Contrast
67
67
  @app_loaded
68
68
  end
69
69
 
70
- def analyze?
71
- @sample_request || @sample_response
72
- end
73
-
74
70
  def analyze_request?
75
71
  @sample_request
76
72
  end
@@ -94,10 +90,8 @@ module Contrast
94
90
  # For TS routes
95
91
  @observed_route.signature = route.route
96
92
  @observed_route.verb = route.verb
97
- @observed_route.session_id = Contrast::Agent::FeatureState.instance.current_session_id
98
-
99
- # TODO: SPEED-273: deprecate when SR handles this. ContrastUI API currently does not allow empty url, so we have to provide a default
100
- @observed_route.url = route.url.empty? ? Contrast::Utils::ObjectShare::SLASH : route.url
93
+ @observed_route.session_id = SETTINGS.session_id
94
+ @observed_route.url = route.url if route.url
101
95
  end
102
96
 
103
97
  # Collect the results for the given rule with the given action
@@ -115,25 +109,28 @@ module Contrast
115
109
  end
116
110
 
117
111
  def service_extract_request
112
+ return false unless AGENT.enabled?
113
+ return false unless PROTECT.enabled?
118
114
  return false if @do_not_track
119
115
 
120
- service_response = CONTRAST_SERVICE.send_message(@activity.http_request)
116
+ service_response = Contrast::Utils::ServiceSenderUtil.send_event_immediately(@activity.http_request)
121
117
  return false unless service_response
122
118
 
123
119
  handle_protect_state(service_response)
124
120
  ia = service_response.input_analysis
125
121
  if ia
126
- logger.debug(nil, "Analysis from Contrast Service: evaluations=#{ ia.results.length }")
127
- logger.debug(nil, "IA=#{ ia.inspect }")
122
+ logger.trace("Analysis from Contrast Service: evaluations=#{ ia.results.length }")
123
+ logger.trace('Results', input_analysis: ia.inspect)
128
124
  @speedracer_input_analysis = ia
125
+ speedracer_input_analysis.request = request
129
126
  else
130
- logger.debug(nil, 'Analysis from Contrast Service was empty.')
127
+ logger.trace('Analysis from Contrast Service was empty.')
131
128
  false
132
129
  end
133
130
  rescue Contrast::SecurityException
134
131
  raise
135
132
  rescue StandardError => e
136
- logger.warn(e, 'Unable to extract Contrast Service information from request')
133
+ logger.warn('Unable to extract Contrast Service information from request', e)
137
134
  false
138
135
  end
139
136
 
@@ -154,7 +151,7 @@ module Contrast
154
151
  build_attack_results(agent_settings)
155
152
 
156
153
  msg = agent_settings.protect_state.security_message
157
- logger.warn(nil, 'Contrast Service said to block this request')
154
+ logger.warn('Contrast Service said to block this request')
158
155
  raise Contrast::SecurityException.new(nil, (msg || 'Blocking suspicious behavior'))
159
156
  end
160
157
 
@@ -165,7 +162,7 @@ module Contrast
165
162
  @response = Contrast::Agent::Response.new(rack_response)
166
163
  activity.http_response = @response.dtm if @sample_response
167
164
  rescue StandardError => e
168
- logger.error(e, 'Unable to extract information after request')
165
+ logger.error('Unable to extract information after request', e)
169
166
  end
170
167
 
171
168
  def add_property key, value
@@ -195,7 +192,7 @@ module Contrast
195
192
  rule = PROTECT.rule(rule_id)
196
193
  next unless rule
197
194
 
198
- logger.debug(nil, "Building attack result from Contrast Service input analysis: result=#{ ia_result.inspect }")
195
+ logger.debug('Building attack result from Contrast Service input analysis result', result: ia_result.inspect)
199
196
 
200
197
  attack_result = if rule.mode == :BLOCK
201
198
  # special case for rules (like reflected xss)
@@ -216,7 +213,7 @@ module Contrast
216
213
  end
217
214
 
218
215
  attack_results_by_rule.each_pair do |_, attack_result|
219
- logger.debug(nil, "Blocking for #{ attack_result.rule_id }")
216
+ logger.info('Blocking attack result', rule: attack_result.rule_id)
220
217
  activity.results << attack_result
221
218
  end
222
219
  end