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,7 +3,9 @@
3
3
 
4
4
  require 'socket'
5
5
  require 'contrast/agent/version'
6
+ require 'contrast/utils/object_share'
6
7
  require 'contrast/logger/aliased_logging'
8
+ require 'fileutils'
7
9
 
8
10
  module Contrast
9
11
  module Utils
@@ -17,6 +19,17 @@ module Contrast
17
19
  PROGNAME = 'Contrast Agent'
18
20
  DATE_TIME_FORMAT = '%Y-%m-%dT%H:%M:%S.%L%z'
19
21
 
22
+ # StringIO is a valid path because it logs directly to a string buffer
23
+ def write_permission? path
24
+ return false if path.nil?
25
+ return true if path.is_a?(StringIO)
26
+ return File.writable?(path) if File.exist?(path)
27
+
28
+ dir_name = File.dirname(File.absolute_path(path))
29
+ FileUtils.mkdir_p(dir_name) unless Dir.exist?(dir_name)
30
+ File.writable?(dir_name)
31
+ end
32
+
20
33
  private
21
34
 
22
35
  def build path: STDOUT_STR, level_const: DEFAULT_LEVEL, progname: PROGNAME
@@ -47,26 +60,26 @@ module Contrast
47
60
  # TeamServer.
48
61
  # @return [String] the path to which to log or STDOUT / STDERR if one of those values provided.
49
62
  def find_valid_path log_file
50
- config = ::Contrast::CONFIG.root.agent.logger
63
+ config = ::Contrast::CONFIG.agent.logger
51
64
  config_path = config&.path&.length.to_i.positive? ? config.path : nil
52
65
  valid_path(config_path || log_file)
53
66
  end
54
67
 
55
- def valid_path path
68
+ def valid_path path, default_name: DEFAULT_NAME
56
69
  path = path.nil? ? Contrast::Utils::ObjectShare::EMPTY_STRING : path
57
70
  return path if path == STDOUT_STR
58
71
  return path if path == STDERR_STR
59
72
 
60
- path = DEFAULT_NAME if path.empty?
73
+ path = default_name if path.empty?
61
74
  if write_permission?(path)
62
75
  path
63
- elsif write_permission?(DEFAULT_NAME)
76
+ elsif write_permission?(default_name)
64
77
  # Log once when the path is invalid. We'll change to this path, so no
65
78
  # need to log again.
66
- if previous_path != DEFAULT_NAME
67
- $stdout.puts("[!] Unable to write to '#{ path }'. Writing to default log '#{ DEFAULT_NAME }' instead.")
79
+ if previous_path != default_name
80
+ $stdout.puts("[!] Unable to write to '#{ path }'. Writing to default log '#{ default_name }' instead.")
68
81
  end
69
- DEFAULT_NAME
82
+ default_name
70
83
  else
71
84
  # Log once when the path is invalid. We'll change to this path, so no
72
85
  # need to log again.
@@ -81,7 +94,7 @@ module Contrast
81
94
  # TeamServer.
82
95
  # @return [::Ougai::Logging::Severity] the level at which to log
83
96
  def find_valid_level log_level
84
- config = ::Contrast::CONFIG.root.agent.logger
97
+ config = ::Contrast::CONFIG.agent.logger
85
98
  config_level = config&.level&.length&.positive? ? config.level : nil
86
99
 
87
100
  valid_level(config_level || log_level)
@@ -166,6 +179,18 @@ module Contrast
166
179
  end
167
180
  end
168
181
 
182
+ def valid_level level
183
+ level ||= DEFAULT_LEVEL
184
+ level = level.upcase
185
+ if VALID_LEVELS.include?(level)
186
+ Object.cs__const_get("::Logger::Severity::#{ level }")
187
+ else
188
+ DEFAULT_LEVEL
189
+ end
190
+ rescue StandardError
191
+ DEFAULT_LEVEL
192
+ end
193
+
169
194
  # This method will extract the metadata information from context and other places
170
195
  #
171
196
  # initial structure of the data:
@@ -175,13 +200,10 @@ module Contrast
175
200
  # initially here we will use case to add it
176
201
  def extract_metadata rule_id = nil, outcome = nil
177
202
  message = []
178
- sender_info = context&.activity&.http_request&.sender
203
+ request = context&.activity&.request
204
+ sender_info = { ip: request&.ip || Contrast::Utils::ObjectShare::EMPTY_STRING, port: request&.port || 0 }
179
205
  rule_id ? message << "pri=#{ rule_id } " : 'asd'
180
- request_method = if context.request.rack_request.env['REQUEST_METHOD'].length.positive?
181
- context.request.rack_request.env['REQUEST_METHOD']
182
- else
183
- DEFAULT_METADATA
184
- end
206
+ request_method = assign_request_method(context)
185
207
  app_name = ::Contrast::APP_CONTEXT.name # rubocop:disable Security/Module/Name
186
208
  attach_request_and_sender_info(message, sender_info)
187
209
  message << "request=#{ context.request.url } "
@@ -198,10 +220,10 @@ module Contrast
198
220
  src = if needed_header
199
221
  needed_header
200
222
  else
201
- sender_info.ip.length > 1 ? sender_info.ip : DEFAULT_METADATA
223
+ sender_info[:ip].length > 1 ? sender_info[:ip] : DEFAULT_METADATA
202
224
  end
203
225
  message << "src=#{ src }"
204
- message << "port=#{ sender_info.port }"
226
+ message << "port=#{ sender_info[:port] }"
205
227
  end
206
228
 
207
229
  def extract_ip_address
@@ -216,9 +238,17 @@ module Contrast
216
238
  end
217
239
 
218
240
  def extract_sender_ip
219
- request_headers = context.activity.http_request.request_headers&.transform_keys(&:to_s)
241
+ request_headers = context.activity.request.headers&.transform_keys(&:to_s)
220
242
  request_headers['X-Forwarded-For']
221
243
  end
244
+
245
+ def assign_request_method context
246
+ if context.request.rack_request.env['REQUEST_METHOD'].length.positive?
247
+ context.request.rack_request.env['REQUEST_METHOD']
248
+ else
249
+ DEFAULT_METADATA
250
+ end
251
+ end
222
252
  end
223
253
  end
224
254
  end
@@ -26,10 +26,10 @@ module Contrast
26
26
  return unless url
27
27
 
28
28
  addr = URI(url)
29
- # the proxy is enabled only if there is provided url even if the enable is set to true
30
29
  return if addr.host.nil? || addr.port.nil?
31
- return if addr.scheme != 'https' && !addr.host.to_s.include?('localhost') # TODO: RUBY-99999 allow http w/ localhost # rubocop:disable Layout/LineLength
30
+ return if addr.scheme != 'https' && !addr.host.to_s.include?('localhost')
32
31
 
32
+ # the proxy is enabled only if there is provided url even if the enable is set to true
33
33
  proxy_addr = URI(Contrast::API.proxy_url) if proxy_enabled?
34
34
  net_http_client = initialize_client(addr, proxy_addr, use_proxy, use_custom_cert)
35
35
  return if net_http_client.nil?
@@ -13,26 +13,6 @@ module Contrast
13
13
  extend Contrast::Components::Scope::InstanceMethods
14
14
 
15
15
  class << self
16
- def running?
17
- result = false
18
- with_contrast_scope do
19
- process = `ps aux | grep contrast-servic[e]`
20
- processes = process.split("\n")
21
- result = !processes.empty? && processes.any? { |process_descriptor| !process_descriptor.include?('grep') }
22
- end
23
- result
24
- end
25
-
26
- # check if service was killed and is a zombie process
27
- # returns an array of zombie process PIDs as strings; empty array if there are none
28
- def zombie_pids
29
- with_contrast_scope do
30
- # retrieve pid of service processes
31
- zombie_pid_list = `ps aux | grep contrast-servic[e] | grep Z | awk '{print $2}'`
32
- zombie_pid_list.split("\n")
33
- end
34
- end
35
-
36
16
  # Check current OS type
37
17
  # returns true if check is correct or false if not
38
18
  def windows?
@@ -117,7 +117,8 @@ module Contrast
117
117
  return ret if current_context && !current_context.analyze_request?
118
118
 
119
119
  trigger_node = method_policy.trigger_node
120
- if trigger_node
120
+
121
+ if trigger_node && !trigger_node.nil?
121
122
  Contrast::Agent::Assess::Policy::TriggerMethod.apply_trigger_rule(trigger_node, object, ret, args)
122
123
  end
123
124
  if method_policy.source_node
@@ -135,7 +136,7 @@ module Contrast
135
136
  rescue StandardError => e
136
137
  logger.error('Unable to assess method call.', e)
137
138
  rescue Exception => e # rubocop:disable Lint/RescueException
138
- logger.error('Unable to assess method call.', e)
139
+ logger.error('Unable to assess method call due to exception.', e)
139
140
  raise(e)
140
141
  ensure
141
142
  ret.rewind if Contrast::Utils::IOUtil.should_rewind?(ret)
@@ -7,22 +7,6 @@ module Contrast
7
7
  module ResponseUtils
8
8
  private
9
9
 
10
- # From the dtm for normalized_response_headers:
11
- # Key is UPPERCASE_UNDERSCORE
12
- #
13
- # Example: Content-Type: text/html; charset=utf-8
14
- # "CONTENT_TYPE" => Content-Type,["text/html; charset=utf8"]
15
- def append_pair map, key, value
16
- return unless key && value
17
- return if value.is_a?(Hash)
18
-
19
- safe_key = Contrast::Utils::StringUtils.force_utf8(key)
20
- hash_key = Contrast::Utils::StringUtils.normalized_key(safe_key)
21
- map[hash_key] ||= Contrast::Api::Dtm::Pair.new
22
- map[hash_key].key = safe_key
23
- map[hash_key].values << Contrast::Utils::StringUtils.force_utf8(value)
24
- end
25
-
26
10
  HTTP_PREFIX = /^[Hh][Tt][Tt][Pp][_-]/i.cs__freeze
27
11
 
28
12
  # Given some holder of the content of the response's body, extract that
@@ -3,7 +3,6 @@
3
3
 
4
4
  require 'contrast/utils/object_share'
5
5
  require 'contrast/agent/reporting/reporting_events/application_defend_attack_sample_stack'
6
- require 'contrast/api'
7
6
 
8
7
  module Contrast
9
8
  module Utils
@@ -33,16 +32,7 @@ module Contrast
33
32
  end
34
33
 
35
34
  # Call and translate a caller_locations array to an array of
36
- # StackTraceElement for TeamServer to display, excluding any Contrast
37
- # code found.
38
- #
39
- # @return [Array<Contrast::Api::Dtm::StackTraceElement>]
40
- def build_protect_stack_array
41
- build_protect_stack(Contrast::Api::Dtm::StackTraceElement)
42
- end
43
-
44
- # Call and translate a caller_locations array to an array of
45
- # StackTraceElement for TeamServer to display, excluding any Contrast
35
+ # ApplicationDefendAttackSampleStack for TeamServer to display, excluding any Contrast
46
36
  # code found.
47
37
  #
48
38
  # @return [Array<Contrast::Agent::Reporting::ApplicationDefendAttackSampleStack>]
@@ -50,31 +40,6 @@ module Contrast
50
40
  build_protect_stack(Contrast::Agent::Reporting::ApplicationDefendAttackSampleStack)
51
41
  end
52
42
 
53
- # Translate a caller array to an array of TraceStacks for TeamServer to
54
- # display, excluding any Contrast code found.
55
- #
56
- # @param stack [Array<String>] the output of Kernel.caller
57
- # @return [Array<Contrast::Api::Dtm::TraceStack]
58
- def build_assess_stack_array stack
59
- converted = []
60
- return converted unless stack
61
-
62
- i = 0
63
- while i < stack.length
64
- caller_location = stack[i]
65
- i += 1
66
- next if caller_location.include?(AGENT_CLASS_MARKER)
67
-
68
- # To play nice with the way that TeamServer is rendering these
69
- # values, we only populate the file_name field with exactly what we
70
- # want them to display
71
- element = Contrast::Api::Dtm::TraceStack.new
72
- element.file_name = caller_location
73
- converted << element
74
- end
75
- converted
76
- end
77
-
78
43
  private
79
44
 
80
45
  def reject_caller_entries stack
@@ -84,10 +49,8 @@ module Contrast
84
49
  end
85
50
  end
86
51
 
87
- # @param clazz [Class] Contrast::Api::Dtm::StackTraceElement or
88
- # Contrast::Agent::Reporting::ApplicationDefendAttackSampleStack
89
- # @return [Array<Contrast::Agent::Reporting::ApplicationDefendAttackSampleStack|
90
- # Contrast::Api::Dtm::StackTraceElement>]
52
+ # @param clazz [Class] Contrast::Agent::Reporting::ApplicationDefendAttackSampleStack
53
+ # @return [Array<Contrast::Agent::Reporting::ApplicationDefendAttackSampleStack>]
91
54
  def build_protect_stack clazz
92
55
  stack = caller(3, 21)
93
56
  return [] unless stack
@@ -22,13 +22,6 @@ module Contrast
22
22
  !str.nil? && !str.to_s.empty?
23
23
  end
24
24
 
25
- def protobuf_format data, truncate: true
26
- data = data&.to_s
27
- data = Contrast::Utils::StringUtils.force_utf8(data)
28
- data = Contrast::Utils::StringUtils.truncate(data) if truncate
29
- data
30
- end
31
-
32
25
  # Protobuf has a very strict typing. Nil is not a String and will throw
33
26
  # an exception if you try to set it. Use this to be safe.
34
27
  # Uses the object share to avoid creating several new strings per request
@@ -37,12 +30,21 @@ module Contrast
37
30
  end
38
31
 
39
32
  # Truncate a string to 255 characters max length
33
+ #
34
+ # @param str [String] the string tt truncate
35
+ # @param default [String] what to default to
36
+ # @return [String]
40
37
  def truncate str, default = Contrast::Utils::ObjectShare::EMPTY_STRING
41
38
  return default if str.nil?
42
39
 
43
40
  str.to_s[0..255]
44
41
  end
45
42
 
43
+ # Cast the given object, which should be a String, into a UTF-8 String for reporting. All given objects will be
44
+ # cast to their to_s form, except nil which will become the ObjectShare::EMPTY_STRING, and then cast.
45
+ #
46
+ # @param str [String, Object, nil]
47
+ # @return [String]
46
48
  def force_utf8 str
47
49
  return Contrast::Utils::ObjectShare::EMPTY_STRING unless str
48
50
 
@@ -84,6 +86,16 @@ module Contrast
84
86
  @_normalized_keys[str] = cut
85
87
  end
86
88
  end
89
+
90
+ # transform string from snake_case to Capitalized Text
91
+ #
92
+ # @param str[String] string to transform
93
+ # @return [String]
94
+ def transform_string str
95
+ return unless str
96
+
97
+ str.split('-').map(&:capitalize).join(' ')
98
+ end
87
99
  end
88
100
  end
89
101
  end
@@ -34,18 +34,12 @@ module Contrast
34
34
  def build_request event
35
35
  return unless valid_event?(event)
36
36
 
37
- string_body = if event.cs__is_a?(Contrast::Agent::Telemetry::TelemetryException::Event)
38
- [event.to_controlled_hash]
39
- else
40
- [event.to_hash]
41
- end
42
-
43
37
  header = {
44
38
  'User-Agent' => "<#{ Contrast::Utils::ObjectShare::RUBY }>-<#{ Contrast::Agent::VERSION }>",
45
39
  'Content-Type' => 'application/json'
46
40
  }
47
41
  request = Net::HTTP::Post.new(build_path(event), header)
48
- request.body = string_body.to_json
42
+ request.body = get_event_json(event)
49
43
  request
50
44
  end
51
45
 
@@ -97,6 +91,18 @@ module Contrast
97
91
  path = endpoint == EXCEPTIONS ? Contrast::Agent::Telemetry::TelemetryException::Event.path : event.path
98
92
  "#{ Contrast::Agent::Telemetry::Base::URL }#{ endpoint }#{ path }"
99
93
  end
94
+
95
+ # Helper Method to get json representation of Telemetry Event data, handles error on to_json
96
+ #
97
+ # @param event [Contrast::Agent::Telemetry::Event, Array<Contrast::Agent::Telemetry::TelemetryException::Event>]
98
+ # @return [String] - JSON
99
+ def get_event_json event
100
+ hsh = [event.to_controlled_hash]
101
+ hsh.to_json
102
+ rescue Exception => e # rubocop:disable Lint/RescueException
103
+ logger.error('Unable to convert TelemetryEvent to JSON string', e, hsh)
104
+ raise(e)
105
+ end
100
106
  end
101
107
  end
102
108
  end
data/lib/contrast.rb CHANGED
@@ -53,13 +53,8 @@ if RUBY_VERSION >= '3.0.0' && RUBY_VERSION < '3.1.0'
53
53
  end
54
54
  end
55
55
 
56
- require 'contrast/components/agent'
57
- require 'contrast/components/api'
58
- require 'contrast/components/app_context'
59
56
  require 'contrast/components/assess'
60
57
  require 'contrast/components/config'
61
- require 'contrast/components/contrast_service'
62
- require 'contrast/components/inventory'
63
58
  require 'contrast/components/logger'
64
59
  require 'contrast/components/protect'
65
60
  require 'contrast/components/sampling'
@@ -68,20 +63,20 @@ require 'contrast/components/settings'
68
63
  require 'contrast/utils/telemetry_hash'
69
64
  require 'contrast/utils/telemetry'
70
65
  require 'contrast/agent/telemetry/events/exceptions/telemetry_exception_event'
71
- require 'protobuf' # TODO: RUBY-1438
66
+ require 'contrast/agent_lib/interface'
72
67
 
73
68
  module Contrast
74
69
  CONFIG = Contrast::Components::Config::Interface.new
75
70
  SCOPE = Contrast::Components::Scope::Interface.new
76
- API = CONFIG.root.api
71
+ API = CONFIG.api
77
72
  SETTINGS = Contrast::Components::Settings::Interface.new
78
- ASSESS = Contrast::Components::Assess::Interface.new
73
+ ASSESS = CONFIG.assess
79
74
  PROTECT = Contrast::Components::Protect::Interface.new
80
- INVENTORY = CONFIG.root.inventory
81
- AGENT = CONFIG.root.agent
75
+ INVENTORY = CONFIG.inventory
76
+ AGENT = CONFIG.agent
82
77
  LOGGER = AGENT.logger
83
- CONTRAST_SERVICE = Contrast::Components::ContrastService::Interface.new
84
- APP_CONTEXT = CONFIG.root.application
78
+ AGENT_LIB = Contrast::AgentLib::Interface.new
79
+ APP_CONTEXT = CONFIG.application
85
80
  end
86
81
 
87
82
  module Contrast
@@ -95,7 +90,6 @@ require 'contrast/agent/version'
95
90
 
96
91
  # shared utils
97
92
  require 'contrast/utils/timer'
98
- require 'contrast/utils/preflight_util'
99
93
 
100
94
  require 'contrast/utils/assess/sampling_util'
101
95
  require 'contrast/agent'
@@ -251,8 +251,7 @@
251
251
  }
252
252
  }
253
253
  ]
254
- },
255
- {
254
+ }, {
256
255
  "name": "sql-injection",
257
256
  "applicator": "Contrast::Agent::Protect::Policy::AppliesSqliRule",
258
257
  "applicator_method": "apply_rule",
data/ruby-agent.gemspec CHANGED
@@ -117,7 +117,8 @@ end
117
117
  def self.add_dependencies spec
118
118
  spec.add_dependency 'ougai', '>= 1.8', '< 3.0.0'
119
119
  spec.add_dependency 'rack', '~> 2.0'
120
- spec.add_dependency 'activesupport', '>= 3.2' # TODO: RUBY-1438 remove w/ protobuf code
120
+ spec.add_dependency 'contrast-agent-lib', '~> 0.1.0'
121
+ spec.add_dependency 'ffi', '~> 1.0'
121
122
  end
122
123
 
123
124
  # Enumerate the files required to build the Agent.
@@ -136,9 +137,6 @@ def self.add_files spec
136
137
  f.match(/(.*\.ya?ml)/)
137
138
  end
138
139
 
139
- spec.files << 'lib/contrast/api/dtm.pb.rb'
140
- spec.files << 'lib/contrast/api/settings.pb.rb'
141
- spec.files += Dir['service_executables/**/*']
142
140
  spec.files += Dir['funchook/**/*']
143
141
  spec.files += Dir['shared_libraries/**/*']
144
142
 
@@ -179,7 +177,6 @@ Gem::Specification.new do |spec|
179
177
  spec.required_ruby_version = ['>= 2.7.0', '< 3.2.0']
180
178
 
181
179
  spec.bindir = 'exe'
182
- spec.executables = ['contrast_service']
183
180
  # Keep cs__common first, it handles funchook.h right now.
184
181
  spec.extensions = Dir['ext/cs__common/extconf.rb', 'ext/**/extconf.rb']
185
182
  spec.require_paths = ['lib']