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
@@ -3,12 +3,14 @@
3
3
 
4
4
  require 'contrast/agent/assess/events/event_factory'
5
5
  require 'contrast/agent/assess/policy/trigger_validation/trigger_validation'
6
+ require 'contrast/agent/excluder'
6
7
  require 'contrast/components/logger'
7
8
  require 'contrast/utils/object_share'
8
9
  require 'contrast/utils/sha256_builder'
9
10
  require 'contrast/utils/assess/trigger_method_utils'
10
11
  require 'contrast/agent/assess/events/event_data'
11
12
  require 'contrast/agent/reporting/reporting_events/preflight'
13
+ require 'contrast/agent/reporting/reporting_events/application_activity'
12
14
  require 'contrast/agent/reporting/reporting_events/preflight_message'
13
15
  require 'contrast/agent/reporting/reporting_events/route_discovery'
14
16
  require 'contrast/agent/reporting/reporting_utilities/reporting_storage'
@@ -21,18 +23,14 @@ module Contrast
21
23
  # A trigger method is one which can perform a dangerous action, as described by the
22
24
  # Contrast::Agent::Assess::Policy::TriggerNode class. Each such method will call to this module just after
23
25
  # invocation in order to determine if the call was done safely. In those cases where it was not, a Finding
24
- # report is issued to the Service.
25
- module TriggerMethod # rubocop:disable Metrics/ModuleLength
26
+ # report is issued to TeamServer.
27
+ module TriggerMethod
26
28
  extend Contrast::Components::Logger::InstanceMethods
27
29
  extend Contrast::Utils::Assess::TriggerMethodUtils
28
30
  extend Contrast::Utils::Assess::EventLimitUtils
29
31
 
30
- # The level of TeamServer compliance our traces meet when in the abnormal condition of being dataflow rules
31
- # without routes.
32
- MINIMUM_FINDING_VERSION = 3
33
- # The level of TeamServer compliance our traces meet.
34
- CURRENT_FINDING_VERSION = 4
35
32
  # Rules that always exists outside of Request Context
33
+ # @return [Array<String>]
36
34
  NON_REQUEST_RULES = [
37
35
  'hardcoded-password', # Contrast::Agent::Assess::Rule::Provider::HardcodedPassword.NAME,
38
36
  'hardcoded-key' # Contrast::Agent::Assess::Rule::Provider::HardcodedKey.NAME
@@ -57,7 +55,9 @@ module Contrast
57
55
  # else proceed, if the flag is true we don't need to check for context we
58
56
  # go as currently.
59
57
  # When outside of a request, only track when the feature is enabled
60
- return unless Contrast::ASSESS.non_request_tracking? || context
58
+ return unless context ||
59
+ Contrast::ASSESS.non_request_tracking? ||
60
+ NON_REQUEST_RULES.include?(trigger_node.rule_id)
61
61
 
62
62
  if trigger_node.sources&.any?
63
63
  trigger_node.sources.each do |marker|
@@ -73,95 +73,57 @@ module Contrast
73
73
  apply_trigger(trigger_node, source, object, ret, *args)
74
74
  end
75
75
 
76
- def append_to_finding finding, event_data, request
77
- finding.rule_id = Contrast::Utils::StringUtils.protobuf_safe_string(event_data.policy_node.rule_id)
78
- finding.version = determine_compliance_version(finding)
79
- append_events(finding, event_data)
80
- append_route(finding, request)
81
- append_hash(finding, event_data.tagged, request)
82
- end
83
-
84
76
  # This converts the source of the finding, and the events leading up to it into a Finding
85
77
  #
86
78
  # @param trigger_node [Contrast::Agent::Assess::Policy::TriggerNode] the node to direct applying this
87
79
  # trigger event
88
80
  # @param source [Object] the source of the Trigger Event
89
81
  # @param object [Object] the Object on which the method was invoked
90
- # @param ret [Object] the Return of the invoked method
82
+ # @param ret [Object, nil] the Return of the invoked method, or nil if void method
91
83
  # @param args [Array<Object>] the Arguments with which the method was invoked
92
- # @return [Contrast::Api::Dtm::Finding, nil] the Contrast::Api::Dtm::Finding to send to TeamServer or
93
- # nil if conditions were not met
84
+ # @return [Contrast::Agent::Reporting::Finding, nil] the finding to send to TeamServer if found
94
85
  def build_finding trigger_node, source, object, ret, *args
95
86
  content_type = Contrast::Agent::REQUEST_TRACKER.current&.response&.content_type
96
-
97
87
  if content_type.nil? && trigger_node.collectable?
98
88
  Contrast::Agent::FINDINGS.collect_finding(trigger_node, source, object, ret, *args)
99
89
  return
100
90
  end
101
-
102
91
  return unless Contrast::Agent::Assess::Policy::TriggerValidation.valid?(trigger_node, object, ret, args)
103
92
 
104
93
  request = find_request(source)
105
94
  return unless reportable?(request&.env)
95
+ return if excluded_by_url_and_rule?(request, trigger_node.rule_id)
106
96
 
107
- process_reportable_finding(trigger_node, source, object, ret, request, *args)
97
+ finding = Contrast::Agent::Reporting::Finding.new(trigger_node.rule_id)
98
+ finding.attach_data(trigger_node, source, object, ret, request, *args)
99
+ return if excluded_by_input_and_rule?(request, finding, trigger_node.rule_id)
100
+
101
+ finding.hash_code = Contrast::Utils::HashDigest.generate_event_hash(finding, source, request)
102
+ finding
108
103
  rescue StandardError => e
109
104
  logger.error('Unable to build a finding', e, rule: trigger_node.rule_id, node_id: trigger_node.id)
105
+ nil
110
106
  end
111
107
 
112
- def process_reportable_finding trigger_node, source, object, ret, request, *args
113
- if Contrast::Agent::Reporter.enabled?
114
- handle_new_finding(trigger_node, source, object, ret, request, *args)
115
- else # TODO: RUBY-1438 -- remove
116
- finding = Contrast::Api::Dtm::Finding.new
117
- event_data = Contrast::Agent::Assess::Events::EventData.new(trigger_node, source, object, ret, args)
118
- append_to_finding(finding, event_data, request)
119
- logger.trace('Finding created', node_id: trigger_node.id, source_id: source.__id__,
120
- rule: trigger_node.rule_id)
121
- report_finding(finding, request)
122
- end
123
- end
124
-
125
- # Given a finding, append it to an activity message and send it to the Service for processing. If an
108
+ # Given a finding, append it to an activity message and send it to the TeamServer for processing. If an
126
109
  # activity message does not exist, b/c we're invoked outside of a request context, build an activity and
127
110
  # immediately report it with the finding.
128
111
  #
129
- # TODO: RUBY-1351
130
- #
131
- # @param finding [Contrast::Api::Dtm::Finding] the Finding to report.
132
- # @param request [Contrast::Agent::Request] our wrapper around the Rack::Request.
133
- def report_finding finding, request = nil
134
- context = Contrast::Agent::REQUEST_TRACKER.current
135
- if context
136
- context.activity.findings << finding
137
- return
138
- end
139
-
140
- return unless ::Contrast::ASSESS.non_request_tracking? || NON_REQUEST_RULES.include?(finding.rule_id)
112
+ # @param finding [Contrast::Agent::Reporting::Finding] the Finding to report.
113
+ def report_finding finding
114
+ return unless finding
141
115
 
142
- activity = Contrast::Api::Dtm::Activity.new
143
- activity.findings << finding
144
- if request
145
- activity.http_request = request.dtm
146
- else
147
- logger.debug('Attempted to report finding without request', finding: finding)
148
- end
149
-
150
- # If we're out of request context, then we need to report this finding ourselves,
151
- # so we'll send it in the one-off activity we created.
152
- Contrast::Agent.messaging_queue&.send_event_eventually(activity)
153
- end
116
+ preflight = Contrast::Agent::Reporting::BuildPreflight.generate(finding)
117
+ return unless preflight
154
118
 
155
- def handle_new_finding trigger_node, source, object, ret, request, *args
156
- # sent to reporter
157
- # here we will generate new type of finding
158
- ruby_finding = Contrast::Agent::Reporting::Finding.new(trigger_node.rule_id)
159
- ruby_finding.attach_data(trigger_node, source, object, ret, request, *args)
160
- hash_code = Contrast::Utils::HashDigest.generate_event_hash(ruby_finding, source, request)
161
- ruby_finding.hash_code = hash_code
119
+ preflight_data = preflight.messages[0].data
120
+ return if Contrast::Agent::REQUEST_TRACKER.current&.reported_findings&.include?(preflight_data)
162
121
 
163
- new_preflight = Contrast::Agent::Reporting::BuildPreflight.build(ruby_finding, request)
164
- Contrast::Agent.reporter&.send_event(new_preflight)
122
+ Contrast::Agent::Reporting::ReportingStorage[preflight.messages[0].data] = finding
123
+ if Contrast::Agent::REQUEST_TRACKER.current
124
+ Contrast::Agent::REQUEST_TRACKER.current.reported_findings << preflight_data
125
+ end
126
+ Contrast::Agent.reporter&.send_event(preflight)
165
127
  end
166
128
 
167
129
  private
@@ -203,30 +165,6 @@ module Contrast
203
165
  end
204
166
  end
205
167
 
206
- def append_events finding, event_data
207
- append_from_source(finding, event_data.tagged)
208
- finding.events << Contrast::Agent::Assess::Events::EventFactory.build(event_data).to_dtm_event
209
- end
210
-
211
- def append_from_source finding, source
212
- return unless source
213
- return unless Contrast::Agent::Assess::Tracker.trackable?(source)
214
-
215
- properties = Contrast::Agent::Assess::Tracker.properties(source)
216
- return unless properties
217
-
218
- build_events(finding, properties.event) if properties.event
219
-
220
- # CSGoogle::Protobuf::Map doesn't support merge!, so we have to do this long form
221
- source_props = properties.properties
222
- return unless source_props
223
-
224
- source_props.each_pair do |key, value|
225
- key = Contrast::Utils::StringUtils.force_utf8(key)
226
- finding.properties[key] = Contrast::Utils::StringUtils.force_utf8(value)
227
- end
228
- end
229
-
230
168
  def build_events finding, event
231
169
  return unless event
232
170
 
@@ -238,36 +176,17 @@ module Contrast
238
176
  finding.events << event.to_dtm_event
239
177
  end
240
178
 
241
- def append_route finding, request
242
- context = Contrast::Agent::REQUEST_TRACKER.current
243
- if context
244
- finding.routes << context.route if context.route
245
- elsif request&.route
246
- finding.routes << request.route
247
- end
248
- end
249
-
250
- def append_hash finding, source, request
251
- hash_code = Contrast::Utils::HashDigest.generate_event_hash(finding, source, request)
252
- finding.hash_code = Contrast::Utils::StringUtils.force_utf8(hash_code)
253
- finding.preflight = Contrast::Utils::PreflightUtil.create_preflight(finding)
254
- end
255
-
256
- # Because our APIs are not versioned, TeamServer relies on a field, version, to tell it what, if any,
257
- # validation it can preform on the findings we send it. Examine the finding and determine the level to
258
- # which it conforms.
179
+ # Check if the finding should be excluded due to the assess exclusion rules.
259
180
  #
260
- # @param finding [Contrast::Api::Dtm::Finding]
261
- # @return [int] the version of compliance
262
- def determine_compliance_version finding
263
- return MINIMUM_FINDING_VERSION unless finding
264
- # as routes are the only variable between findings, in the case where we couldn't determine one, any
265
- # finding with a route is at maximum compliance
266
- return CURRENT_FINDING_VERSION if finding.routes.any?
267
- # any finding without events is not of a dataflow type and therefore at maximum compliance
268
- return CURRENT_FINDING_VERSION unless finding.events.any?
181
+ # @param request [Contrast::Agent::Request] a wrapper around the Rack::Request for the current request
182
+ # @param rule_id [String]
183
+ # return [Boolean]
184
+ def excluded_by_url_and_rule? request, rule_id
185
+ Contrast::SETTINGS.excluder.assess_excluded_by_url_and_rule?(request, rule_id)
186
+ end
269
187
 
270
- MINIMUM_FINDING_VERSION
188
+ def excluded_by_input_and_rule? request, finding, rule_id
189
+ Contrast::SETTINGS.excluder.assess_excluded_by_input_and_rule?(request, finding, rule_id)
271
190
  end
272
191
  end
273
192
  end
@@ -3,7 +3,7 @@
3
3
 
4
4
  require 'contrast/agent/assess/policy/trigger/reflected_xss'
5
5
  require 'contrast/agent/assess/policy/trigger/xpath'
6
- require 'contrast/api/decorators/trace_taint_range_tags'
6
+ require 'contrast/agent/reporting/reporting_events/finding_event_taint_range_tags'
7
7
  require 'contrast/components/logger'
8
8
 
9
9
  module Contrast
@@ -185,8 +185,8 @@ module Contrast
185
185
 
186
186
  tags.each do |tag|
187
187
  raise(ArgumentError, "Rule #{ rule_id } had an invalid tag. #{ tag } is not a known value.") unless
188
- Contrast::Api::Decorators::TraceTaintRangeTags::VALID_TAGS.include?(tag) ||
189
- Contrast::Api::Decorators::TraceTaintRangeTags::VALID_SOURCE_TAGS.include?(tag)
188
+ Contrast::Agent::Reporting::FindingEventTaintRangeTags::VALID_TAGS.include?(tag) ||
189
+ Contrast::Agent::Reporting::FindingEventTaintRangeTags::VALID_SOURCE_TAGS.include?(tag)
190
190
  end
191
191
  end
192
192
 
@@ -7,7 +7,7 @@ module Contrast
7
7
  module Policy
8
8
  module TriggerValidation
9
9
  # Validator used to assert a REDOS finding is actually vulnerable
10
- # before serializing that finding as a DTM to report to the service.
10
+ # before serializing that finding as a DTM to report to the TeamServer.
11
11
  module REDOSValidator
12
12
  RULE_NAME = 'redos'
13
13
 
@@ -7,7 +7,7 @@ module Contrast
7
7
  module Policy
8
8
  module TriggerValidation
9
9
  # Validator used to assert a SSRF finding is actually vulnerable
10
- # before serializing that finding as a DTM to report to the service.
10
+ # before serializing that finding as a DTM to report to the TeamServer.
11
11
  module SSRFValidator
12
12
  RULE_NAME = 'ssrf'
13
13
  URL_PATTERN = %r{(?<protocol>http|https|ftp|sftp|telnet|gopher|rtsp|rtsps|ssh|svn)://(?<host>[^/?]+)(?<path>/?[^?]*)(?<query_string>\?.*)?}i.cs__freeze # rubocop:disable Layout/LineLength
@@ -8,7 +8,7 @@ module Contrast
8
8
  module TriggerValidation
9
9
  # Validator used to assert a Reflected XSS finding is actually
10
10
  # vulnerable before serializing that finding as a DTM to report to
11
- # the service.
11
+ # the TeamServer.
12
12
  module XSSValidator
13
13
  RULE_NAME = 'reflected-xss'
14
14
  SAFE_CONTENT_TYPES = %w[/csv /javascript /json /pdf /x-javascript /x-json].cs__freeze
@@ -42,24 +42,14 @@ module Contrast
42
42
  return unless event.source_type
43
43
  return unless (current_request = Contrast::Agent::REQUEST_TRACKER.current)
44
44
 
45
- append_to_ruby_object(current_request, event)
46
- end
47
-
48
- # @param current_request [Contrast::Agent::RequestContext]
49
- # @param event [Contrast::Agent::Assess::Events::ContrastEvent]
50
- def append_to_ruby_object current_request, event
51
45
  if current_request.observed_route.sources.any? do |source|
52
- source.type == event.forced_source_type &&
53
- source.name == event.forced_source_name # rubocop:disable Security/Module/Name
46
+ source.type == event.source_type && source.name == event.source_name # rubocop:disable Security/Module/Name
54
47
  end
55
48
 
56
49
  return
57
50
  end
58
51
 
59
- event_source = event.build_event_source
60
- return unless event_source
61
-
62
- current_request.observed_route.sources << event_source
52
+ current_request.observed_route.sources << event.event_source if event.event_source
63
53
  end
64
54
  end
65
55
  end
@@ -11,9 +11,8 @@ module Contrast
11
11
  module Assess
12
12
  module Rule
13
13
  module Provider
14
- # Hardcoded rules detect if any secret value has been written
15
- # directly into the sourcecode of the application. To use this base
16
- # class, a provider must implement three methods:
14
+ # Hardcoded rules detect if any secret value has been written directly into the sourcecode of the
15
+ # application. To use this base class, a provider must implement three methods:
17
16
  # 1) name_passes? : does the constant name match a given value set
18
17
  # 2) value_node_passes? : does the value of the constant match a
19
18
  # given value set
@@ -21,23 +20,21 @@ module Contrast
21
20
  module HardcodedValueRule
22
21
  include Contrast::Components::Logger::InstanceMethods
23
22
 
23
+ # @return [Boolean]
24
24
  def disabled?
25
25
  !::Contrast::ASSESS.enabled? || ::Contrast::ASSESS.rule_disabled?(rule_id)
26
26
  end
27
27
 
28
- # Parse the file pertaining to the given TracePoint to walk its AST
29
- # to determine if a Constant is hardcoded. For our purposes, this
30
- # hard coding means directly set rather than as an interpolated
31
- # String or through a method call.
28
+ # Parse the file pertaining to the given TracePoint to walk its AST to determine if a Constant is
29
+ # hardcoded. For our purposes, this hard coding means directly set rather than as an interpolated String or
30
+ # through a method call.
32
31
  #
33
- # Note: This is a top layer check, we make no assertions about what
34
- # the methods or interpolations do. Their presence, even if only
35
- # calling a hardcoded thing, causes this check to not report.
32
+ # Note: This is a top layer check, we make no assertions about what the methods or interpolations do.
33
+ # Their presence, even if only calling a hardcoded thing, causes this check to not report.
36
34
  #
37
- # @param trace_point [TracePoint] the TracePoint event created on
38
- # the :end of a Module being loaded
39
- # @param ast [RubyVM::AbstractSyntaxTree::Node] the abstract syntax
40
- # tree of the Module defined in the TracePoint end event
35
+ # @param trace_point [TracePoint] the TracePoint event created on the :end of a Module being loaded
36
+ # @param ast [RubyVM::AbstractSyntaxTree::Node] the abstract syntax tree of the Module defined in the
37
+ # TracePoint end event
41
38
  def parse trace_point, ast
42
39
  return if disabled?
43
40
 
@@ -56,8 +53,8 @@ module Contrast
56
53
  private
57
54
 
58
55
  # @param mod [Module] the module to which this AST pertains
59
- # @param ast [RubyVM::AbstractSyntaxTree::Node, Object] a node
60
- # within the AST, which may be a leaf, so any Object
56
+ # @param ast [RubyVM::AbstractSyntaxTree::Node, Object] a node within the AST, which may be a leaf, so any
57
+ # Object
61
58
  def parse_ast mod, ast
62
59
  return unless ast.cs__is_a?(RubyVM::AbstractSyntaxTree::Node)
63
60
  return unless ast.cs__respond_to?(:children)
@@ -72,32 +69,27 @@ module Contrast
72
69
  # https://www.rubydoc.info/gems/ruby-internal/Node/CDECL
73
70
  return unless ast.type == :CDECL
74
71
 
75
- # The CDECL Node has two children, the first being the Constant
76
- # name as a symbol, the second as the value to assign to that
77
- # constant
72
+ # The CDECL Node has two children, the first being the Constant name as a symbol, the second as the value
73
+ # to assign to that constant
78
74
  children = ast.children
79
75
  name = children[0].to_s
80
76
  # If that constant name doesn't pass our checks, move on.
81
77
  return unless name_passes?(name)
82
78
 
83
79
  value = children[1]
84
- # The assignment node could be a direct value or a call of some
85
- # sort. We leave it to each rule to properly handle these nodes.
80
+ # The assignment node could be a direct value or a call of some sort. We leave it to each rule to
81
+ # properly handle these nodes.
86
82
  return unless value_node_passes?(value)
87
83
 
88
- if Contrast::Agent::Reporter.enabled?
89
- new_finding_and_reporting(mod, name)
90
- else # TODO: RUBY-1438 -- remove
91
- build_finding(mod, name)
92
- end
84
+ build_and_report(mod, name)
85
+ rescue StandardError => e
86
+ logger.error('Unable to parse AST for Hardcoded Rule analysis.', e)
93
87
  end
94
88
 
95
- # Constants can be set as frozen directly. We need to account for
96
- # this change as it means the Node given to the :CDECL call will be
97
- # a :CALL, not a constant.
89
+ # Constants can be set as frozen directly. We need to account for this change as it means the Node given to
90
+ # the :CDECL call will be a :CALL, not a constant.
98
91
  #
99
- # @param value_node [RubyVM::AbstractSyntaxTree::Node] the node to
100
- # evaluate
92
+ # @param value_node [RubyVM::AbstractSyntaxTree::Node] the node to evaluate
101
93
  # @return [Boolean] is this a freeze call or not
102
94
  def freeze_call? value_node
103
95
  return false unless value_node.type == :CALL
@@ -109,61 +101,29 @@ module Contrast
109
101
  children[1] == :freeze
110
102
  end
111
103
 
112
- def build_finding clazz, constant_string
113
- class_name = clazz.cs__name
114
-
115
- finding = assign_finding(class_name, constant_string)
116
- activity = Contrast::Api::Dtm::Activity.new
117
- activity.findings << finding
118
- Contrast::Agent.messaging_queue.send_event_eventually(activity, force: true)
119
- rescue StandardError => e
120
- logger.error('Unable to build a finding for Hardcoded Rule', e)
121
- nil
122
- end
104
+ # @param mod [Module] the module to which this AST pertains
105
+ # @param name [String] the name of the hardcoded constant
106
+ def build_and_report mod, name
107
+ finding = build_finding(mod, name)
108
+ return unless finding
123
109
 
124
- # @param class_name [String] the name of the class in which the hardcoded value is present
125
- # @param constant_string [String] the name of the constant
126
- # @return [Contrast::Api::Dtm::Finding]
127
- def assign_finding class_name, constant_string
128
- finding = Contrast::Api::Dtm::Finding.new
129
- finding.rule_id = Contrast::Utils::StringUtils.protobuf_safe_string(rule_id)
130
- finding.version = Contrast::Agent::Assess::Policy::TriggerMethod::CURRENT_FINDING_VERSION
131
-
132
- finding.properties[SOURCE_KEY] = Contrast::Utils::StringUtils.protobuf_safe_string(class_name)
133
- finding.properties[CONSTANT_NAME_KEY] = Contrast::Utils::StringUtils.protobuf_safe_string(constant_string)
134
- finding.properties[CODE_SOURCE_KEY] =
135
- Contrast::Utils::StringUtils.protobuf_safe_string(constant_string + redacted_marker)
136
-
137
- hash = Contrast::Utils::HashDigest.generate_class_scanning_hash(finding)
138
- finding.hash_code = Contrast::Utils::StringUtils.protobuf_safe_string(hash)
139
- finding.preflight = Contrast::Utils::PreflightUtil.create_preflight(finding)
140
- finding
141
- end
110
+ preflight = Contrast::Agent::Reporting::BuildPreflight.generate(finding)
111
+ return unless preflight
142
112
 
143
- def new_finding_and_reporting clazz, constant_string
144
- return unless Contrast::Agent::Reporter.enabled?
145
-
146
- # sent to reporter
147
- # and add logger message for the report of the preflight
148
- new_preflight = Contrast::Agent::Reporting::Preflight.new
149
- new_preflight_message = Contrast::Agent::Reporting::PreflightMessage.new
150
- new_preflight_message.hash_code = hash
151
- new_preflight_message.data = "#{ rule_id },#{ hash }"
152
- new_preflight.messages << new_preflight_message
153
-
154
- # extract to new method
155
- # here we will generate new type of finding
156
- ruby_finding = Contrast::Agent::Reporting::Finding.new(rule_id)
157
- ruby_finding.hash_code = hash
158
- ruby_finding.properties[SOURCE_KEY] = clazz.cs__name
159
- ruby_finding.properties[CONSTANT_NAME_KEY] = constant_string
160
- ruby_finding.properties[CODE_SOURCE_KEY] = constant_string + redacted_marker
161
- save_and_report_finding(ruby_finding, new_preflight)
113
+ Contrast::Agent::Reporting::ReportingStorage[preflight.messages[0].data] = finding
114
+ Contrast::Agent.reporter&.send_event(preflight)
162
115
  end
163
116
 
164
- def save_and_report_finding ruby_finding, new_preflight
165
- Contrast::Agent::Reporting::ReportingStorage[hash] = ruby_finding
166
- Contrast::Agent.reporter&.send_event(new_preflight)
117
+ # @param clazz [Class] the Class or Module containing the constant
118
+ # @param constant_string [String]
119
+ # @return [Contrast::Agent::Reporting::Finding]
120
+ def build_finding clazz, constant_string
121
+ finding = Contrast::Agent::Reporting::Finding.new(rule_id)
122
+ finding.properties[SOURCE_KEY] = clazz.cs__name
123
+ finding.properties[CONSTANT_NAME_KEY] = constant_string
124
+ finding.properties[CODE_SOURCE_KEY] = constant_string + redacted_marker
125
+ finding.hash_code = Contrast::Utils::HashDigest.generate_class_scanning_hash(finding)
126
+ finding
167
127
  end
168
128
  end
169
129
  end
@@ -3,10 +3,8 @@
3
3
 
4
4
  require 'rack'
5
5
  require 'json'
6
- require 'contrast/agent/reporting/reporting_utilities/dtm_message'
7
6
  require 'contrast/agent/reporting/reporting_utilities/build_preflight'
8
7
  require 'contrast/utils/hash_digest'
9
- require 'contrast/utils/preflight_util'
10
8
  require 'contrast/utils/string_utils'
11
9
 
12
10
  module Contrast
@@ -32,18 +30,11 @@ module Contrast
32
30
  finding = build_finding(violation)
33
31
  return unless finding
34
32
 
35
- if Contrast::Agent::Reporter.enabled?
36
- report = Contrast::Agent::Reporting::DtmMessage.dtm_to_event(finding)
37
- if report.is_a?(Contrast::Agent::Reporting::Finding)
38
- request = Contrast::Agent::REQUEST_TRACKER.current&.request
39
- preflight = Contrast::Agent::Reporting::BuildPreflight.build(report, request)
40
- Contrast::Agent.reporter&.send_event(preflight)
41
- else
42
- Contrast::Agent.reporter&.send_event(report)
43
- end
44
- else
45
- Contrast::Agent::REQUEST_TRACKER.current.activity.findings << finding
46
- end
33
+ preflight = Contrast::Agent::Reporting::BuildPreflight.generate(finding)
34
+ return unless preflight
35
+
36
+ Contrast::Agent::Reporting::ReportingStorage[preflight.messages[0].data] = finding
37
+ Contrast::Agent.reporter&.send_event(preflight)
47
38
  end
48
39
 
49
40
  protected
@@ -75,16 +66,15 @@ module Contrast
75
66
  # Convert the given evidence into a finding. The rule will populate this evidence with each of the
76
67
  #
77
68
  # @param evidence [Hash] the properties required to build this finding.
78
- # @return [Contrast::Api::Dtm::Finding]
69
+ # @return [Contrast::Agent::Reporting::Finding]
79
70
  def build_finding evidence
80
- finding = Contrast::Api::Dtm::Finding.new
81
- finding.rule_id = rule_id
71
+ finding = Contrast::Agent::Reporting::Finding.new(rule_id)
82
72
  context = Contrast::Agent::REQUEST_TRACKER.current
83
- finding.routes << context.route if context&.route
73
+ finding.routes << context.discovered_route if context&.discovered_route
84
74
  build_evidence(evidence, finding)
75
+ finding.request = Contrast::Agent::Reporting::FindingRequest.convert(context.request) if context&.request
85
76
  hash = Contrast::Utils::HashDigest.generate_config_hash(finding)
86
77
  finding.hash_code = Contrast::Utils::StringUtils.force_utf8(hash)
87
- finding.preflight = Contrast::Utils::PreflightUtil.create_preflight(finding)
88
78
  finding
89
79
  end
90
80
 
@@ -92,16 +82,10 @@ module Contrast
92
82
  # Change it accordingly the rule you work on
93
83
  #
94
84
  # @param evidence [Hash] the properties required to build this finding.
95
- # @param finding [Contrast::Api::Dtm::Finding] finding to attach the evidence to
85
+ # @param finding [Contrast::Agent::Reporting::Finding] finding to attach the evidence to
96
86
  def build_evidence evidence, finding
97
87
  evidence.each_pair do |key, value|
98
- finding.properties[key] = if value.cs__is_a?(Hash)
99
- Contrast::Utils::StringUtils.protobuf_format(value.to_json)
100
- elsif value.cs__is_a?(Array)
101
- value.map { Contrast::Utils::StringUtils.protobuf_format(_1) }.to_s
102
- else
103
- Contrast::Utils::StringUtils.protobuf_format(value)
104
- end
88
+ finding.properties[key] = value
105
89
  end
106
90
  end
107
91
 
@@ -2,9 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'rack'
5
- require 'contrast/agent/reporting/reporting_utilities/dtm_message'
6
5
  require 'contrast/utils/hash_digest'
7
- require 'contrast/utils/preflight_util'
8
6
  require 'contrast/utils/string_utils'
9
7
  require 'contrast/agent/assess/rule/response/base_rule'
10
8
 
@@ -22,7 +20,7 @@ module Contrast
22
20
  START_PROP = 'start'.cs__freeze
23
21
  END_PROP = 'end'.cs__freeze
24
22
  FORM_START_REGEXP = /<form/i.cs__freeze
25
- META_TYPE = 'meta'
23
+ META_TYPE = 'META tag'
26
24
  PRAGMA = 'pragma'
27
25
 
28
26
  # Rules discern which responses they can/should analyze.