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
@@ -10,72 +10,48 @@ module Contrast
10
10
  include Contrast::Config::BaseConfiguration
11
11
 
12
12
  attr_accessor :disabled_rules
13
- attr_writer :bot_blocker, :cmd_injection, :sql_injection, :nosql_injection, :untrusted_deserialization,
14
- :xxe, :path_traversal, :reflected_xss, :unsafe_file_upload, :rule_base
13
+ attr_reader :bot_blocker,
14
+ :cmd_injection, :cmdi_command_backdoors,
15
+ :cmd_injection_semantic_chained_commands, :cmd_injection_semantic_dangerous_paths,
16
+ :method_tampering,
17
+ :nosql_injection,
18
+ :path_traversal, :path_traversal_semantic_file_security_bypass,
19
+ :reflected_xss,
20
+ :sql_injection, :sqli_dangerous_function,
21
+ :unsafe_file_upload,
22
+ :untrusted_deserialization,
23
+ :xxe,
24
+ :rule_base
15
25
 
16
26
  BASE_RULE = 'Contrast::Agent::Protect::Rule::Base'.cs__freeze
17
27
 
18
- def initialize hsh = {}
28
+ def initialize hsh = {} # rubocop:disable Metrics/AbcSize
19
29
  return unless hsh
20
30
 
21
31
  @disabled_rules = hsh[:disabled_rules]
22
32
  @rule_base = Contrast::Config::ProtectRuleConfiguration.new(hsh[BASE_RULE.to_sym])
23
33
  @bot_blocker = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'bot-blocker'])
24
34
  @cmd_injection = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'cmd-injection'])
35
+ @cmdi_command_backdoors =
36
+ Contrast::Config::ProtectRuleConfiguration.new(hsh[:'cmd-injection-command-backdoors'])
37
+ @cmdi_chained_command =
38
+ Contrast::Config::ProtectRuleConfiguration.new(hsh[:'cmd-injection-semantic-chained-commands'])
39
+ @cmdi_dangerous_path =
40
+ Contrast::Config::ProtectRuleConfiguration.new(hsh[:'cmd-injection-semantic-dangerous-paths'])
25
41
  @method_tampering = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'method-tampering'])
26
42
  @nosql_injection = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'nosql-injection'])
27
43
  @path_traversal = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'path-traversal'])
44
+ @path_traversal_semantic_file_security_bypass =
45
+ Contrast::Config::ProtectRuleConfiguration.new(hsh[:'path-traversal-semantic-file-security-bypass'])
28
46
  @reflected_xss = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'reflected-xss'])
29
47
  @sql_injection = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'sql-injection'])
48
+ @sqli_dangerous_function =
49
+ Contrast::Config::ProtectRuleConfiguration.new(hsh[:'sql-injection-semantic-dangerous-functions'])
30
50
  @unsafe_file_upload = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'unsafe-file-upload'])
31
51
  @untrusted_deserialization = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'untrusted-deserialization'])
32
52
  @xxe = Contrast::Config::ProtectRuleConfiguration.new(hsh[:xxe])
33
53
  end
34
54
 
35
- def bot_blocker
36
- @bot_blocker ||= Contrast::Config::ProtectRuleConfiguration.new
37
- end
38
-
39
- def cmd_injection
40
- @cmd_injection ||= Contrast::Config::ProtectRuleConfiguration.new
41
- end
42
-
43
- def sql_injection
44
- @sql_injection ||= Contrast::Config::ProtectRuleConfiguration.new
45
- end
46
-
47
- def nosql_injection
48
- @nosql_injection ||= Contrast::Config::ProtectRuleConfiguration.new
49
- end
50
-
51
- def untrusted_deserialization
52
- @untrusted_deserialization ||= Contrast::Config::ProtectRuleConfiguration.new
53
- end
54
-
55
- def method_tampering
56
- @method_tampering ||= Contrast::Config::ProtectRuleConfiguration.new
57
- end
58
-
59
- def xxe
60
- @xxe ||= Contrast::Config::ProtectRuleConfiguration.new
61
- end
62
-
63
- def path_traversal
64
- @path_traversal ||= Contrast::Config::ProtectRuleConfiguration.new
65
- end
66
-
67
- def reflected_xss
68
- @reflected_xss ||= Contrast::Config::ProtectRuleConfiguration.new
69
- end
70
-
71
- def unsafe_file_upload
72
- @unsafe_file_upload ||= Contrast::Config::ProtectRuleConfiguration.new
73
- end
74
-
75
- def rule_base
76
- @rule_base ||= Contrast::Config::ProtectRuleConfiguration.new
77
- end
78
-
79
55
  def []= key, value
80
56
  instance_variable_set("@#{ convert_key(key) }".to_sym, value)
81
57
  end
@@ -90,7 +66,7 @@ module Contrast
90
66
 
91
67
  # Convert instance variable names to format expected by TS
92
68
  # for adding to the hash
93
- def to_hash
69
+ def to_contrast_hash
94
70
  hsh = {}
95
71
  instance_variables.each do |iv|
96
72
  # strip the '@' to get the key
@@ -9,7 +9,7 @@ module Contrast
9
9
  include Contrast::Config::BaseConfiguration
10
10
 
11
11
  # @return [String, nil]
12
- attr_accessor :name
12
+ attr_reader :name
13
13
  # @return [String, nil]
14
14
  attr_accessor :path
15
15
  # @return [String, nil]
@@ -11,13 +11,7 @@ module Contrast
11
11
  end
12
12
 
13
13
  require 'contrast/config/base_configuration'
14
- require 'contrast/config/service_configuration'
15
14
  require 'contrast/config/exception_configuration'
16
- require 'contrast/config/assess_rules_configuration'
17
15
  require 'contrast/config/protect_rule_configuration'
18
16
  require 'contrast/config/protect_rules_configuration'
19
-
20
- require 'contrast/config/ruby_configuration'
21
17
  require 'contrast/config/server_configuration'
22
- require 'contrast/config/assess_configuration'
23
- require 'contrast/config/root_configuration'
@@ -6,7 +6,14 @@ require 'fileutils'
6
6
 
7
7
  require 'contrast/config'
8
8
  require 'contrast/utils/object_share'
9
+ require 'contrast/components/agent'
10
+ require 'contrast/components/api'
11
+ require 'contrast/components/app_context'
9
12
  require 'contrast/components/scope'
13
+ require 'contrast/components/inventory'
14
+ require 'contrast/components/protect'
15
+ require 'contrast/components/assess'
16
+ require 'contrast/config/server_configuration'
10
17
 
11
18
  module Contrast
12
19
  # This is how we read in the local settings for the Agent, both ENV/ CMD line
@@ -18,11 +25,30 @@ module Contrast
18
25
  include Contrast::Components::Scope::InstanceMethods
19
26
  extend Contrast::Components::Scope::InstanceMethods
20
27
 
21
- attr_reader :default_name, :root
28
+ include Contrast::Config::BaseConfiguration
29
+
30
+ attr_reader :default_name
31
+
32
+ # @return [Contrast::Components::Api::Interface]
33
+ attr_writer :api
34
+ # @return [Contrast::Components::Agent::Interface]
35
+ attr_writer :agent
36
+ # @return [Contrast::Components::AppContext::Interface]
37
+ attr_writer :application
38
+ # @return [Contrast::Config::ServerConfiguration]
39
+ attr_writer :server
40
+ # @return [Contrast::Components::Assess::Interface]
41
+ attr_writer :assess
42
+ # @return [Contrast::Components::Inventory::Interface]
43
+ attr_writer :inventory
44
+ # @return [Contrast::Components::Protect::Interface]
45
+ attr_writer :protect
46
+ # @return [Boolean, nil]
47
+ attr_accessor :enable
22
48
 
23
49
  DEFAULT_YAML_PATH = 'contrast_security.yaml'
24
50
  MILLISECOND_MARKER = '_ms'
25
- CONVERSION = { 'agent.service.enable' => 'agent.start_bundled_service' }.cs__freeze
51
+ CONVERSION = {}.cs__freeze
26
52
  CONFIG_BASE_PATHS = ['', 'config/', '/etc/contrast/ruby/', '/etc/contrast/', '/etc/'].cs__freeze
27
53
  KEYS_TO_REDACT = %i[api_key url service_key user_name].cs__freeze
28
54
  REDACTED = '**REDACTED**'
@@ -40,20 +66,14 @@ module Contrast
40
66
  # Some in-flight rewrites to maintain backwards compatibility
41
67
  config_kv = update_prop_keys(config_kv)
42
68
 
43
- @root = Contrast::Config::RootConfiguration.new(config_kv)
44
- end
45
-
46
- # Because we call this method to determine the need for scoping, it itself
47
- # must be executed inside a Contrast scope. Failure to do so could result
48
- # in an infinite loop on the to_sym method used later.
49
- def method_missing symbol, *args
50
- with_contrast_scope do
51
- root.public_send(symbol, *args) if root.cs__respond_to?(symbol)
52
- end
53
- end
54
-
55
- def respond_to_missing? method_name, *args
56
- root&.cs__respond_to?(method_name) || super
69
+ @api = Contrast::Components::Api::Interface.new(config_kv[:api])
70
+ @enable = config_kv[:enable]
71
+ @agent = Contrast::Components::Agent::Interface.new(config_kv[:agent])
72
+ @application = Contrast::Components::AppContext::Interface.new(config_kv[:application])
73
+ @server = Contrast::Config::ServerConfiguration.new(config_kv[:server])
74
+ @assess = Contrast::Components::Assess::Interface.new(config_kv[:assess])
75
+ @inventory = Contrast::Components::Inventory::Interface.new(config_kv[:inventory])
76
+ @protect = Contrast::Components::Protect::Interface.new(config_kv[:protect])
57
77
  end
58
78
 
59
79
  # Get a loggable YAML format of this configuration
@@ -63,6 +83,41 @@ module Contrast
63
83
  convert_to_hash.to_yaml
64
84
  end
65
85
 
86
+ # @return [Contrast::Components::Api::Interface]
87
+ def api
88
+ @api ||= Contrast::Components::Api::Interface.new # rubocop:disable Naming/MemoizedInstanceVariableName
89
+ end
90
+
91
+ # @return [Contrast::Components::Agent::Interface]
92
+ def agent
93
+ @agent ||= Contrast::Components::Agent::Interface.new # rubocop:disable Naming/MemoizedInstanceVariableName
94
+ end
95
+
96
+ # @return [Contrast::Components::AppContext::Interface]
97
+ def application
98
+ @application ||= Contrast::Components::AppContext::Interface.new # rubocop:disable Naming/MemoizedInstanceVariableName
99
+ end
100
+
101
+ # @return [Contrast::Config::ServerConfiguration]
102
+ def server
103
+ @server ||= Contrast::Config::ServerConfiguration.new # rubocop:disable Naming/MemoizedInstanceVariableName
104
+ end
105
+
106
+ # @return [Contrast::Components::Assess::Interface]
107
+ def assess
108
+ @assess ||= Contrast::Components::Assess::Interface.new # rubocop:disable Naming/MemoizedInstanceVariableName
109
+ end
110
+
111
+ # @return [Contrast::Components::Inventory::Interface]
112
+ def inventory
113
+ @inventory ||= Contrast::Components::Inventory::Interface.new # rubocop:disable Naming/MemoizedInstanceVariableName
114
+ end
115
+
116
+ # @return [Contrast::Components::Protect::Interface]
117
+ def protect
118
+ @protect ||= Contrast::Components::Protect::Interface.new # rubocop:disable Naming/MemoizedInstanceVariableName
119
+ end
120
+
66
121
  protected
67
122
 
68
123
  # TODO: RUBY-546 move utility methods to auxiliary classes
@@ -213,11 +268,11 @@ module Contrast
213
268
  # @return [Hash, Object] the leaf of each
214
269
  # Contrast::Config::BaseConfiguration will be returned in the N > 0 steps
215
270
  # the Hash will be returned at the end of the 0 level
216
- def convert_to_hash convert = root, hash = {}
271
+ def convert_to_hash convert = self, hash = {}
217
272
  case convert
218
273
  when Contrast::Config::BaseConfiguration
219
274
  # to_hash returns @configuration_map
220
- convert.to_hash.each_key do |key|
275
+ convert.to_contrast_hash.each_key do |key|
221
276
  # change '-' to '_' for ProtectRulesConfiguration
222
277
  hash[key] = convert_to_hash(convert.send(key.tr('-', '_').to_sym), {})
223
278
  hash[key] = REDACTED if redactable?(key)
@@ -5,6 +5,7 @@ require 'contrast/agent/patching/policy/patch'
5
5
  require 'contrast/agent/patching/policy/patcher'
6
6
  require 'contrast/components/scope'
7
7
  require 'contrast/agent/assess/events/event_data'
8
+ require 'cs__assess_array/cs__assess_array'
8
9
 
9
10
  module Contrast
10
11
  module Extension
@@ -61,6 +62,14 @@ module Contrast
61
62
  end
62
63
  end
63
64
  end
65
+
66
+ # Helper module to call cs__join
67
+ module ContrastArray
68
+ def join *args
69
+ cs__join(*args)
70
+ super(*args)
71
+ end
72
+ end
64
73
  end
65
74
  end
66
75
  end
@@ -19,7 +19,9 @@ module Contrast
19
19
  # source might not be all the args passed in, but it is the one we care
20
20
  # about. we could pass in all the args in the last param here if it
21
21
  # becomes an issue in rendering on TS
22
- Contrast::Agent::Assess::Policy::TriggerMethod.build_finding(trigger_node, source, Kernel, nil, source)
22
+ finding = Contrast::Agent::Assess::Policy::TriggerMethod.build_finding(trigger_node,
23
+ source, Kernel, nil, source)
24
+ Contrast::Agent::Assess::Policy::TriggerMethod.report_finding(finding) if finding
23
25
  end
24
26
 
25
27
  private
@@ -36,8 +36,9 @@ module Contrast
36
36
  # source might not be all the args passed in, but it is the one we care
37
37
  # about. we could pass in all the args in the last param here if it
38
38
  # becomes an issue in rendering on TS
39
- Contrast::Agent::Assess::Policy::TriggerMethod.build_finding(trigger_node('Marshal', :load), source,
40
- self, ret, *args)
39
+ finding = Contrast::Agent::Assess::Policy::TriggerMethod.build_finding(trigger_node('Marshal', :load),
40
+ source, self, ret, *args)
41
+ Contrast::Agent::Assess::Policy::TriggerMethod.report_finding(finding) if finding
41
42
  return unless (properties = Contrast::Agent::Assess::Tracker.properties!(ret))
42
43
 
43
44
  properties.copy_from(source, ret)
@@ -37,7 +37,6 @@ module Contrast
37
37
  # @param inputs [Array<String>] Inputs for interpolation.
38
38
  # @param result [String] The result from the interpolation.
39
39
  def track_interpolation inputs, result
40
- return unless ::Contrast::AGENT.interpolation_enabled?
41
40
  return unless inputs.any? { |input| Contrast::Agent::Assess::Tracker.tracked?(input) }
42
41
  return unless (properties = Contrast::Agent::Assess::Tracker.properties!(result))
43
42
 
@@ -1,6 +1,8 @@
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 'delegate'
5
+
4
6
  # Some developers override various methods on Delegator, which can often
5
7
  # involve changing expected method parity/behavior which in turn prevents us
6
8
  # from being able to reliably use affected methods. Let's alias these methods
@@ -36,7 +36,7 @@ module Contrast
36
36
  # conditions
37
37
  def assign_value path
38
38
  case path
39
- when /fiber/, /interpolation26/
39
+ when /fiber/, /interpolation/
40
40
  require(path) if Funchook.available?
41
41
  else
42
42
  require(path)
@@ -41,11 +41,6 @@ module Contrast
41
41
  raise(NoMethodError, 'Subclasses of BaseSupport should implement this method')
42
42
  end
43
43
 
44
- # @raise [NoMethodError] raises error if subclass does not implement this method
45
- def current_route
46
- raise(NoMethodError, 'Subclasses of BaseSupport should implement this method')
47
- end
48
-
49
44
  # @raise [NoMethodError] raises error if subclass does not implement this method
50
45
  def retrieve_request _env
51
46
  raise(NoMethodError, 'Subclasses of BaseSupport should implement this method')
@@ -68,29 +68,6 @@ module Contrast
68
68
  routes
69
69
  end
70
70
 
71
- # Given the current request return a RouteCoverage dtm.
72
- #
73
- # @param request [Contrast::Agent::Request] a contrast tracked request.
74
- # @param controller [::Grape::API] optionally use this controller instead of global ::Grape::API.
75
- # @return [Contrast::Api::Dtm::RouteCoverage, nil] a Dtm describing the route
76
- # matched to the request if a match was found.
77
- def current_route request, controller = ::Grape::API, full_route = nil
78
- return unless grape_controller?(controller)
79
-
80
- method = request.env[::Rack::REQUEST_METHOD] # GET, PUT, POST, etc...
81
-
82
- # Find final controller - actually we gotta match the route to the scanned application
83
- # Initially Grape compiles all routes on startup, so we can use the url from the request
84
- # and create the observed route
85
- # Class < Grape::API, Grape::Router::Route
86
- final_controller, route_pattern = _route_recurse(method, _cleaned_route(request), grape_controllers)
87
- return unless final_controller
88
-
89
- full_route ||= request.env[::Rack::PATH_INFO]
90
-
91
- Contrast::Api::Dtm::RouteCoverage.from_grape_controller(final_controller, method, route_pattern, full_route)
92
- end
93
-
94
71
  # Given the current request - return a RouteCoverage object
95
72
 
96
73
  # @param request [Contrast::Agent::Request] a contrast tracked request.
@@ -113,6 +90,7 @@ module Contrast
113
90
 
114
91
  new_route_coverage = Contrast::Agent::Reporting::RouteCoverage.new
115
92
  new_route_coverage.attach_rack_based_data(final_controller, method, route_pattern, full_route)
93
+ new_route_coverage
116
94
  end
117
95
 
118
96
  # Search object space for grape controllers--any class that subclasses ::Grape::API.
@@ -71,9 +71,11 @@ module Contrast
71
71
  first_framework_result(:application_name, 'root')
72
72
  end
73
73
 
74
+ # @return app_root [String] path
74
75
  def app_root
75
76
  found = first_framework_result(:application_root, nil)
76
- found || ::Rack::Directory.new('').root
77
+ found ||= ::Rack::Directory.new('').root
78
+ found.to_s
77
79
  end
78
80
 
79
81
  # Build a request from the provided env, based on the framework(s) we're currently supporting.
@@ -108,16 +110,6 @@ module Contrast
108
110
  result
109
111
  end
110
112
 
111
- # Iterate through current frameworks and return the current request's route. This will be the first non-nil
112
- # result.
113
- #
114
- # @param request [Contrast::Agent::Request] the current request.
115
- # @return [Contrast::Api::Dtm::RouteCoverage] the current route as a Dtm.
116
- def get_route_dtm request
117
- @_frameworks.lazy.map { |framework_support| framework_support.current_route(request) }.
118
- reject(&:nil?).first # rubocop:disable Style/CollectionCompact
119
- end
120
-
121
113
  # Iterate through current frameworks and return the current request's route. This will be the first non-nil
122
114
  # result.
123
115
  #
@@ -20,12 +20,7 @@ module Contrast
20
20
  Contrast::Agent.reporter&.send_event_immediately(event)
21
21
  end
22
22
 
23
- if Contrast::Agent::Reporter.enabled?
24
- event = Contrast::Agent::Reporting::DtmMessage.dtm_to_event(context.activity)
25
- Contrast::Agent.reporter&.send_event_immediately(event)
26
- else
27
- Contrast::Agent.messaging_queue&.send_event_immediately(context.activity)
28
- end
23
+ Contrast::Agent.reporter&.send_event_immediately(context.activity)
29
24
  end
30
25
 
31
26
  def instrument
@@ -25,7 +25,6 @@ module Contrast
25
25
  end
26
26
 
27
27
  rake_tasks do
28
- load 'contrast/tasks/service.rb'
29
28
  load 'contrast/tasks/config.rb'
30
29
  end
31
30
  end
@@ -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/framework/base_support'
6
5
  require 'contrast/framework/rails/patch/support'
7
6
  require 'contrast/utils/string_utils'
@@ -49,36 +48,6 @@ module Contrast
49
48
  find_all_routes(::Rails.application, [])
50
49
  end
51
50
 
52
- # Find the current route, based on the provided Request wrapper
53
- #
54
- # @param request[Contrast::Agent::Request]
55
- # @return [Contrast::Api::Dtm::RouteCoverage, nil]
56
- def current_route request
57
- return unless ::Rails.cs__respond_to?(:application)
58
-
59
- # ActionDispatch::Journey::Path::Pattern::MatchData, Hash, ActionDispatch::Journey::Route, Array<String>
60
- match, _params, route, path = get_full_route(request.rack_request)
61
- unless route
62
- logger.warn("Unable to determine the current route of this request: #{ request.rack_request }")
63
- return
64
- end
65
-
66
- original_url = request.rack_request.path_info
67
- mounted_app = route&.app&.app
68
- # Route is either the final rails route, or a router that points to a Sinatra controller.
69
- if mounted_app && Contrast::Framework::Sinatra::Support.sinatra_controller?(mounted_app)
70
- return mounted_sinatra_route(request, match, path, route, original_url)
71
- end
72
- if mounted_app && Contrast::Framework::Grape::Support.grape_controller?(mounted_app)
73
- return mounted_grape_route(request, match, path, route, original_url)
74
- end
75
-
76
- Contrast::Api::Dtm::RouteCoverage.from_action_dispatch_journey(route, original_url)
77
- rescue StandardError => e
78
- logger.warn('Unable to determine the current route of this request', e)
79
- nil
80
- end
81
-
82
51
  # Find the current route, based on the provided Request wrapper
83
52
  #
84
53
  # @param request[Contrast::Agent::Request]
@@ -105,9 +74,10 @@ module Contrast
105
74
  end
106
75
 
107
76
  new_route_coverage = Contrast::Agent::Reporting::RouteCoverage.new
108
- new_route_coverage.attach_rails_data(route, original_url)
77
+ new_route_coverage&.attach_rails_data(route, original_url)
78
+ new_route_coverage
109
79
  rescue StandardError => e
110
- logger.warn('Unable to determine the current route of this request', e)
80
+ logger.warn('Unable to determine the current route of this request due to exception: ', e)
111
81
  nil
112
82
  end
113
83
 
@@ -132,7 +102,7 @@ module Contrast
132
102
  # Determine if route is a Rails engine route.
133
103
  #
134
104
  # @param route [Object] app or route that points to a ::Rails::Engine
135
- # @return [bool] whether the router is an engine or not.
105
+ # @return [Boolean, nil] whether the router is an engine or not.
136
106
  def engine_route? route
137
107
  return false unless route&.app&.app
138
108
  return false unless route.app.is_a?(::ActionDispatch::Routing::Mapper::Constraints) ||
@@ -155,7 +125,7 @@ module Contrast
155
125
 
156
126
  match, params, route = route_matches.first
157
127
 
158
- # If the current routing node points to a sub-app (::Rais::Engine), dive deeper.
128
+ # If the current routing node points to a sub-app (::Rails::Engine), dive deeper.
159
129
  # Have sub-app route the remainder of the url.
160
130
  if engine_route?(route)
161
131
  new_req = retrieve_request(request.env)
@@ -186,36 +156,12 @@ module Contrast
186
156
  route_list
187
157
  end
188
158
 
189
- # @param request[Contrast::Agent::Request]
190
- # @param match [ActionDispatch::Journey::Path::Pattern::MatchData]
191
- # @param path [Array<String>] the path of this request, built out from each nested
192
- # ActionDispatch::Journey::Path::Pattern::MatchData
193
- # @param route [::ActionDispatch::Journey::Route]
194
- # @param original_url [String] the full url of this request, including the mount
195
- # @return [Contrast::Api::Dtm::RouteCoverage, nil]
196
- def mounted_sinatra_route request, match, path, route, original_url
197
- new_req = unmounted_route(request, match, path)
198
- Contrast::Framework::Sinatra::Support.current_route(new_req, route.app.app, original_url)
199
- end
200
-
201
159
  # @return [Contrast::Agent::Reporting::RouteCoverage, nil]
202
160
  def mounted_new_sinatra_route request, match, path, route, original_url
203
161
  new_req = unmounted_route(request, match, path)
204
162
  Contrast::Framework::Sinatra::Support.current_route_coverage(new_req, route.app.app, original_url)
205
163
  end
206
164
 
207
- # @param request[Contrast::Agent::Request]
208
- # @param match [ActionDispatch::Journey::Path::Pattern::MatchData]
209
- # @param path [Array<String>] the path of this request, built out from each nested
210
- # ActionDispatch::Journey::Path::Pattern::MatchData
211
- # @param route [::ActionDispatch::Journey::Route]
212
- # @param original_url [String] the full url of this request, including the mount
213
- # @return [Contrast::Api::Dtm::RouteCoverage, nil]
214
- def mounted_grape_route request, match, path, route, original_url
215
- new_req = unmounted_route(request, match, path)
216
- Contrast::Framework::Grape::Support.current_route(new_req, route.app.app, original_url)
217
- end
218
-
219
165
  # @return [Contrast::Agent::Reporting::RouteCoverage, nil]
220
166
  def mounted_new_grape_route request, match, path, route, original_url
221
167
  new_req = unmounted_route(request, match, path)
@@ -64,26 +64,6 @@ module Contrast
64
64
  routes
65
65
  end
66
66
 
67
- # Given the current request return a RouteCoverage dtm.
68
- #
69
- # @param request [Contrast::Agent::Request] a contrast tracked request.
70
- # @param controller [::Sinatra::Base] optionally use this controller instead of global ::Sinatra::Base.
71
- # @return [Contrast::Api::Dtm::RouteCoverage, nil] a Dtm describing the route
72
- # matched to the request if a match was found.
73
- def current_route request, controller = ::Sinatra::Base, full_route = nil
74
- return unless sinatra_controller?(controller)
75
-
76
- method = request.env[::Rack::REQUEST_METHOD] # GET, PUT, POST, etc...
77
-
78
- # Find route match--checking superclasses if necessary.
79
- final_controller, route_pattern = _route_recurse(controller, method, _cleaned_route(request))
80
- return unless !final_controller.nil? && !route_pattern.nil?
81
-
82
- full_route ||= request.path_info
83
-
84
- Contrast::Api::Dtm::RouteCoverage.from_sinatra_route(final_controller, method, route_pattern, full_route)
85
- end
86
-
87
67
  # Given the current request - return a RouteCoverage object
88
68
 
89
69
  # @param request [Contrast::Agent::Request] a contrast tracked request.
@@ -97,12 +77,13 @@ module Contrast
97
77
 
98
78
  # Find route match--checking superclasses if necessary.
99
79
  final_controller, route_pattern = _route_recurse(controller, method, _cleaned_route(request))
100
- return unless final_controller
80
+ return unless final_controller && route_pattern
101
81
 
102
82
  full_route ||= request.env[::Rack::PATH_INFO]
103
83
 
104
84
  new_route_coverage = Contrast::Agent::Reporting::RouteCoverage.new
105
85
  new_route_coverage.attach_rack_based_data(final_controller, method, route_pattern, full_route)
86
+ new_route_coverage
106
87
  end
107
88
 
108
89
  # Search object space for sinatra controllers--any class that subclasses ::Sinatra::Base.
@@ -51,16 +51,20 @@ module Contrast
51
51
  # set by local configuration.
52
52
  #
53
53
  # @param log_level [String] the level at which to log, as provided by TeamServer settings
54
- def build_logger log_level = nil
54
+ # @param log_file [String] the file to which to log, as provided by TeamServer settings
55
+ def build_logger log_level = nil, log_file = nil
56
+ current_path_const = find_valid_path(log_file)
55
57
  current_level_const = find_valid_level(log_level)
56
58
  level_change = current_level_const != previous_level
59
+ path_change = current_path_const != previous_path
57
60
 
58
61
  # don't needlessly recreate logger
59
- return if @cef_logger && !level_change
62
+ return if @cef_logger && !(level_change || path_change)
60
63
 
61
64
  @previous_level = current_level_const
65
+ @previous_path = current_path_const
62
66
 
63
- @_cef_logger = build(path: DEFAULT_CEF_NAME, level_const: current_level_const)
67
+ @_cef_logger = build(path: current_path_const, level_const: current_level_const)
64
68
  # If we're logging to a new path, then let's start it w/ our helpful
65
69
  # data gathering messages
66
70
  # log_update if path_change
@@ -82,6 +86,20 @@ module Contrast
82
86
  @_cef_logger
83
87
  end
84
88
 
89
+ def find_valid_path log_file
90
+ config = ::Contrast::CONFIG.agent.security_logger
91
+ config_path = config&.path&.length.to_i.positive? ? config.path : nil
92
+ valid_path(config_path || log_file, default_name: DEFAULT_CEF_NAME)
93
+ end
94
+
95
+ # @return [::Ougai::Logging::Severity] the level at which to log
96
+ def find_valid_level log_level
97
+ config = ::Contrast::CONFIG.agent.security_logger
98
+ config_level = config&.level&.length&.positive? ? config.level : nil
99
+
100
+ valid_level(config_level || log_level)
101
+ end
102
+
85
103
  def log msg, level = @_cef_logger.level
86
104
  case level
87
105
  when ::Logger::Severity::INFO