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
@@ -0,0 +1,118 @@
1
+ # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
+ # frozen_string_literal: true
3
+
4
+ module Contrast
5
+ module AgentLib
6
+ # Base class to set basic rule sets and input list.
7
+ class InterfaceBase
8
+ # This could be changed to regular Hash.
9
+ # This format is used to supports this kind of log_level assignment:
10
+ # via Contrast::Api::Settings::LogLevel::WARN => 3
11
+ # ( note -1 is not supported in the protobuf LogLevel)
12
+ LOG_LEVEL = { -1 => 'OFF', 0 => 'TRACE', 1 => 'DEBUG', 2 => 'INFO', 3 => 'WARN', 4 => 'ERROR' }.cs__freeze
13
+ LOG_DIR = File.join(Dir.pwd).cs__freeze
14
+ # Named after Protect rule_id / Names
15
+ # Corresponding to Rust's ulong enum
16
+ RULE_SET = {
17
+ 'unsafe-file-upload' => 1 << 0,
18
+ 'path-traversal' => 1 << 1,
19
+ 'reflected-xss' => 1 << 2,
20
+ 'sql-injection' => 1 << 3,
21
+ 'cmd-injection' => 1 << 4,
22
+ 'nosql-injection' => 1 << 5,
23
+ 'bot-blocker' => 1 << 6,
24
+ 'ssjs-injection' => 1 << 7,
25
+ 'method-tampering' => 1 << 8
26
+ }.cs__freeze
27
+ # Named same as Contrast::Agent::Reporting::InputTypes
28
+ INPUT_SET = {
29
+ COOKIE_NAME: 1,
30
+ COOKIE_VALUE: 2,
31
+ HEADER_NAME: 3,
32
+ HEADER_VALUE: 4,
33
+ JSON_NAME: 5,
34
+ JSON_VALUE: 6,
35
+ METHOD: 7,
36
+ PARAMETER_NAME: 8,
37
+ PARAMETER_VALUE: 9,
38
+ URI: 10,
39
+ URL_PARAMETER: 11,
40
+ MULTIPART_NAME: 12,
41
+ XML_VALUE: 13
42
+ }.cs__freeze
43
+ EVAL_OPTIONS = { NONE: 0, WORTHWATCHING: 1 }.cs__freeze
44
+
45
+ # Initializes the Agent lib.
46
+ #
47
+ # @param enable_logging [Boolean, nil] flag to enable or disable logging.
48
+ # @param set_log_level [Integer, nil]
49
+ # @param set_log_dir [String, nil] dir to write log files.
50
+ # @return [Boolean] true if success.
51
+ # @raise [StandardError] Any Errors raised in the init process are most
52
+ # likely to be a C segfaults and termination, probably redundant but safe.
53
+ def initialize enable_logging = nil, set_log_level = nil, set_log_dir = nil
54
+ # Override
55
+ end
56
+
57
+ # Return list of available rules
58
+ #
59
+ # @return [Hash]
60
+ def rule_set
61
+ RULE_SET
62
+ end
63
+
64
+ # Returns list of available input types.
65
+ #
66
+ # @return [Hash]
67
+ def input_set
68
+ INPUT_SET
69
+ end
70
+
71
+ # Return list of input evaluation options:
72
+ # WorthWatching or none
73
+ #
74
+ # @return [Hash]
75
+ def eval_option
76
+ EVAL_OPTIONS
77
+ end
78
+
79
+ private
80
+
81
+ # Updates the logging status:
82
+ # Enabled && Level
83
+ #
84
+ # @param level [Integer] one of:
85
+ # [-1...4]
86
+ # @param enabled [Boolean] logging status.
87
+ def update_logging level, enabled
88
+ update_log_level(level)
89
+ @enable_log = !!enabled
90
+ end
91
+
92
+ # Updates the log level for the AgentLib.
93
+ #
94
+ # @param level [Integer] one of:
95
+ # [-1...4]
96
+ def update_log_level level
97
+ value = LOG_LEVEL[level]
98
+ @log_level = value if value
99
+ end
100
+
101
+ # Creates the directory for AgentLib log files.
102
+ # If no path provided use default.
103
+ #
104
+ # @param log_dir [String, nil] path to log.
105
+ # @rescue [StandardError] any error concerning
106
+ # the directory creation.
107
+ def create_log_dir log_dir = nil
108
+ path = log_dir.nil? ? LOG_DIR : log_dir
109
+ FileUtils.mkdir_p(path)
110
+ path
111
+ rescue StandardError => e
112
+ logger.debug('Could not create log directory', error: e)
113
+ FileUtils.mkdir_p(LOG_DIR)
114
+ LOG_DIR
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,44 @@
1
+ # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
+ # frozen_string_literal: true
3
+
4
+ require 'contrast/agent_lib/interface'
5
+
6
+ module Contrast
7
+ module AgentLib
8
+ # This class will hold resulst received form AgentLib structs.
9
+ class EvalResult
10
+ # Name of the Protect rule analyzed.
11
+ # @return [String]
12
+ attr_accessor :rule_id
13
+ # Type of the input.
14
+ # @return [String]
15
+ attr_accessor :input_type
16
+ # Score of the input after AgentLib
17
+ # Analysis
18
+ #
19
+ # @return score [Float]
20
+ attr_accessor :score
21
+
22
+ # Init a new EvalResult, and translate results to usable for
23
+ # reporting values.
24
+ #
25
+ # @param hsh [Hash, nil] return from AgentLib populated struct.
26
+ def initialize hsh
27
+ return unless hsh&.cs__is_a?(Hash)
28
+
29
+ @rule_id = Contrast::AgentLib::Interface::RULE_SET.key(hsh[:rule_id])
30
+ @input_type = Contrast::AgentLib::Interface::INPUT_SET.key(hsh[:input_type])
31
+ @score = hsh[:score]
32
+ end
33
+
34
+ # Used in specs.
35
+ def to_controlled_hash
36
+ {
37
+ rule_id: rule_id,
38
+ input_type: input_type,
39
+ score: score
40
+ }
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,29 @@
1
+ # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
+ # frozen_string_literal: false
3
+
4
+ require_relative 'api/init'
5
+
6
+ module Contrast # :nodoc:
7
+ module Test # :nodoc:
8
+ extend Contrast::AgentLib::Init
9
+
10
+ LOG_DIR = File.join(File.dirname(__FILE__))
11
+
12
+ class << self
13
+ def test_init_with_options enable_log, log_level
14
+ dl__init_with_options(enable_log, LOG_DIR, log_level)
15
+ end
16
+ end
17
+ end
18
+ end
19
+
20
+ # for the other cases - I tried with loop and everything, but nothing worked
21
+ # Contrast::Test.test_init_with_options(true, "WARN")
22
+ # Contrast::Test.test_init_with_options(true, "ERROR")
23
+ # Contrast::Test.test_init_with_options(true, "DEBUG")
24
+ # Contrast::Test.test_init_with_options(true, "TRACE")
25
+ response = Contrast::Test.test_init_with_options(true, 'INFO')
26
+ puts response # rubocop:disable Rails/Output
27
+
28
+ # we cannot check here for the file as it's being created after the execution of the file is done
29
+ raise(StandardError, 'Not Working') if response == false
@@ -4,7 +4,7 @@
4
4
  module Contrast
5
5
  module Api
6
6
  module Communication
7
- # Keeps track of the state of connections to SpeedRacer.
7
+ # Keeps track of the state of connections to TeamServer.
8
8
  class ConnectionStatus
9
9
  def initialize
10
10
  @last_success = nil
@@ -12,8 +12,8 @@ module Contrast
12
12
  @startup_messages_sent = false
13
13
  end
14
14
 
15
- # Whether we have sent startup message to SpeedRacer. True after successfully sending startup messages to
16
- # SpeedRacer and reset to false if we lose connection.
15
+ # Whether we have sent startup message to TeamServer. True after successfully sending startup messages to
16
+ # TeamServer and reset to false if we lose connection.
17
17
  #
18
18
  # @return [Boolean]
19
19
  def startup_messages_sent?
@@ -27,13 +27,13 @@ module Contrast
27
27
  @last_success && (@last_failure.nil? || @last_success > @last_failure)
28
28
  end
29
29
 
30
- # The current state of the SpeedRacer is active with a successful message sent
30
+ # The current state of the TeamServer is active with a successful message sent
31
31
  def success!
32
32
  @startup_messages_sent = true
33
33
  @last_success = Time.now.to_f
34
34
  end
35
35
 
36
- # The SpeedRacer may be in some sort of error state
36
+ # The TeamServer may be in some sort of error state
37
37
  def failure!
38
38
  @startup_messages_sent = false
39
39
  @last_failure = Time.now.to_f
@@ -4,7 +4,9 @@
4
4
  require 'rubygems/version'
5
5
  require 'contrast/agent/rule_set'
6
6
  require 'contrast/components/logger'
7
+ require 'contrast/components/security_logger'
7
8
  require 'contrast/components/heap_dump'
9
+ require 'contrast/components/ruby_component'
8
10
 
9
11
  module Contrast
10
12
  module Components
@@ -19,35 +21,29 @@ module Contrast
19
21
  return unless hsh
20
22
 
21
23
  @_enable = hsh[:enable]
22
- @_start_bundled_service = hsh[:start_bundled_service]
23
24
  @_omit_body = hsh[:omit_body]
24
- @_service = Contrast::Config::ServiceConfiguration.new(hsh[:service])
25
25
  @_logger = Contrast::Components::Logger::Interface.new(hsh[:logger])
26
- @_ruby = Contrast::Config::RubyConfiguration.new(hsh[:ruby])
26
+ @_security_logger = Contrast::Components::SecurityLogger::Interface.new(hsh[:security_logger])
27
+ @_ruby = Contrast::Components::Ruby::Interface.new(hsh[:ruby])
27
28
  @_heap_dump = Contrast::Components::HeapDump::Interface.new(hsh[:heap_dump])
28
29
  end
29
30
 
30
- # @return [Boolean, true]
31
- def start_bundled_service?
32
- @_start_bundled_service.nil? ? true : @_start_bundled_service
33
- end
34
-
35
- def service
36
- return @_service unless @_service.nil?
37
-
38
- @_service = Contrast::Config::ServiceConfiguration.new
39
- end
40
-
41
31
  def logger
42
32
  return @_logger unless @_logger.nil?
43
33
 
44
34
  @_logger = Contrast::Components::Logger::Interface.new
45
35
  end
46
36
 
37
+ def security_logger
38
+ return @_security_logger unless @_security_logger.nil?
39
+
40
+ @_security_logger = Contrast::Components::SecurityLogger::Interface.new
41
+ end
42
+
47
43
  def ruby
48
44
  return @_ruby unless @_ruby.nil?
49
45
 
50
- @_ruby = Contrast::Config::RubyConfiguration.new
46
+ @_ruby = Contrast::Components::Ruby::Interface.new
51
47
  end
52
48
 
53
49
  def heap_dump
@@ -57,7 +53,7 @@ module Contrast
57
53
  end
58
54
 
59
55
  def enabled?
60
- @_enable = !false?(::Contrast::CONFIG.root.enable) if @_enable.nil?
56
+ @_enable = !false?(::Contrast::CONFIG.enable) if @_enable.nil?
61
57
  @_enable
62
58
  end
63
59
 
@@ -87,12 +83,6 @@ module Contrast
87
83
  !false?(ruby.propagate_yield)
88
84
  end
89
85
 
90
- def interpolation_enabled?
91
- return @_interpolation_enabled unless @_interpolation_enabled.nil?
92
-
93
- @_interpolation_enabled = !false?(::Contrast::CONFIG.root.agent.ruby.interpolate)
94
- end
95
-
96
86
  def omit_body?
97
87
  @_omit_body
98
88
  end
@@ -108,7 +98,7 @@ module Contrast
108
98
  def skip_instrumentation? loaded_module_name
109
99
  return true unless loaded_module_name
110
100
 
111
- loaded_module_name.start_with?(*::Contrast::CONFIG.root.agent.ruby.uninstrument_namespace)
101
+ loaded_module_name.start_with?(*::Contrast::CONFIG.agent.ruby.uninstrument_namespace)
112
102
  end
113
103
 
114
104
  # Insert ourselves into the application, keeping our middleware at the outermost layer of the onion
@@ -66,7 +66,7 @@ module Contrast
66
66
 
67
67
  def api_url
68
68
  @_api_url ||= begin
69
- tmp = Contrast::CONFIG.root.api.url
69
+ tmp = Contrast::CONFIG.api.url
70
70
  tmp += '/Contrast' unless tmp.end_with?('/Contrast')
71
71
  tmp
72
72
  end
@@ -75,7 +75,7 @@ module Contrast
75
75
  def proxy_enable
76
76
  return @_proxy_enable unless @_proxy_enable.nil?
77
77
 
78
- @_proxy_enable = true?(::Contrast::CONFIG.root.api.proxy.enable)
78
+ @_proxy_enable = true?(::Contrast::CONFIG.api.proxy.enable)
79
79
  end
80
80
 
81
81
  def proxy_url
@@ -85,39 +85,39 @@ module Contrast
85
85
  def request_audit_enable
86
86
  return @_request_audit_enable unless @_request_audit_enable.nil?
87
87
 
88
- @_request_audit_enable = true?(::Contrast::CONFIG.root.api.request_audit.enable)
88
+ @_request_audit_enable = true?(::Contrast::CONFIG.api.request_audit.enable)
89
89
  end
90
90
 
91
91
  def request_audit_requests
92
92
  return @_request_audit_requests unless @_request_audit_requests.nil?
93
93
 
94
- @_request_audit_requests = true?(::Contrast::CONFIG.root.api.request_audit.requests)
94
+ @_request_audit_requests = true?(::Contrast::CONFIG.api.request_audit.requests)
95
95
  end
96
96
 
97
97
  def request_audit_responses
98
98
  return @_request_audit_responses unless @_request_audit_responses.nil?
99
99
 
100
- @_request_audit_responses = true?(::Contrast::CONFIG.root.api.request_audit.responses)
100
+ @_request_audit_responses = true?(::Contrast::CONFIG.api.request_audit.responses)
101
101
  end
102
102
 
103
103
  def request_audit_path
104
- @_request_audit_path ||= ::Contrast::CONFIG.root.api.request_audit.path.to_s
104
+ @_request_audit_path ||= ::Contrast::CONFIG.api.request_audit.path.to_s
105
105
  end
106
106
 
107
107
  def certification_enable
108
- @_certification_enable ||= certification_truly_enabled?(::Contrast::CONFIG.root.api.certificate)
108
+ @_certification_enable ||= certification_truly_enabled?(::Contrast::CONFIG.api.certificate)
109
109
  end
110
110
 
111
111
  def certification_ca_file
112
- @_certification_ca_file ||= ::Contrast::CONFIG.root.api.certificate.ca_file
112
+ @_certification_ca_file ||= ::Contrast::CONFIG.api.certificate.ca_file
113
113
  end
114
114
 
115
115
  def certification_cert_file
116
- @_certification_cert_file ||= ::Contrast::CONFIG.root.api.certificate.cert_file
116
+ @_certification_cert_file ||= ::Contrast::CONFIG.api.certificate.cert_file
117
117
  end
118
118
 
119
119
  def certification_key_file
120
- @_certification_key_file ||= ::Contrast::CONFIG.root.api.certificate.key_file
120
+ @_certification_key_file ||= ::Contrast::CONFIG.api.certificate.key_file
121
121
  end
122
122
 
123
123
  private
@@ -2,8 +2,6 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'rubygems/version'
5
- require 'contrast/api/decorators/agent_startup'
6
- require 'contrast/api/decorators/application_startup'
7
5
  require 'contrast/utils/object_share'
8
6
  require 'contrast/components/app_context_extend'
9
7
  require 'contrast/config/base_configuration'
@@ -27,17 +25,17 @@ module Contrast
27
25
  DEFAULT_SERVER_PATH = '/'
28
26
 
29
27
  # @return [String]
30
- attr_reader :version
28
+ attr_accessor :version
31
29
  # @return [String]
32
- attr_reader :language
30
+ attr_accessor :language
33
31
  # @return [String]
34
- attr_reader :group
32
+ attr_accessor :group
35
33
  # @return [String]
36
- attr_reader :tags
34
+ attr_accessor :tags
37
35
  # @return [String]
38
- attr_reader :code
36
+ attr_accessor :code
39
37
  # @return [String]
40
- attr_reader :metadata
38
+ attr_accessor :metadata
41
39
 
42
40
  def initialize hsh = {}
43
41
  original_pid
@@ -83,7 +81,7 @@ module Contrast
83
81
 
84
82
  def server_type
85
83
  @_server_type ||= begin
86
- tmp = ::Contrast::CONFIG.root.server.type
84
+ tmp = ::Contrast::CONFIG.server.type
87
85
  tmp = Contrast::Agent.framework_manager.server_type unless Contrast::Utils::StringUtils.present?(tmp)
88
86
  tmp
89
87
  end
@@ -118,7 +116,7 @@ module Contrast
118
116
 
119
117
  def server_name
120
118
  @_server_name ||= begin
121
- tmp = ::Contrast::CONFIG.root.server.name # rubocop:disable Security/Module/Name
119
+ tmp = ::Contrast::CONFIG.server.name # rubocop:disable Security/Module/Name
122
120
  tmp = Socket.gethostname unless Contrast::Utils::StringUtils.present?(tmp)
123
121
  tmp = Contrast::Utils::StringUtils.force_utf8(tmp)
124
122
  Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_SERVER_NAME)
@@ -129,7 +127,7 @@ module Contrast
129
127
 
130
128
  def server_path
131
129
  @_server_path ||= begin
132
- tmp = ::Contrast::CONFIG.root.server.path
130
+ tmp = ::Contrast::CONFIG.server.path
133
131
  tmp = Dir.pwd unless Contrast::Utils::StringUtils.present?(tmp)
134
132
  Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_SERVER_PATH)
135
133
  rescue StandardError
@@ -12,23 +12,6 @@ module Contrast
12
12
  SUPPORTED_FRAMEWORKS = %w[rails sinatra grape rack].cs__freeze
13
13
  SUPPORTED_SERVERS = %w[passenger puma thin unicorn].cs__freeze
14
14
 
15
- def build_app_startup_message
16
- @_build_app_startup_message ||= Contrast::Api::Dtm::ApplicationCreate.build
17
- end
18
-
19
- def build_agent_startup_message
20
- msg = Contrast::Api::Dtm::AgentStartup.build(server_name, server_path, server_type)
21
- Contrast::CONFIG.proto_logger.info('Application context',
22
- server_name: msg.server_name,
23
- server_path: msg.server_path,
24
- server_type: msg.server_type,
25
- application_name: name, # rubocop:disable Security/Module/Name
26
- application_path: path,
27
- application_language: Contrast::Utils::ObjectShare::RUBY)
28
-
29
- msg
30
- end
31
-
32
15
  def pid
33
16
  Process.pid
34
17
  end
@@ -37,14 +20,6 @@ module Contrast
37
20
  Process.ppid
38
21
  end
39
22
 
40
- def pgid
41
- Process.getpgid(pid)
42
- end
43
-
44
- def client_id
45
- @_client_id ||= [name, pgid].join('-') # rubocop:disable Security/Module/Name
46
- end
47
-
48
23
  def app_and_server_information
49
24
  {
50
25
  application_info: find_gem_information(SUPPORTED_FRAMEWORKS),
@@ -71,7 +46,7 @@ module Contrast
71
46
  end
72
47
 
73
48
  def disabled_agent_rake_tasks
74
- ::Contrast::CONFIG.root.agent.ruby.disabled_agent_rake_tasks
49
+ ::Contrast::CONFIG.agent.ruby.disabled_agent_rake_tasks
75
50
  end
76
51
  end
77
52
  end
@@ -3,7 +3,7 @@
3
3
 
4
4
  require 'contrast/components/base'
5
5
  require 'contrast/components/config'
6
- require 'contrast/components/settings'
6
+ require 'contrast/components/assess_rules'
7
7
 
8
8
  module Contrast
9
9
  module Components
@@ -12,9 +12,85 @@ module Contrast
12
12
  # for access of the values contained in its
13
13
  # parent_configuration_spec.yaml.
14
14
  # Specifically, this allows for querying the state of the Assess product.
15
- class Interface
15
+ class Interface # rubocop:disable Metrics/ClassLength
16
16
  include Contrast::Components::ComponentBase
17
17
 
18
+ # @return [String, nil]
19
+ attr_accessor :tags
20
+ # @return [Boolean, nil]
21
+ attr_accessor :enable
22
+ # @return [Array, nil]
23
+ attr_writer :enable_scan_response, :enable_dynamic_sources, :sampling, :rules, :stacktraces
24
+
25
+ DEFAULT_STACKTRACES = 'ALL'
26
+ DEFAULT_MAX_SOURCE_EVENTS = 50_000
27
+ DEFAULT_MAX_PROPAGATION_EVENTS = 50_000
28
+ DEFAULT_MAX_RULE_REPORTED = 100
29
+ DEFAULT_MAX_RULE_TIME_THRESHOLD = 300_000
30
+
31
+ # rubocop:disable Naming/MemoizedInstanceVariableName
32
+ def initialize hsh = {}
33
+ return unless hsh
34
+
35
+ @enable = hsh[:enable]
36
+ @tags = hsh[:tags]
37
+ @enable_scan_response = hsh[:enable_scan_response]
38
+ @enable_dynamic_sources = hsh[:enable_dynamic_sources]
39
+ @enable_original_object = hsh[:enable_original_object]
40
+ @sampling = Contrast::Components::Sampling::Interface.new(hsh[:sampling])
41
+ @rules = Contrast::Components::AssessRules::Interface.new(hsh[:rules])
42
+ @stacktraces = hsh[:stacktraces]
43
+ @max_context_source_events = hsh[:max_context_source_events]
44
+ @max_propagation_events = hsh[:max_propagation_events]
45
+ @max_rule_reported = hsh[:max_rule_reported]
46
+ @time_limit_threshold = hsh[:time_limit_threshold]
47
+ end
48
+
49
+ # @return [Boolean, true]
50
+ def enable_scan_response
51
+ @enable_scan_response.nil? ? true : @enable_scan_response
52
+ end
53
+
54
+ # @return [Boolean, true]
55
+ def enable_dynamic_sources
56
+ @enable_dynamic_sources.nil? ? true : @enable_dynamic_sources
57
+ end
58
+
59
+ # @return [Boolean, true]
60
+ def enable_original_object
61
+ @enable_original_object.nil? ? true : @enable_original_object
62
+ end
63
+
64
+ # @return [Contrast::Components::Sampling::Interface]
65
+ def sampling
66
+ @sampling ||= Contrast::Components::Sampling::Interface.new
67
+ end
68
+
69
+ # @return [Contrast::Components::AssessRules::Interface]
70
+ def rules
71
+ @rules ||= Contrast::Components::AssessRules::Interface.new
72
+ end
73
+
74
+ def stacktraces
75
+ @stacktraces ||= DEFAULT_STACKTRACES
76
+ end
77
+
78
+ def max_rule_reported
79
+ @max_rule_reported ||= DEFAULT_MAX_RULE_REPORTED
80
+ end
81
+
82
+ def time_limit_threshold
83
+ @time_limit_threshold ||= DEFAULT_MAX_RULE_TIME_THRESHOLD
84
+ end
85
+
86
+ def max_propagation_events
87
+ @max_propagation_events ||= DEFAULT_MAX_PROPAGATION_EVENTS
88
+ end
89
+
90
+ def max_context_source_events
91
+ @max_context_source_events ||= DEFAULT_MAX_SOURCE_EVENTS
92
+ end
93
+
18
94
  def enabled?
19
95
  # config overrides if forcibly set
20
96
  return false if forcibly_disabled?
@@ -28,7 +104,8 @@ module Contrast
28
104
  end
29
105
 
30
106
  def forcibly_disabled?
31
- @_forcibly_disabled = false?(::Contrast::CONFIG.root.assess.enable) if @_forcibly_disabled.nil?
107
+ @_forcibly_disabled = false?(enable) if @_forcibly_disabled.nil?
108
+
32
109
  @_forcibly_disabled
33
110
  end
34
111
 
@@ -40,9 +117,9 @@ module Contrast
40
117
  # faster comparisons when we use it. Anything not one of the known values of
41
118
  # 'NONE', 'SOME', or 'ALL' is treated as 'ALL'
42
119
  #
43
- # @return [Symbol] the normalized value of ::Contrast::CONFIG.root.assess.stacktraces
120
+ # @return [Symbol] the normalized value of ::Contrast::CONFIG.assess.stacktraces
44
121
  def capture_stacktrace_value
45
- @_capture_stacktrace_value ||= case ::Contrast::CONFIG.root.assess.stacktraces.upcase
122
+ @_capture_stacktrace_value ||= case stacktraces&.upcase
46
123
  when 'NONE'
47
124
  :NONE
48
125
  when 'SOME'
@@ -53,7 +130,7 @@ module Contrast
53
130
  end
54
131
 
55
132
  # Consider capture_stacktrace_value along with the node type
56
- # to dertmine whether stacktraces should be captured.
133
+ # to determine whether stacktraces should be captured.
57
134
  #
58
135
  # capture_stacktrace_value -> (:ALL, :NONE, :SOME)
59
136
  # node types (SourceNode, PolicyNode, TriggerNode, PropagationNode)
@@ -72,42 +149,34 @@ module Contrast
72
149
  end
73
150
 
74
151
  def scan_response?
75
- @_scan_response = !false?(::Contrast::CONFIG.root.assess.enable_scan_response) if @_scan_response.nil?
152
+ @_scan_response = !false?(enable_scan_response) if @_scan_response.nil?
153
+
76
154
  @_scan_response
77
155
  end
78
156
 
79
157
  def require_scan?
80
- @_require_scan = !false?(::Contrast::CONFIG.root.agent.ruby.require_scan) if @_require_scan.nil?
158
+ @_require_scan = !false?(::Contrast::CONFIG.agent.ruby.require_scan) if @_require_scan.nil?
81
159
  @_require_scan
82
160
  end
83
161
 
84
162
  def require_dynamic_sources?
85
163
  return @_require_dynamic_sources unless @_require_dynamic_sources.nil?
86
164
 
87
- @_require_dynamic_sources = !false?(::Contrast::CONFIG.root.assess.enable_dynamic_sources)
165
+ @_require_dynamic_sources = !false?(enable_dynamic_sources)
88
166
  end
89
167
 
90
168
  def non_request_tracking?
91
- @_non_request_tracking = true?(::Contrast::CONFIG.root.agent.ruby.non_request_tracking) if
169
+ @_non_request_tracking = true?(::Contrast::CONFIG.agent.ruby.non_request_tracking) if
92
170
  @_non_request_tracking.nil?
93
171
  @_non_request_tracking
94
172
  end
95
173
 
96
- def tags
97
- ::Contrast::CONFIG.root.assess&.tags
98
- end
99
-
100
174
  def disabled_rules
101
- # TODO: RUBY-903
102
- ::Contrast::CONFIG.root.assess&.rules&.disabled_rules ||
103
- ::Contrast::SETTINGS.assess_state.disabled_assess_rules ||
104
- []
175
+ rules&.disabled_rules || ::Contrast::SETTINGS.assess_state.disabled_assess_rules || []
105
176
  end
106
177
 
107
178
  def track_original_object?
108
- if @_track_original_object.nil?
109
- @_track_original_object = !false?(::Contrast::CONFIG.root.assess.enable_original_object)
110
- end
179
+ @_track_original_object = !false?(enable_original_object) if @_track_original_object.nil?
111
180
 
112
181
  @_track_original_object
113
182
  end
@@ -118,26 +187,11 @@ module Contrast
118
187
  ::Contrast::SETTINGS.assess_state.session_id
119
188
  end
120
189
 
121
- def max_source_events
122
- ::Contrast::CONFIG.root.assess.max_context_source_events
123
- end
124
-
125
- def max_propagation_events
126
- ::Contrast::CONFIG.root.assess.max_propagation_events
127
- end
128
-
129
- def time_limit_threshold
130
- ::Contrast::CONFIG.root.assess.time_limit_threshold
131
- end
132
-
133
- def max_rule_reported
134
- ::Contrast::CONFIG.root.assess.max_rule_reported
135
- end
136
-
190
+ # rubocop:enable Naming/MemoizedInstanceVariableName
137
191
  private
138
192
 
139
193
  def forcibly_enabled?
140
- @_forcibly_enabled = true?(::Contrast::CONFIG.root.assess.enable) if @_forcibly_enabled.nil?
194
+ @_forcibly_enabled = true?(::Contrast::CONFIG.assess.enable) if @_forcibly_enabled.nil?
141
195
  @_forcibly_enabled
142
196
  end
143
197
  end