contrast-agent 6.6.4 → 6.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (340) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -2
  3. data/.gitmodules +0 -3
  4. data/.simplecov +0 -1
  5. data/Rakefile +0 -1
  6. data/ext/cs__assess_array/cs__assess_array.c +41 -10
  7. data/ext/cs__assess_array/cs__assess_array.h +4 -1
  8. data/ext/cs__scope/cs__scope.c +1 -1
  9. data/lib/contrast/agent/assess/contrast_event.rb +2 -24
  10. data/lib/contrast/agent/assess/events/source_event.rb +7 -61
  11. data/lib/contrast/agent/assess/finalizers/hash.rb +11 -0
  12. data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +0 -55
  13. data/lib/contrast/agent/assess/policy/policy_node.rb +3 -3
  14. data/lib/contrast/agent/assess/policy/policy_node_utils.rb +0 -1
  15. data/lib/contrast/agent/assess/policy/propagation_node.rb +4 -4
  16. data/lib/contrast/agent/assess/policy/source_method.rb +24 -1
  17. data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +7 -5
  18. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +6 -1
  19. data/lib/contrast/agent/assess/policy/trigger_method.rb +40 -121
  20. data/lib/contrast/agent/assess/policy/trigger_node.rb +3 -3
  21. data/lib/contrast/agent/assess/policy/trigger_validation/redos_validator.rb +1 -1
  22. data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +1 -1
  23. data/lib/contrast/agent/assess/policy/trigger_validation/xss_validator.rb +1 -1
  24. data/lib/contrast/agent/assess/property/evented.rb +2 -12
  25. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +42 -82
  26. data/lib/contrast/agent/assess/rule/response/base_rule.rb +11 -27
  27. data/lib/contrast/agent/assess/rule/response/body_rule.rb +1 -3
  28. data/lib/contrast/agent/assess/rule/response/cache_control_header_rule.rb +77 -62
  29. data/lib/contrast/agent/assess/rule/response/csp_header_insecure_rule.rb +1 -1
  30. data/lib/contrast/agent/assess/rule/response/framework/rails_support.rb +6 -1
  31. data/lib/contrast/agent/assess/rule/response/header_rule.rb +5 -5
  32. data/lib/contrast/agent/assess/rule/response/hsts_header_rule.rb +1 -1
  33. data/lib/contrast/agent/assess/rule/response/x_xss_protection_header_rule.rb +1 -1
  34. data/lib/contrast/agent/assess/tracker.rb +1 -7
  35. data/lib/contrast/agent/at_exit_hook.rb +1 -7
  36. data/lib/contrast/agent/excluder.rb +224 -0
  37. data/lib/contrast/agent/exclusion_matcher.rb +25 -7
  38. data/lib/contrast/agent/inventory/database_config.rb +18 -23
  39. data/lib/contrast/agent/middleware.rb +4 -5
  40. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +6 -0
  41. data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +146 -127
  42. data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +4 -0
  43. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +20 -0
  44. data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +1 -0
  45. data/lib/contrast/agent/protect/policy/rule_applicator.rb +1 -1
  46. data/lib/contrast/agent/protect/rule/base.rb +98 -66
  47. data/lib/contrast/agent/protect/rule/base_service.rb +49 -24
  48. data/lib/contrast/agent/protect/rule/bot_blocker/bot_blocker_input_classification.rb +98 -0
  49. data/lib/contrast/agent/protect/rule/bot_blocker.rb +81 -0
  50. data/lib/contrast/agent/protect/rule/cmd_injection.rb +30 -99
  51. data/lib/contrast/agent/protect/rule/cmdi/cmdi_backdoors.rb +132 -0
  52. data/lib/contrast/agent/protect/rule/cmdi/cmdi_base_rule.rb +169 -0
  53. data/lib/contrast/agent/protect/rule/cmdi/cmdi_chained_command.rb +69 -0
  54. data/lib/contrast/agent/protect/rule/cmdi/cmdi_dangerous_path.rb +68 -0
  55. data/lib/contrast/agent/protect/rule/cmdi/cmdi_input_classification.rb +2 -58
  56. data/lib/contrast/agent/protect/rule/default_scanner.rb +1 -1
  57. data/lib/contrast/agent/protect/rule/deserialization.rb +10 -19
  58. data/lib/contrast/agent/protect/rule/http_method_tampering/http_method_tampering_input_classification.rb +2 -2
  59. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +0 -11
  60. data/lib/contrast/agent/protect/rule/no_sqli/no_sqli_input_classification.rb +29 -34
  61. data/lib/contrast/agent/protect/rule/no_sqli.rb +25 -18
  62. data/lib/contrast/agent/protect/rule/path_traversal/path_traversal_input_classification.rb +61 -0
  63. data/lib/contrast/agent/protect/rule/path_traversal/path_traversal_semantic_security_bypass.rb +114 -0
  64. data/lib/contrast/agent/protect/rule/path_traversal.rb +46 -18
  65. data/lib/contrast/agent/protect/rule/sql_sample_builder.rb +49 -29
  66. data/lib/contrast/agent/protect/rule/sqli/sqli_base_rule.rb +37 -0
  67. data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +2 -62
  68. data/lib/contrast/agent/protect/rule/sqli/sqli_semantic/sqli_dangerous_functions.rb +67 -0
  69. data/lib/contrast/agent/protect/rule/sqli.rb +67 -22
  70. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_input_classification.rb +39 -63
  71. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +6 -33
  72. data/lib/contrast/agent/protect/rule/xss/reflected_xss_input_classification.rb +58 -0
  73. data/lib/contrast/agent/protect/rule/xss.rb +14 -20
  74. data/lib/contrast/agent/protect/rule/xxe.rb +15 -30
  75. data/lib/contrast/agent/protect/rule.rb +3 -1
  76. data/lib/contrast/agent/reporting/attack_result/attack_result.rb +8 -0
  77. data/lib/contrast/agent/reporting/attack_result/rasp_rule_sample.rb +70 -36
  78. data/lib/contrast/agent/reporting/attack_result/response_type.rb +9 -9
  79. data/lib/contrast/agent/reporting/attack_result/user_input.rb +11 -0
  80. data/lib/contrast/agent/reporting/details/bot_blocker_details.rb +29 -0
  81. data/lib/contrast/agent/reporting/details/cmd_injection_details.rb +30 -0
  82. data/lib/contrast/agent/reporting/details/details.rb +18 -0
  83. data/lib/contrast/agent/reporting/details/http_method_tempering_details.rb +27 -0
  84. data/lib/contrast/agent/reporting/details/ip_denylist_details.rb +35 -0
  85. data/lib/contrast/agent/reporting/details/no_sqli_details.rb +36 -0
  86. data/lib/contrast/agent/reporting/details/path_traversal_details.rb +24 -0
  87. data/lib/contrast/agent/reporting/details/path_traversal_semantic_analysis_details.rb +32 -0
  88. data/lib/contrast/agent/reporting/details/protect_rule_details.rb +17 -0
  89. data/lib/contrast/agent/reporting/details/sqli_dangerous_functions.rb +22 -0
  90. data/lib/contrast/agent/reporting/details/sqli_details.rb +36 -0
  91. data/lib/contrast/agent/reporting/details/untrusted_deserialization_details.rb +27 -0
  92. data/lib/contrast/agent/reporting/details/virtual_patch_details.rb +30 -0
  93. data/lib/contrast/agent/reporting/details/xss_details.rb +33 -0
  94. data/lib/contrast/agent/reporting/details/xss_match.rb +30 -0
  95. data/lib/contrast/agent/reporting/details/xxe_details.rb +36 -0
  96. data/lib/contrast/agent/reporting/details/xxe_match.rb +25 -0
  97. data/lib/contrast/agent/reporting/details/xxe_wrapper.rb +25 -0
  98. data/lib/contrast/agent/reporting/input_analysis/details/bot_blocker_details.rb +27 -0
  99. data/lib/contrast/agent/reporting/input_analysis/details/protect_rule_details.rb +15 -0
  100. data/lib/contrast/agent/reporting/input_analysis/input_analysis.rb +1 -2
  101. data/lib/contrast/agent/reporting/input_analysis/input_analysis_result.rb +17 -3
  102. data/lib/contrast/agent/reporting/masker/masker.rb +80 -65
  103. data/lib/contrast/agent/reporting/masker/masker_utils.rb +1 -30
  104. data/lib/contrast/agent/reporting/reporter.rb +1 -15
  105. data/lib/contrast/agent/reporting/reporting_events/agent_startup.rb +2 -2
  106. data/lib/contrast/agent/reporting/reporting_events/application_activity.rb +84 -15
  107. data/lib/contrast/agent/reporting/reporting_events/application_defend_activity.rb +13 -25
  108. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_activity.rb +19 -24
  109. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample.rb +46 -126
  110. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample_activity.rb +5 -16
  111. data/lib/contrast/agent/reporting/reporting_events/application_defend_attacker_activity.rb +10 -18
  112. data/lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb +6 -14
  113. data/lib/contrast/agent/reporting/reporting_events/application_startup.rb +1 -1
  114. data/lib/contrast/agent/reporting/reporting_events/application_update.rb +0 -2
  115. data/lib/contrast/agent/reporting/reporting_events/architecture_component.rb +7 -22
  116. data/lib/contrast/agent/reporting/reporting_events/finding.rb +23 -53
  117. data/lib/contrast/agent/reporting/reporting_events/finding_event.rb +12 -9
  118. data/lib/contrast/agent/reporting/reporting_events/finding_event_signature.rb +1 -1
  119. data/lib/contrast/agent/reporting/reporting_events/finding_event_source.rb +23 -21
  120. data/lib/contrast/agent/reporting/reporting_events/finding_event_stack.rb +5 -18
  121. data/lib/contrast/agent/reporting/reporting_events/finding_event_taint_range.rb +1 -0
  122. data/lib/contrast/{api/decorators/trace_taint_range_tags.rb → agent/reporting/reporting_events/finding_event_taint_range_tags.rb} +7 -6
  123. data/lib/contrast/agent/reporting/reporting_events/finding_request.rb +40 -10
  124. data/lib/contrast/agent/reporting/reporting_events/library_discovery.rb +0 -1
  125. data/lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb +1 -1
  126. data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +2 -2
  127. data/lib/contrast/agent/reporting/reporting_events/poll.rb +1 -11
  128. data/lib/contrast/agent/reporting/reporting_events/preflight_message.rb +10 -14
  129. data/lib/contrast/agent/reporting/reporting_events/reporting_event.rb +11 -0
  130. data/lib/contrast/agent/reporting/reporting_events/route_coverage.rb +3 -1
  131. data/lib/contrast/agent/reporting/reporting_events/route_discovery.rb +12 -25
  132. data/lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb +8 -27
  133. data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +3 -3
  134. data/lib/contrast/agent/reporting/reporting_utilities/build_preflight.rb +4 -7
  135. data/lib/contrast/agent/reporting/reporting_utilities/headers.rb +1 -1
  136. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +2 -1
  137. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +3 -3
  138. data/lib/contrast/agent/reporting/reporting_utilities/response.rb +1 -1
  139. data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +0 -3
  140. data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +1 -0
  141. data/lib/contrast/agent/reporting/settings/code_exclusion.rb +6 -1
  142. data/lib/contrast/agent/reporting/settings/exclusion_base.rb +18 -0
  143. data/lib/contrast/agent/reporting/settings/exclusions.rb +2 -1
  144. data/lib/contrast/agent/reporting/settings/input_exclusion.rb +9 -3
  145. data/lib/contrast/agent/reporting/settings/protect.rb +15 -15
  146. data/lib/contrast/agent/request.rb +4 -14
  147. data/lib/contrast/agent/request_context.rb +18 -24
  148. data/lib/contrast/agent/request_context_extend.rb +23 -164
  149. data/lib/contrast/agent/request_handler.rb +1 -11
  150. data/lib/contrast/agent/response.rb +0 -18
  151. data/lib/contrast/agent/telemetry/events/event.rb +1 -1
  152. data/lib/contrast/agent/telemetry/events/metric_event.rb +1 -1
  153. data/lib/contrast/agent/telemetry/events/startup_metrics_event.rb +3 -3
  154. data/lib/contrast/agent/thread_watcher.rb +3 -18
  155. data/lib/contrast/agent/version.rb +1 -1
  156. data/lib/contrast/agent.rb +0 -11
  157. data/lib/contrast/agent_lib/api/command_injection.rb +46 -0
  158. data/lib/contrast/agent_lib/api/init.rb +101 -0
  159. data/lib/contrast/agent_lib/api/input_tracing.rb +267 -0
  160. data/lib/contrast/agent_lib/api/method_tempering.rb +29 -0
  161. data/lib/contrast/agent_lib/api/panic.rb +87 -0
  162. data/lib/contrast/agent_lib/api/path_semantic_file_security_bypass.rb +40 -0
  163. data/lib/contrast/agent_lib/interface.rb +260 -0
  164. data/lib/contrast/agent_lib/interface_base.rb +118 -0
  165. data/lib/contrast/agent_lib/return_types/eval_result.rb +44 -0
  166. data/lib/contrast/agent_lib/test.rb +29 -0
  167. data/lib/contrast/api/communication/connection_status.rb +5 -5
  168. data/lib/contrast/components/agent.rb +13 -23
  169. data/lib/contrast/components/api.rb +10 -10
  170. data/lib/contrast/components/app_context.rb +9 -11
  171. data/lib/contrast/components/app_context_extend.rb +1 -26
  172. data/lib/contrast/components/assess.rb +92 -38
  173. data/lib/contrast/components/assess_rules.rb +36 -0
  174. data/lib/contrast/components/config.rb +49 -24
  175. data/lib/contrast/components/heap_dump.rb +1 -1
  176. data/lib/contrast/components/protect.rb +9 -6
  177. data/lib/contrast/components/ruby_component.rb +81 -0
  178. data/lib/contrast/components/sampling.rb +1 -1
  179. data/lib/contrast/components/security_logger.rb +23 -0
  180. data/lib/contrast/components/settings.rb +41 -85
  181. data/lib/contrast/config/base_configuration.rb +1 -1
  182. data/lib/contrast/config/protect_rule_configuration.rb +7 -7
  183. data/lib/contrast/config/protect_rules_configuration.rb +24 -48
  184. data/lib/contrast/config/server_configuration.rb +1 -1
  185. data/lib/contrast/config.rb +0 -6
  186. data/lib/contrast/configuration.rb +73 -18
  187. data/lib/contrast/extension/assess/array.rb +9 -0
  188. data/lib/contrast/extension/assess/exec_trigger.rb +3 -1
  189. data/lib/contrast/extension/assess/marshal.rb +3 -2
  190. data/lib/contrast/extension/assess/string.rb +0 -1
  191. data/lib/contrast/extension/delegator.rb +2 -0
  192. data/lib/contrast/extension/extension.rb +1 -1
  193. data/lib/contrast/framework/base_support.rb +0 -5
  194. data/lib/contrast/framework/grape/support.rb +1 -23
  195. data/lib/contrast/framework/manager.rb +3 -11
  196. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +1 -6
  197. data/lib/contrast/framework/rails/railtie.rb +0 -1
  198. data/lib/contrast/framework/rails/support.rb +5 -59
  199. data/lib/contrast/framework/sinatra/support.rb +2 -21
  200. data/lib/contrast/logger/cef_log.rb +21 -3
  201. data/lib/contrast/logger/log.rb +1 -11
  202. data/lib/contrast/tasks/config.rb +5 -10
  203. data/lib/contrast/utils/assess/event_limit_utils.rb +28 -12
  204. data/lib/contrast/utils/assess/trigger_method_utils.rb +10 -18
  205. data/lib/contrast/utils/duck_utils.rb +1 -0
  206. data/lib/contrast/utils/findings.rb +6 -5
  207. data/lib/contrast/utils/hash_digest.rb +9 -24
  208. data/lib/contrast/utils/hash_digest_extend.rb +6 -6
  209. data/lib/contrast/utils/input_classification_base.rb +156 -0
  210. data/lib/contrast/utils/invalid_configuration_util.rb +21 -58
  211. data/lib/contrast/utils/log_utils.rb +47 -17
  212. data/lib/contrast/utils/net_http_base.rb +2 -2
  213. data/lib/contrast/utils/os.rb +0 -20
  214. data/lib/contrast/utils/patching/policy/patch_utils.rb +3 -2
  215. data/lib/contrast/utils/response_utils.rb +0 -16
  216. data/lib/contrast/utils/stack_trace_utils.rb +3 -40
  217. data/lib/contrast/utils/string_utils.rb +19 -7
  218. data/lib/contrast/utils/telemetry_client.rb +13 -7
  219. data/lib/contrast.rb +7 -13
  220. data/resources/protect/policy.json +1 -2
  221. data/ruby-agent.gemspec +2 -5
  222. metadata +78 -137
  223. data/exe/contrast_service +0 -23
  224. data/lib/contrast/agent/protect/rule/cmdi/cmdi_worth_watching.rb +0 -64
  225. data/lib/contrast/agent/protect/rule/sqli/sqli_worth_watching.rb +0 -118
  226. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_matcher.rb +0 -45
  227. data/lib/contrast/agent/reaction_processor.rb +0 -47
  228. data/lib/contrast/agent/reporting/reporting_events/trace_event_source.rb +0 -30
  229. data/lib/contrast/agent/reporting/reporting_utilities/dtm_message.rb +0 -43
  230. data/lib/contrast/agent/service_heartbeat.rb +0 -35
  231. data/lib/contrast/api/communication/messaging_queue.rb +0 -129
  232. data/lib/contrast/api/communication/response_processor.rb +0 -90
  233. data/lib/contrast/api/communication/service_lifecycle.rb +0 -77
  234. data/lib/contrast/api/communication/socket.rb +0 -44
  235. data/lib/contrast/api/communication/socket_client.rb +0 -130
  236. data/lib/contrast/api/communication/speedracer.rb +0 -142
  237. data/lib/contrast/api/communication/tcp_socket.rb +0 -32
  238. data/lib/contrast/api/communication/unix_socket.rb +0 -28
  239. data/lib/contrast/api/communication.rb +0 -20
  240. data/lib/contrast/api/decorators/activity.rb +0 -33
  241. data/lib/contrast/api/decorators/address.rb +0 -59
  242. data/lib/contrast/api/decorators/agent_startup.rb +0 -57
  243. data/lib/contrast/api/decorators/application_settings.rb +0 -42
  244. data/lib/contrast/api/decorators/application_startup.rb +0 -56
  245. data/lib/contrast/api/decorators/architecture_component.rb +0 -36
  246. data/lib/contrast/api/decorators/bot_blocker.rb +0 -37
  247. data/lib/contrast/api/decorators/finding.rb +0 -29
  248. data/lib/contrast/api/decorators/http_request.rb +0 -137
  249. data/lib/contrast/api/decorators/input_analysis.rb +0 -18
  250. data/lib/contrast/api/decorators/instrumentation_mode.rb +0 -35
  251. data/lib/contrast/api/decorators/ip_denylist.rb +0 -37
  252. data/lib/contrast/api/decorators/message.rb +0 -71
  253. data/lib/contrast/api/decorators/rasp_rule_sample.rb +0 -58
  254. data/lib/contrast/api/decorators/response_type.rb +0 -17
  255. data/lib/contrast/api/decorators/route_coverage.rb +0 -91
  256. data/lib/contrast/api/decorators/server_features.rb +0 -25
  257. data/lib/contrast/api/decorators/trace_event.rb +0 -120
  258. data/lib/contrast/api/decorators/trace_event_object.rb +0 -63
  259. data/lib/contrast/api/decorators/trace_event_signature.rb +0 -69
  260. data/lib/contrast/api/decorators/trace_taint_range.rb +0 -52
  261. data/lib/contrast/api/decorators/user_input.rb +0 -51
  262. data/lib/contrast/api/decorators/virtual_patch.rb +0 -34
  263. data/lib/contrast/api/decorators.rb +0 -28
  264. data/lib/contrast/api/dtm.pb.rb +0 -852
  265. data/lib/contrast/api/settings.pb.rb +0 -500
  266. data/lib/contrast/api.rb +0 -16
  267. data/lib/contrast/components/contrast_service.rb +0 -88
  268. data/lib/contrast/config/assess_configuration.rb +0 -93
  269. data/lib/contrast/config/assess_rules_configuration.rb +0 -32
  270. data/lib/contrast/config/root_configuration.rb +0 -90
  271. data/lib/contrast/config/ruby_configuration.rb +0 -81
  272. data/lib/contrast/config/service_configuration.rb +0 -49
  273. data/lib/contrast/tasks/service.rb +0 -84
  274. data/lib/contrast/utils/input_classification.rb +0 -73
  275. data/lib/contrast/utils/preflight_util.rb +0 -13
  276. data/lib/protobuf/code_generator.rb +0 -129
  277. data/lib/protobuf/decoder.rb +0 -28
  278. data/lib/protobuf/deprecation.rb +0 -117
  279. data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +0 -79
  280. data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +0 -360
  281. data/lib/protobuf/descriptors.rb +0 -3
  282. data/lib/protobuf/encoder.rb +0 -11
  283. data/lib/protobuf/enum.rb +0 -365
  284. data/lib/protobuf/exceptions.rb +0 -9
  285. data/lib/protobuf/field/base_field.rb +0 -380
  286. data/lib/protobuf/field/base_field_object_definitions.rb +0 -504
  287. data/lib/protobuf/field/bool_field.rb +0 -64
  288. data/lib/protobuf/field/bytes_field.rb +0 -67
  289. data/lib/protobuf/field/double_field.rb +0 -25
  290. data/lib/protobuf/field/enum_field.rb +0 -56
  291. data/lib/protobuf/field/field_array.rb +0 -102
  292. data/lib/protobuf/field/field_hash.rb +0 -122
  293. data/lib/protobuf/field/fixed32_field.rb +0 -25
  294. data/lib/protobuf/field/fixed64_field.rb +0 -28
  295. data/lib/protobuf/field/float_field.rb +0 -43
  296. data/lib/protobuf/field/int32_field.rb +0 -21
  297. data/lib/protobuf/field/int64_field.rb +0 -34
  298. data/lib/protobuf/field/integer_field.rb +0 -23
  299. data/lib/protobuf/field/message_field.rb +0 -51
  300. data/lib/protobuf/field/sfixed32_field.rb +0 -27
  301. data/lib/protobuf/field/sfixed64_field.rb +0 -28
  302. data/lib/protobuf/field/signed_integer_field.rb +0 -29
  303. data/lib/protobuf/field/sint32_field.rb +0 -21
  304. data/lib/protobuf/field/sint64_field.rb +0 -21
  305. data/lib/protobuf/field/string_field.rb +0 -51
  306. data/lib/protobuf/field/uint32_field.rb +0 -21
  307. data/lib/protobuf/field/uint64_field.rb +0 -21
  308. data/lib/protobuf/field/varint_field.rb +0 -77
  309. data/lib/protobuf/field.rb +0 -74
  310. data/lib/protobuf/generators/base.rb +0 -85
  311. data/lib/protobuf/generators/enum_generator.rb +0 -39
  312. data/lib/protobuf/generators/extension_generator.rb +0 -27
  313. data/lib/protobuf/generators/field_generator.rb +0 -193
  314. data/lib/protobuf/generators/file_generator.rb +0 -262
  315. data/lib/protobuf/generators/group_generator.rb +0 -122
  316. data/lib/protobuf/generators/message_generator.rb +0 -104
  317. data/lib/protobuf/generators/option_generator.rb +0 -17
  318. data/lib/protobuf/generators/printable.rb +0 -160
  319. data/lib/protobuf/generators/service_generator.rb +0 -50
  320. data/lib/protobuf/lifecycle.rb +0 -33
  321. data/lib/protobuf/logging.rb +0 -39
  322. data/lib/protobuf/message/fields.rb +0 -233
  323. data/lib/protobuf/message/serialization.rb +0 -85
  324. data/lib/protobuf/message.rb +0 -241
  325. data/lib/protobuf/optionable.rb +0 -72
  326. data/lib/protobuf/tasks/compile.rake +0 -80
  327. data/lib/protobuf/tasks.rb +0 -1
  328. data/lib/protobuf/varint.rb +0 -20
  329. data/lib/protobuf/varint_pure.rb +0 -31
  330. data/lib/protobuf/version.rb +0 -3
  331. data/lib/protobuf/wire_type.rb +0 -10
  332. data/lib/protobuf.rb +0 -91
  333. data/proto/dynamic_discovery.proto +0 -46
  334. data/proto/google/protobuf/compiler/plugin.proto +0 -183
  335. data/proto/google/protobuf/descriptor.proto +0 -911
  336. data/proto/rpc.proto +0 -71
  337. data/service_executables/.gitkeep +0 -0
  338. data/service_executables/VERSION +0 -1
  339. data/service_executables/linux/contrast-service +0 -0
  340. data/service_executables/mac/contrast-service +0 -0
@@ -6,7 +6,7 @@ require 'contrast/agent/reporting/reporting_events/application_reporting_event'
6
6
  module Contrast
7
7
  module Agent
8
8
  module Reporting
9
- # This is the new Poll class for the Heartbeat Service.
9
+ # This is the new Poll class for the Heartbeat to TeamServer.
10
10
  class Poll < Contrast::Agent::Reporting::ApplicationReportingEvent
11
11
  def initialize
12
12
  @event_type = :heartbeat
@@ -17,16 +17,6 @@ module Contrast
17
17
  def file_name
18
18
  'applications-heartbeat'
19
19
  end
20
-
21
- # This is commented out as I am not aware if we're supposed to send some information and/or parse it to hash
22
- # In https://github.com/Contrast-Security-Inc/contrast-service/blob/next/reporting/tsreporter.go
23
- #
24
- # Convert the instance variables on the class, and other information, into the identifiers required for
25
- # TeamServer to process the JSON form of this message.
26
- #
27
- # @return [Hash]
28
- # @raise [ArgumentError]
29
- # def to_controlled_hash; end
30
20
  end
31
21
  end
32
22
  end
@@ -1,9 +1,10 @@
1
1
  # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
+ require 'contrast/agent/reporting/reporting_events/reporting_event'
4
5
  require 'contrast/components/assess'
5
6
  require 'contrast/components/logger'
6
- require 'contrast/agent/reporting/reporting_events/reporting_event'
7
+ require 'contrast/utils/string_utils'
7
8
 
8
9
  module Contrast
9
10
  module Agent
@@ -13,6 +14,8 @@ module Contrast
13
14
  # identifying information of a Finding/Trace, which TeamServer will use to determine if it requires the full
14
15
  # information of the Finding/Trace to be reported.
15
16
  class PreflightMessage
17
+ include Contrast::Components::Logger::InstanceMethods
18
+
16
19
  # @return [String] the message identifier; rule_id,hash
17
20
  attr_accessor :data
18
21
  # @return [String] CRC checksum of the finding to which this message pertains
@@ -26,9 +29,6 @@ module Contrast
26
29
  CODE = :TRACE
27
30
 
28
31
  def initialize
29
- @app_language = Contrast::Utils::ObjectShare::RUBY
30
- @app_name = ::Contrast::APP_CONTEXT.name # rubocop:disable Security/Module/Name
31
- @app_version = ::Contrast::APP_CONTEXT.version
32
32
  @routes = []
33
33
  end
34
34
 
@@ -47,24 +47,20 @@ module Contrast
47
47
 
48
48
  {
49
49
  code: CODE,
50
- app_language: @app_language,
51
- app_name: @app_name,
52
- app_version: @app_version,
50
+ app_language: Contrast::Utils::ObjectShare::RUBY,
51
+ app_name: ::Contrast::APP_CONTEXT.name, # rubocop:disable Security/Module/Name
52
+ app_version: ::Contrast::APP_CONTEXT.version,
53
53
  data: '',
54
54
  key: 0,
55
- routes: @routes,
55
+ routes: @routes.map(&:to_controlled_hash),
56
56
  session_id: ::Contrast::ASSESS.session_id
57
57
  }
58
58
  end
59
59
 
60
60
  # @raise [ArgumentError]
61
61
  def validate
62
- raise(ArgumentError, "#{ cs__class } did not have a proper data. Unable to continue.") unless data
63
- unless @app_name
64
- raise(ArgumentError, "#{ cs__class } did not have a proper application name. Unable to continue.")
65
- end
66
- unless @app_language
67
- raise(ArgumentError, "#{ cs__class } did not have a proper application language. Unable to continue.")
62
+ unless Contrast::Utils::StringUtils.present?(data)
63
+ raise(ArgumentError, "#{ cs__class } did not have a proper data. Unable to continue.")
68
64
  end
69
65
  unless ::Contrast::ASSESS.session_id
70
66
  raise(ArgumentError, "#{ cs__class } did not have a proper session id. Unable to continue.")
@@ -49,6 +49,17 @@ module Contrast
49
49
 
50
50
  # @raise [ArgumentError]
51
51
  def validate; end
52
+
53
+ # Helper method to get json representation of event and handle errors
54
+ #
55
+ # @return [String] - JSON
56
+ def event_json
57
+ hsh = to_controlled_hash
58
+ hsh.to_json
59
+ rescue Exception => e # rubocop:disable Lint/RescueException
60
+ logger.error('Unable to convert JSON string', e, hsh)
61
+ raise(e)
62
+ end
52
63
  end
53
64
  end
54
65
  end
@@ -42,7 +42,9 @@ module Contrast
42
42
  # @param url [String] the literal url of the route actively being executed
43
43
  # @return [Contrast::Agent::Reporting::RouteCoverage]
44
44
  def attach_rack_based_data final_controller, method, route_pattern, url = nil
45
- if route_pattern.cs__is_a?(Grape::Router::Route)
45
+ if Contrast::Utils::ClassUtil.truly_defined?('Grape::Router::Route') &&
46
+ route_pattern.cs__is_a?(Grape::Router::Route)
47
+
46
48
  safe_pattern = route_pattern.pattern&.path&.to_s
47
49
  safe_url = source_or_string(url || safe_pattern)
48
50
  else
@@ -2,7 +2,6 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/agent/reporting/reporting_events/route_discovery_observation'
5
- require 'contrast/api/dtm.pb'
6
5
  require 'contrast/components/logger'
7
6
 
8
7
  module Contrast
@@ -14,34 +13,22 @@ module Contrast
14
13
  # externally accessible endpoints within the application, as registered to the application framework. They may or
15
14
  # may not have been invoked at the time of reporting.
16
15
  #
17
- # @attr_reader observations [observations] the routes and verbs seen that match to this Route
18
- # @attr_reader signature [String] the unique identifier for this route; typically the method signature. Required
19
- # for reporting.
20
16
  class RouteDiscovery
21
17
  include Contrast::Components::Logger::InstanceMethods
22
18
 
23
- # required attributes
24
- attr_reader :observations, :signature
25
-
26
- class << self
27
- # Convert a DTM for SpeedRacer to an Event for TeamServer.
28
- #
29
- # @param route_coverage_dtm [Contrast::Api::Dtm::RouteCoverage]
30
- # @return [Contrast::Agent::Reporting::RouteDiscovery]
31
- def convert route_coverage_dtm
32
- report = new
33
- report.attach_data(route_coverage_dtm)
34
- report
35
- end
36
- end
37
-
38
- # Attach the data from the protobuf models to this reporter so that it can be sent to TeamServer directly
39
- #
40
- # @param route_coverage_dtm [Contrast::Api::Dtm::RouteCoverage]
41
- def attach_data route_coverage_dtm
42
- @signature = route_coverage_dtm.route
19
+ # @return [Array<Contrast::Agent::Reporting::RouteDiscoveryObservation>] the routes and verbs seen that match
20
+ # to this Route.
21
+ attr_reader :observations
22
+ # @return [String] the unique identifier for this route; typically the method signature. Required for
23
+ # reporting.
24
+ attr_accessor :signature
25
+
26
+ # @param signature [String]
27
+ # @param observation [Contrast::Agent::Reporting::RouteDiscoveryObservation]
28
+ def initialize signature, observation
29
+ @signature = signature
43
30
  @observations = []
44
- observations << Contrast::Agent::Reporting::RouteDiscoveryObservation.convert(route_coverage_dtm)
31
+ observations << observation
45
32
  end
46
33
 
47
34
  # Convert the instance variables on the class, and other information, into the identifiers required for
@@ -1,7 +1,6 @@
1
1
  # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'contrast/api/dtm.pb'
5
4
  require 'contrast/utils/string_utils'
6
5
  require 'contrast/components/logger'
7
6
 
@@ -12,36 +11,18 @@ module Contrast
12
11
  # reporting system to relay this information in the Application Update messages. These route observations are
13
12
  # used by TeamServer to construct the route coverage information for the assess feature. They represent the
14
13
  # literal URL and HTTP verb used to invoke a method in the application, as routed by the application framework.
15
- #
16
- # @attr_reader url [String] the URL requested to hit this endpoint. Required for reporting.
17
- # @attr_reader verb [String] the HTTP Method requested to his this endpoint. Empty means all, so is allowed.
18
- # for reporting.
19
14
  class RouteDiscoveryObservation
20
15
  include Contrast::Components::Logger::InstanceMethods
21
16
 
22
- # required attributes
23
- attr_reader :url
24
- # optional attributes
25
- attr_reader :verb
17
+ # @return [String] the URL requested to hit this endpoint. Required for reporting; required attributes
18
+ attr_accessor :url
19
+ # @return [String] the HTTP Method requested to his this endpoint. Empty means all, so is allowed for
20
+ # reporting; optional attributes
21
+ attr_accessor :verb
26
22
 
27
- class << self
28
- # Convert a DTM for SpeedRacer to an Event for TeamServer.
29
- #
30
- # @param route_coverage_dtm [Contrast::Api::Dtm::RouteCoverage]
31
- # @return [Contrast::Agent::Reporting::RouteDiscoveryObservation]
32
- def convert route_coverage_dtm
33
- report = new
34
- report.attach_data(route_coverage_dtm)
35
- report
36
- end
37
- end
38
-
39
- # Attach the data from the protobuf models to this reporter so that it can be sent to TeamServer directly
40
- #
41
- # @param route_coverage_dtm [Contrast::Api::Dtm::RouteCoverage]
42
- def attach_data route_coverage_dtm
43
- @url = route_coverage_dtm.url
44
- @verb = route_coverage_dtm.verb if Contrast::Utils::StringUtils.present?(route_coverage_dtm.verb)
23
+ def initialize url, verb
24
+ @url = url
25
+ @verb = verb if Contrast::Utils::StringUtils.present?(verb)
45
26
  end
46
27
 
47
28
  # Convert the instance variables on the class, and other information, into the identifiers required for
@@ -19,8 +19,8 @@ module Contrast
19
19
  generate_paths if enabled?
20
20
  end
21
21
 
22
- # This method will be handling the auditing of the requests and responses we send to SpeedRacer. If the audit
23
- # feature is enabled, we'll log to file the request and/or response protobuf objects.
22
+ # This method will be handling the auditing of the requests and responses we send to TeamServer. If the audit
23
+ # feature is enabled, we'll log to file the request and/or response JSON objects.
24
24
  #
25
25
  # @param event [Contrast::Agent::Reporting::ReportingEvent] One of the DTMs valid for the
26
26
  # event field of Contrast::Agent::Reporting::ReportingEvent
@@ -29,7 +29,7 @@ module Contrast
29
29
  return unless ::Contrast::API.request_audit_requests || ::Contrast::API.request_audit_responses
30
30
 
31
31
  file_name = event.cs__respond_to?(:file_name) ? event.file_name : event.cs__class.cs__name.to_s.downcase
32
- data = event.to_controlled_hash.to_json
32
+ data = event.event_json
33
33
  log_data(:request, file_name, data) if data
34
34
  return unless ::Contrast::API.request_audit_responses
35
35
 
@@ -14,17 +14,14 @@ module Contrast
14
14
  module BuildPreflight
15
15
  class << self
16
16
  # @param finding [Contrast::Agent::Reporting::Finding]
17
- # @param request [Contrast::Agent::Request] current request
18
- def build finding, request
17
+ # @return [Contrast::Agent::Reporting::Preflight, nil]
18
+ def generate finding
19
19
  return unless finding
20
20
 
21
- # save the current finding
22
- Contrast::Agent::Reporting::ReportingStorage[finding.hash_code] = finding
23
-
24
21
  new_preflight = Contrast::Agent::Reporting::Preflight.new
25
22
  new_preflight_message = Contrast::Agent::Reporting::PreflightMessage.new
26
- if request&.route
27
- new_preflight_message.routes << Contrast::Agent::Reporting::RouteDiscovery.convert(request.route)
23
+ finding.routes.each do |route|
24
+ new_preflight_message.routes << route
28
25
  end
29
26
  new_preflight_message.hash_code = finding.hash_code
30
27
  new_preflight_message.data = "#{ finding.rule_id },#{ finding.hash_code }"
@@ -32,7 +32,7 @@ module Contrast
32
32
  @encoding = ENCODING
33
33
  end
34
34
 
35
- def to_hash
35
+ def to_contrast_hash
36
36
  {
37
37
  app_name: @app_name,
38
38
  api_key: @api_key,
@@ -43,7 +43,6 @@ module Contrast
43
43
  # @param connection [Net::HTTP] open connection
44
44
  def startup! connection
45
45
  return if status.startup_messages_sent?
46
- return unless Contrast::Agent::Reporter.enabled?
47
46
 
48
47
  send_agent_startup(connection)
49
48
  end
@@ -57,6 +56,8 @@ module Contrast
57
56
  def send_event event, connection
58
57
  return unless connection
59
58
 
59
+ logger.debug('Preparing to send reporting event', event_class: event.cs__class)
60
+
60
61
  request = build_request(event)
61
62
  response = connection.request(request)
62
63
  audit&.audit_event(event, response) if ::Contrast::API.request_audit_enable
@@ -69,7 +69,7 @@ module Contrast
69
69
  # Handles standard error case, logs and set status for failure
70
70
  #
71
71
  # @param event [Contrast::Agent::Reporting::ReportingEvent]
72
- # One of the DTMs valid for the event field of Contrast::Api::Dtm::Message|Contrast::Api::Dtm::Activity
72
+ # One of the DTMs valid for the event field of Contrast::Api::Dtm::Message
73
73
  # @param error_msg [StandardError]
74
74
  # @return nil [NilClass] to be passed as response
75
75
  def handle_error event, error_msg
@@ -105,7 +105,7 @@ module Contrast
105
105
  findings_to_return = response.body.split(',').delete_if { |el| el.include?('*') }
106
106
  findings_to_return.each do |index|
107
107
  preflight_message = event.messages[index.to_i]
108
- corresponding_finding = Contrast::Agent::Reporting::ReportingStorage.delete(preflight_message.hash_code)
108
+ corresponding_finding = Contrast::Agent::Reporting::ReportingStorage.delete(preflight_message.data)
109
109
  next unless corresponding_finding
110
110
 
111
111
  send_event(corresponding_finding, connection)
@@ -130,7 +130,7 @@ module Contrast
130
130
  end
131
131
  build_headers(request)
132
132
  event.attach_headers(request)
133
- request.body = event.to_controlled_hash.to_json
133
+ request.body = event.event_json
134
134
  request
135
135
  end
136
136
  end
@@ -19,7 +19,7 @@ module Contrast
19
19
 
20
20
  # All of the feature server_features
21
21
  #
22
- # @return [Contrast::Agent::Reporting::Settings::FeatureSettings, nil]
22
+ # @return [Contrast::Agent::Reporting::Settings::ServerFeatures, nil]
23
23
  attr_accessor :server_features
24
24
 
25
25
  # Success boolean message value
@@ -1,12 +1,9 @@
1
1
  # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'contrast/api/communication/response_processor'
5
- require 'contrast/api/decorators/application_settings'
6
4
  require 'contrast/agent/reporting/reporting_utilities/response'
7
5
  require 'contrast/agent/reporting/reporting_utilities/response_handler_utils'
8
6
  require 'contrast/agent/reporting/reporting_utilities/response_handler_mode'
9
- require 'contrast/api/decorators/server_features'
10
7
  require 'contrast/components/logger'
11
8
  require 'json'
12
9
 
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/agent/reporting/reporting_utilities/response_extractor'
5
+ require 'contrast/agent/disable_reaction'
5
6
 
6
7
  module Contrast
7
8
  module Agent
@@ -12,9 +12,14 @@ module Contrast
12
12
  ATTRIBUTES = BASE_ATTRIBUTES.dup << :denylist
13
13
  ATTRIBUTES.cs__freeze
14
14
 
15
- # @return denylist [Array<String>] #rubocop:disable [Naming/InclusiveLanguage]
15
+ # @return [Array<String>]
16
16
  attr_accessor :denylist
17
17
 
18
+ def initialize
19
+ super
20
+ @denylist = []
21
+ end
22
+
18
23
  def to_controlled_hash
19
24
  hash = super
20
25
  hash[:denylist] = denylist
@@ -18,6 +18,24 @@ module Contrast
18
18
  # @return protect_rules [Array<String>]
19
19
  attr_accessor :protect_rules
20
20
 
21
+ def initialize
22
+ @modes = []
23
+ @assess_rules = []
24
+ @protect_rules = []
25
+ end
26
+
27
+ # @return [Boolean] does this exclusion apply to Assess or not
28
+ def assess
29
+ @_assess = modes&.include?('assess') if @_assess.nil?
30
+ @_assess
31
+ end
32
+
33
+ # @return [Boolean] does this exclusion apply to Protect or not
34
+ def protect
35
+ @_protect = modes&.include?('defend') if @_protect.nil?
36
+ @_protect
37
+ end
38
+
21
39
  def to_controlled_hash
22
40
  {
23
41
  name: name, # rubocop:disable Security/Module/Name
@@ -26,6 +26,7 @@ module Contrast
26
26
  # @param new_code_exclusions [Array<CodeExclusion>] Array of CodeExclusion: {
27
27
  # name [String] The name of the exclusion as defined by the user in TS.
28
28
  # modes [String] If this exclusion applies to assess or protect. [assess, defend]
29
+ # protect_rules [Array] Array of ProtectRuleID [String] The protect rules to which this exclusion applies.
29
30
  # assess_rules [Array] Array of assess rules to which this exclusion applies. AssessRuleID [String]
30
31
  # denylist [String] The call, if in the stack, should result in the agent not taking action.
31
32
  # }
@@ -39,7 +40,7 @@ module Contrast
39
40
 
40
41
  # Cases where rules should be excluded if violated from a given input.
41
42
  #
42
- # @return input_exclusions [Array<Contrast::Agent::Reporting::Settings::InputExclusions>]
43
+ # @return input_exclusions [Array<Contrast::Agent::Reporting::Settings::InputExclusion>]
43
44
  # Array of InputExclusions
44
45
  def input_exclusions
45
46
  @_input_exclusions ||= []
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'contrast/agent/reporting/settings/exclusion_base'
4
+ require 'contrast/agent/reporting/settings/url_exclusion'
5
5
  require 'contrast/utils/object_share'
6
6
 
7
7
  module Contrast
@@ -9,11 +9,17 @@ module Contrast
9
9
  module Reporting
10
10
  module Settings
11
11
  # InputExclusions class
12
- class InputExclusion < ExclusionBase
13
- ATTRIBUTES = BASE_ATTRIBUTES.dup << :type
12
+ class InputExclusion < UrlExclusion
13
+ ATTRIBUTES = UrlExclusion::ATTRIBUTES.dup << :type
14
14
  ATTRIBUTES.cs__freeze
15
15
  VALID_INPUT_TYPES = %w[COOKIE PARAMETER HEADER BODY QUERYSTRING].cs__freeze
16
16
 
17
+ # @return [String] the name of the input to match
18
+ attr_accessor :input_name
19
+
20
+ # @return [String] the type of the input to match
21
+ attr_accessor :input_type
22
+
17
23
  # @return type [String] The type of the input
18
24
  def type
19
25
  @_type ||= Contrast::Utils::ObjectShare::EMPTY_STRING
@@ -2,8 +2,6 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/utils/object_share'
5
- require 'contrast/api/dtm.pb'
6
- require 'contrast/api/settings.pb'
7
5
 
8
6
  module Contrast
9
7
  module Agent
@@ -79,23 +77,25 @@ module Contrast
79
77
 
80
78
  modes_by_id = {}
81
79
  protection_rules.each do |rule|
82
- setting_mode = rule[:mode]
83
- next unless PROTECT_RULES_MODE.include?(setting_mode)
84
-
85
- api_mode = case setting_mode
86
- when PROTECT_RULES_MODE[1]
87
- ::Contrast::Api::Settings::ProtectionRule::Mode::MONITOR
88
- when PROTECT_RULES_MODE[2]
89
- if rule[:blockAtEntry]
90
- ::Contrast::Api::Settings::ProtectionRule::Mode::BLOCK_AT_PERIMETER
80
+ setting_mode = rule[:mode] || rule['mode']
81
+ api_mode = if PROTECT_RULES_MODE.include?(setting_mode)
82
+ case setting_mode
83
+ when PROTECT_RULES_MODE[1]
84
+ :MONITOR
85
+ when PROTECT_RULES_MODE[2]
86
+ if rule[:blockAtEntry] || rule['blockAtEntry']
87
+ :BLOCK_AT_PERIMETER
88
+ else
89
+ :BLOCK
90
+ end
91
91
  else
92
- ::Contrast::Api::Settings::ProtectionRule::Mode::BLOCK
92
+ :NO_ACTION
93
93
  end
94
94
  else
95
- ::Contrast::Api::Settings::ProtectionRule::Mode::NO_ACTION
95
+ setting_mode.to_sym
96
96
  end
97
-
98
- modes_by_id[rule[:id]] = api_mode
97
+ id = rule[:id] || rule['id']
98
+ modes_by_id[id] = api_mode
99
99
  end
100
100
  modes_by_id
101
101
  end
@@ -33,10 +33,10 @@ module Contrast
33
33
 
34
34
  # @return [Rack::Request] The passed to the Agent RackRequest to be wrapped.
35
35
  attr_reader :rack_request
36
- # @return [Contrast::Api::Dtm::RouteCoverage] the route, used for findings, of this request
37
- attr_accessor :route
38
36
  # @return [Contrast::Agent::Reporting::ObservedRoute] the route, used for coverage, of this request
39
37
  attr_accessor :observed_route
38
+ # @return [Contrast::Agent::Reporting::RouteDiscovery]
39
+ attr_accessor :discovered_route
40
40
 
41
41
  # Delegate calls to the following methods to the attribute @rack_request
42
42
  def_delegators :@rack_request, :base_url, :cookies, :env, :ip, :media_type, :path, :port, :query_string,
@@ -74,7 +74,8 @@ module Contrast
74
74
  # @return uri [String]
75
75
  def normalized_uri
76
76
  @_normalized_uri ||= begin
77
- path = rack_request.path_info
77
+ path = rack_request.path_info || rack_request.path.to_s
78
+ path = '/' if path.empty?
78
79
  uri = path.split(Contrast::Utils::ObjectShare::SEMICOLON)[0] # remove ;jsessionid
79
80
  uri = uri.split(Contrast::Utils::ObjectShare::QUESTION_MARK)[0] # remove ?query_string=
80
81
  uri.gsub(INNER_REST_TOKEN, INNER_NUMBER_MARKER) # replace interior tokens
@@ -142,17 +143,6 @@ module Contrast
142
143
  @_body
143
144
  end
144
145
 
145
- # Unlike most of our translation, which is called where needed for each
146
- # message and forgotten, we'll leave this method to call the build as we
147
- # don't want to pay to reconstruct the DTM for this Request multiple
148
- # times.
149
- #
150
- # @return [Contrast::Api::Dtm::HttpRequest] the SpeedRacer compatible
151
- # form of this Request
152
- def dtm
153
- @_dtm ||= Contrast::Api::Dtm::HttpRequest.build(self)
154
- end
155
-
156
146
  # flattened hash of request params
157
147
  #
158
148
  # @return parameters [Hash]
@@ -1,7 +1,6 @@
1
1
  # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'contrast/api/dtm.pb'
5
4
  require 'contrast/utils/timer'
6
5
  require 'contrast/agent/request'
7
6
  require 'contrast/agent/response'
@@ -12,6 +11,7 @@ require 'contrast/utils/request_utils'
12
11
  require 'contrast/agent/request_context_extend'
13
12
  require 'contrast/agent/reporting/reporting_events/observed_route'
14
13
  require 'contrast/agent/reporting/input_analysis/input_analysis'
14
+ require 'contrast/agent/reporting/reporting_events/application_activity'
15
15
 
16
16
  module Contrast
17
17
  module Agent
@@ -23,9 +23,9 @@ module Contrast
23
23
  include Contrast::Utils::RequestUtils
24
24
  include Contrast::Agent::RequestContextExtend
25
25
 
26
- EMPTY_INPUT_ANALYSIS_PB = Contrast::Api::Settings::InputAnalysis.new
26
+ INPUT_ANALYSIS = Contrast::Agent::Reporting::InputAnalysis.new
27
27
 
28
- # @return [Contrast::Api::Dtm::Activity] the application activity found in this request
28
+ # @return [Contrast::Agent::Reporting:ApplicationActivity] the application activity found in this request
29
29
  attr_reader :activity
30
30
  # @return [Hash] context used to log the request
31
31
  attr_reader :logging_hash
@@ -36,10 +36,12 @@ module Contrast
36
36
  # @return [Contrast::Agent::Response] our wrapper around the Rack::Response or Array for this context,
37
37
  # only available after the application has finished its processing
38
38
  attr_reader :response
39
- # @return [Contrast::Api::Dtm::RouteCoverage] the route, used for findings, of this request
40
- attr_reader :route
41
- # @return [Contrast::Api::Settings::InputAnalysis] the protect input analysis of sources on this request
42
- attr_reader :speedracer_input_analysis
39
+ # @return [Contrast::Agent::Reporting::RouteDiscovery] the route, used for findings, of this request
40
+ attr_reader :discovered_route
41
+ # @return [Contrast::Agent::Reporting::InputAnalysis]
42
+ attr_reader :agent_input_analysis
43
+ # @return [Array<String>] the hash of findings already reported fro this request
44
+ attr_reader :reported_findings
43
45
  # @return [Contrast::Utils::Timer] when the context was created
44
46
  attr_reader :timer
45
47
 
@@ -52,17 +54,13 @@ module Contrast
52
54
  @logging_hash = { request_id: __id__ }
53
55
 
54
56
  # instantiate helper for request and response
55
- @request = Contrast::Agent::Request.new(rack_request)
56
-
57
- @activity = Contrast::Api::Dtm::Activity.new
58
- @activity.http_request = request.dtm
57
+ @request = Contrast::Agent::Request.new(rack_request) if rack_request
58
+ @activity = Contrast::Agent::Reporting::ApplicationActivity.new
59
59
 
60
60
  # build analyzer
61
61
  @do_not_track = false
62
- @speedracer_input_analysis = EMPTY_INPUT_ANALYSIS_PB
63
- speedracer_input_analysis.request = request
64
-
65
- # TODO: RUBY-1627
62
+ @agent_input_analysis = INPUT_ANALYSIS
63
+ agent_input_analysis.request = request
66
64
 
67
65
  # flag to indicate whether the app is fully loaded
68
66
  @app_loaded = !!app_loaded
@@ -80,6 +78,8 @@ module Contrast
80
78
  @sample_req, @sample_res = Contrast::Utils::Assess::SamplingUtil.instance.sample?(@request)
81
79
  end
82
80
 
81
+ @reported_findings = []
82
+
83
83
  handle_routes
84
84
  end
85
85
  end
@@ -125,7 +125,7 @@ module Contrast
125
125
  end
126
126
 
127
127
  def reset_activity
128
- @activity = Contrast::Api::Dtm::Activity.new(http_request: request.dtm)
128
+ @activity = Contrast::Agent::Reporting::ApplicationActivity.new
129
129
  @observed_route = Contrast::Agent::Reporting::ObservedRoute.new
130
130
  end
131
131
 
@@ -133,14 +133,8 @@ module Contrast
133
133
 
134
134
  def handle_routes
135
135
  @observed_route = Contrast::Agent::Reporting::ObservedRoute.new
136
- # TODO: RUBY-1705 when we no longer need the DTM style, delete this method and use the get_route_information
137
- # instead.
138
- route_dtm = Contrast::Agent.framework_manager.get_route_dtm(@request)
139
- # new_route_coverage_dtm = Contrast::Agent.framework_manager.get_route_information(@request)
140
- # TODO: RUBY-1705 -- delete append_route_coverage
141
- append_route_coverage(route_dtm)
142
- # TODO: RUBY-1705 -- change to take [Contrast::Agent::Reporting::ObservedRoute]
143
- append_to_observed_route(route_dtm)
136
+ reporting_route = Contrast::Agent.framework_manager.get_route_information(@request)
137
+ append_to_observed_route(reporting_route)
144
138
  end
145
139
  end
146
140
  end