contrast-agent 6.0.0 → 6.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (260) hide show
  1. checksums.yaml +4 -4
  2. data/.simplecov +1 -1
  3. data/Rakefile +1 -1
  4. data/ext/build_funchook.rb +3 -3
  5. data/ext/cs__assess_basic_object/cs__assess_basic_object.c +5 -1
  6. data/ext/cs__assess_regexp/cs__assess_regexp.c +15 -2
  7. data/ext/cs__assess_regexp/cs__assess_regexp.h +2 -0
  8. data/ext/cs__assess_string/cs__assess_string.c +8 -0
  9. data/ext/cs__assess_test/cs__assess_test.h +9 -0
  10. data/ext/cs__assess_test/cs__assess_tests.c +22 -0
  11. data/ext/cs__assess_test/extconf.rb +5 -0
  12. data/ext/cs__common/cs__common.c +101 -0
  13. data/ext/cs__common/cs__common.h +29 -5
  14. data/ext/cs__contrast_patch/cs__contrast_patch.c +1 -1
  15. data/ext/cs__tests/cs__tests.c +12 -0
  16. data/ext/cs__tests/cs__tests.h +3 -0
  17. data/ext/cs__tests/extconf.rb +5 -0
  18. data/ext/extconf_common.rb +1 -1
  19. data/lib/contrast/agent/assess/contrast_object.rb +16 -16
  20. data/lib/contrast/agent/assess/events/source_event.rb +17 -19
  21. data/lib/contrast/agent/assess/finalizers/hash.rb +2 -2
  22. data/lib/contrast/agent/assess/policy/policy.rb +9 -10
  23. data/lib/contrast/agent/assess/policy/policy_node.rb +9 -10
  24. data/lib/contrast/agent/assess/policy/policy_scanner.rb +2 -16
  25. data/lib/contrast/agent/assess/policy/propagation_method.rb +3 -3
  26. data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -3
  27. data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
  28. data/lib/contrast/agent/assess/policy/propagator/buffer.rb +2 -1
  29. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +1 -1
  30. data/lib/contrast/agent/assess/policy/propagator/splat.rb +1 -1
  31. data/lib/contrast/agent/assess/policy/propagator/split.rb +17 -21
  32. data/lib/contrast/agent/assess/policy/propagator/trim.rb +1 -1
  33. data/lib/contrast/agent/assess/policy/source_node.rb +1 -1
  34. data/lib/contrast/agent/assess/policy/trigger_method.rb +10 -18
  35. data/lib/contrast/agent/assess/policy/trigger_node.rb +16 -16
  36. data/lib/contrast/agent/assess/policy/trigger_validation/redos_validator.rb +1 -1
  37. data/lib/contrast/agent/assess/property/evented.rb +2 -2
  38. data/lib/contrast/agent/assess/property/tagged.rb +2 -2
  39. data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +6 -8
  40. data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +6 -7
  41. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +12 -7
  42. data/lib/contrast/agent/assess/rule/response/base_rule.rb +13 -6
  43. data/lib/contrast/agent/assess/rule/response/cache_control_header_rule.rb +66 -43
  44. data/lib/contrast/agent/assess/rule/response/click_jacking_header_rule.rb +4 -4
  45. data/lib/contrast/agent/assess/rule/response/csp_header_insecure_rule.rb +6 -6
  46. data/lib/contrast/agent/assess/rule/response/csp_header_missing_rule.rb +4 -4
  47. data/lib/contrast/agent/assess/rule/response/hsts_header_rule.rb +4 -4
  48. data/lib/contrast/agent/assess/rule/response/x_content_type_header_rule.rb +4 -4
  49. data/lib/contrast/agent/assess/rule/response/x_xss_protection_header_rule.rb +3 -4
  50. data/lib/contrast/agent/assess/tag.rb +13 -14
  51. data/lib/contrast/agent/at_exit_hook.rb +12 -1
  52. data/lib/contrast/agent/inventory/database_config.rb +22 -7
  53. data/lib/contrast/agent/middleware.rb +9 -6
  54. data/lib/contrast/agent/patching/policy/after_load_patch.rb +3 -5
  55. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +2 -2
  56. data/lib/contrast/agent/patching/policy/method_policy_extend.rb +4 -4
  57. data/lib/contrast/agent/patching/policy/patch.rb +20 -19
  58. data/lib/contrast/agent/patching/policy/patch_status.rb +10 -3
  59. data/lib/contrast/agent/patching/policy/patcher.rb +1 -1
  60. data/lib/contrast/agent/patching/policy/policy.rb +13 -15
  61. data/lib/contrast/agent/patching/policy/policy_node.rb +19 -21
  62. data/lib/contrast/agent/patching/policy/trigger_node.rb +1 -1
  63. data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +126 -122
  64. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -2
  65. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +1 -1
  66. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +1 -1
  67. data/lib/contrast/agent/protect/policy/rule_applicator.rb +4 -4
  68. data/lib/contrast/agent/protect/rule/base.rb +30 -18
  69. data/lib/contrast/agent/protect/rule/base_service.rb +31 -14
  70. data/lib/contrast/agent/protect/rule/cmd_injection.rb +16 -9
  71. data/lib/contrast/agent/protect/rule/cmdi/cmdi_input_classification.rb +3 -3
  72. data/lib/contrast/agent/protect/rule/default_scanner.rb +2 -1
  73. data/lib/contrast/agent/protect/rule/deserialization.rb +18 -7
  74. data/lib/contrast/agent/protect/rule/http_method_tampering/http_method_tampering_input_classification.rb +74 -74
  75. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +71 -53
  76. data/lib/contrast/agent/protect/rule/no_sqli/no_sqli_input_classification.rb +3 -3
  77. data/lib/contrast/agent/protect/rule/no_sqli.rb +15 -16
  78. data/lib/contrast/agent/protect/rule/path_traversal.rb +13 -3
  79. data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +2 -2
  80. data/lib/contrast/agent/protect/rule/sqli/sqli_worth_watching.rb +1 -1
  81. data/lib/contrast/agent/protect/rule/sqli.rb +16 -23
  82. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_input_classification.rb +61 -61
  83. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_matcher.rb +29 -29
  84. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +32 -32
  85. data/lib/contrast/agent/protect/rule/xss.rb +17 -0
  86. data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +14 -13
  87. data/lib/contrast/agent/protect/rule/xxe.rb +25 -3
  88. data/lib/contrast/agent/reaction_processor.rb +1 -1
  89. data/lib/contrast/agent/reporting/attack_result/rasp_rule_sample.rb +36 -36
  90. data/lib/contrast/agent/reporting/masker/masker.rb +18 -21
  91. data/lib/contrast/agent/reporting/masker/masker_utils.rb +10 -6
  92. data/lib/contrast/agent/reporting/reporter.rb +11 -16
  93. data/lib/contrast/agent/reporting/reporter_heartbeat.rb +49 -0
  94. data/lib/contrast/agent/reporting/reporting_events/agent_startup.rb +6 -2
  95. data/lib/contrast/agent/reporting/reporting_events/application_activity.rb +51 -0
  96. data/lib/contrast/agent/reporting/reporting_events/application_defend_activity.rb +96 -0
  97. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_activity.rb +70 -0
  98. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample.rb +182 -0
  99. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample_activity.rb +56 -0
  100. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample_stack.rb +22 -0
  101. data/lib/contrast/agent/reporting/reporting_events/application_defend_attacker_activity.rb +70 -0
  102. data/lib/contrast/agent/reporting/reporting_events/application_inventory.rb +6 -2
  103. data/lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb +60 -0
  104. data/lib/contrast/agent/reporting/reporting_events/application_reporting_event.rb +27 -0
  105. data/lib/contrast/agent/reporting/reporting_events/application_startup.rb +15 -11
  106. data/lib/contrast/agent/reporting/reporting_events/application_update.rb +7 -12
  107. data/lib/contrast/agent/reporting/reporting_events/discovered_route.rb +1 -1
  108. data/lib/contrast/agent/reporting/reporting_events/finding.rb +9 -3
  109. data/lib/contrast/agent/reporting/reporting_events/finding_event.rb +2 -4
  110. data/lib/contrast/agent/reporting/reporting_events/finding_event_object.rb +3 -3
  111. data/lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb +6 -2
  112. data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +7 -3
  113. data/lib/contrast/agent/reporting/reporting_events/poll.rb +6 -2
  114. data/lib/contrast/agent/reporting/reporting_events/preflight.rb +10 -8
  115. data/lib/contrast/agent/reporting/reporting_events/preflight_message.rb +6 -10
  116. data/lib/contrast/agent/reporting/reporting_events/server_activity.rb +12 -20
  117. data/lib/contrast/agent/reporting/reporting_events/server_reporting_event.rb +27 -0
  118. data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +17 -27
  119. data/lib/contrast/agent/reporting/reporting_utilities/build_preflight.rb +38 -0
  120. data/lib/contrast/agent/reporting/reporting_utilities/dtm_message.rb +8 -0
  121. data/lib/contrast/agent/reporting/reporting_utilities/endpoints.rb +6 -0
  122. data/lib/contrast/agent/reporting/reporting_utilities/headers.rb +1 -2
  123. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +15 -10
  124. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +54 -67
  125. data/lib/contrast/agent/reporting/reporting_utilities/response.rb +17 -7
  126. data/lib/contrast/agent/reporting/reporting_utilities/response_extractor.rb +9 -6
  127. data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +17 -17
  128. data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +47 -32
  129. data/lib/contrast/agent/reporting/settings/application_settings.rb +1 -1
  130. data/lib/contrast/agent/reporting/settings/assess.rb +5 -5
  131. data/lib/contrast/agent/reporting/settings/assess_server_feature.rb +3 -3
  132. data/lib/contrast/agent/reporting/settings/exclusions.rb +3 -3
  133. data/lib/contrast/agent/reporting/settings/protect.rb +21 -6
  134. data/lib/contrast/agent/reporting/settings/protect_server_feature.rb +6 -6
  135. data/lib/contrast/agent/reporting/settings/reaction.rb +3 -3
  136. data/lib/contrast/agent/reporting/settings/sensitive_data_masking.rb +2 -2
  137. data/lib/contrast/agent/reporting/settings/sensitive_data_masking_rule.rb +2 -2
  138. data/lib/contrast/agent/reporting/settings/server_features.rb +2 -2
  139. data/lib/contrast/agent/request.rb +5 -5
  140. data/lib/contrast/agent/request_context.rb +23 -19
  141. data/lib/contrast/agent/request_context_extend.rb +11 -24
  142. data/lib/contrast/agent/request_handler.rb +4 -4
  143. data/lib/contrast/agent/response.rb +2 -0
  144. data/lib/contrast/agent/rule_set.rb +2 -2
  145. data/lib/contrast/agent/scope.rb +1 -1
  146. data/lib/contrast/agent/service_heartbeat.rb +6 -48
  147. data/lib/contrast/agent/static_analysis.rb +1 -1
  148. data/lib/contrast/agent/telemetry/base.rb +155 -0
  149. data/lib/contrast/agent/telemetry/events/event.rb +35 -0
  150. data/lib/contrast/agent/telemetry/events/exceptions/obfuscate.rb +119 -0
  151. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_base.rb +44 -36
  152. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_event.rb +29 -21
  153. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message.rb +91 -73
  154. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message_exception.rb +62 -44
  155. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_stack_frame.rb +50 -33
  156. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exceptions.rb +20 -0
  157. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exceptions_report.rb +30 -0
  158. data/lib/contrast/agent/telemetry/events/metric_event.rb +28 -0
  159. data/lib/contrast/agent/telemetry/events/startup_metrics_event.rb +123 -0
  160. data/lib/contrast/agent/thread_watcher.rb +52 -68
  161. data/lib/contrast/agent/version.rb +1 -1
  162. data/lib/contrast/agent/worker_thread.rb +8 -0
  163. data/lib/contrast/agent.rb +1 -3
  164. data/lib/contrast/api/communication/messaging_queue.rb +29 -12
  165. data/lib/contrast/api/communication/response_processor.rb +7 -10
  166. data/lib/contrast/api/communication/service_lifecycle.rb +1 -1
  167. data/lib/contrast/api/communication/socket.rb +1 -1
  168. data/lib/contrast/api/communication/socket_client.rb +1 -1
  169. data/lib/contrast/api/communication/speedracer.rb +3 -3
  170. data/lib/contrast/api/decorators/activity.rb +33 -0
  171. data/lib/contrast/api/decorators/agent_startup.rb +10 -9
  172. data/lib/contrast/api/decorators/application_settings.rb +1 -1
  173. data/lib/contrast/api/decorators/application_startup.rb +4 -4
  174. data/lib/contrast/api/decorators/http_request.rb +1 -1
  175. data/lib/contrast/api/decorators/response_type.rb +4 -17
  176. data/lib/contrast/components/agent.rb +1 -1
  177. data/lib/contrast/components/base.rb +1 -1
  178. data/lib/contrast/components/config.rb +19 -28
  179. data/lib/contrast/components/contrast_service.rb +13 -1
  180. data/lib/contrast/components/sampling.rb +1 -1
  181. data/lib/contrast/components/settings.rb +58 -24
  182. data/lib/contrast/config/agent_configuration.rb +21 -11
  183. data/lib/contrast/config/api_configuration.rb +12 -8
  184. data/lib/contrast/config/api_proxy_configuration.rb +7 -3
  185. data/lib/contrast/config/application_configuration.rb +15 -11
  186. data/lib/contrast/config/assess_configuration.rb +13 -9
  187. data/lib/contrast/config/assess_rules_configuration.rb +6 -2
  188. data/lib/contrast/config/base_configuration.rb +3 -35
  189. data/lib/contrast/config/certification_configuration.rb +9 -5
  190. data/lib/contrast/config/exception_configuration.rb +10 -7
  191. data/lib/contrast/config/heap_dump_configuration.rb +13 -9
  192. data/lib/contrast/config/inventory_configuration.rb +9 -6
  193. data/lib/contrast/config/logger_configuration.rb +9 -6
  194. data/lib/contrast/config/protect_configuration.rb +9 -6
  195. data/lib/contrast/config/protect_rule_configuration.rb +12 -8
  196. data/lib/contrast/config/protect_rules_configuration.rb +19 -18
  197. data/lib/contrast/config/request_audit_configuration.rb +10 -7
  198. data/lib/contrast/config/root_configuration.rb +29 -12
  199. data/lib/contrast/config/ruby_configuration.rb +14 -11
  200. data/lib/contrast/config/sampling_configuration.rb +11 -8
  201. data/lib/contrast/config/server_configuration.rb +13 -9
  202. data/lib/contrast/config/service_configuration.rb +14 -11
  203. data/lib/contrast/configuration.rb +23 -14
  204. data/lib/contrast/extension/assess/array.rb +1 -1
  205. data/lib/contrast/extension/assess/erb.rb +1 -1
  206. data/lib/contrast/extension/assess/marshal.rb +1 -1
  207. data/lib/contrast/extension/assess/string.rb +1 -1
  208. data/lib/contrast/extension/extension.rb +2 -2
  209. data/lib/contrast/framework/base_support.rb +8 -8
  210. data/lib/contrast/framework/grape/support.rb +3 -3
  211. data/lib/contrast/framework/manager.rb +5 -5
  212. data/lib/contrast/framework/manager_extend.rb +1 -1
  213. data/lib/contrast/framework/rack/patch/session_cookie.rb +1 -1
  214. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +14 -3
  215. data/lib/contrast/framework/rails/patch/assess_configuration.rb +3 -3
  216. data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +1 -1
  217. data/lib/contrast/framework/rails/patch/support.rb +14 -46
  218. data/lib/contrast/framework/rails/support.rb +2 -2
  219. data/lib/contrast/framework/sinatra/support.rb +1 -1
  220. data/lib/contrast/logger/aliased_logging.rb +94 -0
  221. data/lib/contrast/logger/application.rb +0 -4
  222. data/lib/contrast/logger/cef_log.rb +14 -14
  223. data/lib/contrast/logger/format.rb +1 -1
  224. data/lib/contrast/logger/log.rb +8 -8
  225. data/lib/contrast/tasks/config.rb +30 -21
  226. data/lib/contrast/tasks/service.rb +2 -2
  227. data/lib/contrast/utils/assess/tracking_util.rb +4 -4
  228. data/lib/contrast/utils/class_util.rb +6 -10
  229. data/lib/contrast/utils/findings.rb +3 -3
  230. data/lib/contrast/utils/hash_digest.rb +6 -7
  231. data/lib/contrast/utils/head_dump_utils_extend.rb +1 -1
  232. data/lib/contrast/utils/invalid_configuration_util.rb +2 -2
  233. data/lib/contrast/utils/log_utils.rb +6 -4
  234. data/lib/contrast/utils/lru_cache.rb +1 -1
  235. data/lib/contrast/utils/metrics_hash.rb +1 -1
  236. data/lib/contrast/utils/middleware_utils.rb +6 -6
  237. data/lib/contrast/utils/net_http_base.rb +4 -4
  238. data/lib/contrast/utils/object_share.rb +1 -1
  239. data/lib/contrast/utils/os.rb +1 -1
  240. data/lib/contrast/utils/patching/policy/patch_utils.rb +2 -2
  241. data/lib/contrast/utils/request_utils.rb +2 -2
  242. data/lib/contrast/utils/sha256_builder.rb +4 -4
  243. data/lib/contrast/utils/stack_trace_utils.rb +31 -13
  244. data/lib/contrast/utils/telemetry.rb +22 -7
  245. data/lib/contrast/utils/telemetry_client.rb +27 -15
  246. data/lib/contrast/utils/telemetry_hash.rb +41 -0
  247. data/lib/contrast/utils/telemetry_identifier.rb +18 -3
  248. data/lib/contrast/utils/timer.rb +1 -1
  249. data/lib/contrast.rb +9 -0
  250. data/resources/assess/policy.json +1 -1
  251. data/ruby-agent.gemspec +1 -1
  252. data/service_executables/VERSION +1 -1
  253. data/service_executables/linux/contrast-service +0 -0
  254. data/service_executables/mac/contrast-service +0 -0
  255. metadata +41 -16
  256. data/lib/contrast/agent/telemetry/events/metric_telemetry_event.rb +0 -26
  257. data/lib/contrast/agent/telemetry/events/startup_metrics_telemetry_event.rb +0 -121
  258. data/lib/contrast/agent/telemetry/events/telemetry_event.rb +0 -33
  259. data/lib/contrast/agent/telemetry/telemetry.rb +0 -150
  260. data/lib/contrast/utils/exclude_key.rb +0 -20
@@ -64,25 +64,25 @@ module Contrast
64
64
  end
65
65
 
66
66
  def platform_version
67
- framework_version = first_framework_result :version, ''
67
+ framework_version = first_framework_result(:version, '')
68
68
 
69
69
  Contrast::Framework::PlatformVersion.from_string(framework_version)
70
70
  end
71
71
 
72
72
  def platform_version_string
73
- first_framework_result :version, ''
73
+ first_framework_result(:version, '')
74
74
  end
75
75
 
76
76
  def server_type
77
- first_framework_result :server_type, 'rack'
77
+ first_framework_result(:server_type, 'rack')
78
78
  end
79
79
 
80
80
  def app_name
81
- first_framework_result :application_name, 'root'
81
+ first_framework_result(:application_name, 'root')
82
82
  end
83
83
 
84
84
  def app_root
85
- found = first_framework_result :application_root, nil
85
+ found = first_framework_result(:application_root, nil)
86
86
  found || ::Rack::Directory.new('').root
87
87
  end
88
88
 
@@ -21,7 +21,7 @@ module Contrast
21
21
  end
22
22
 
23
23
  def routes_for_all_frameworks
24
- data_for_all_frameworks :collect_routes
24
+ data_for_all_frameworks(:collect_routes)
25
25
  end
26
26
 
27
27
  # This returns an array of all data from each framework in a flat, no-nil values array
@@ -25,7 +25,7 @@ module Contrast
25
25
  def instrument
26
26
  @_instrument ||= begin
27
27
  ::Rack::Session::Cookie.class_eval do
28
- alias_method :cs__patched_initialize, :initialize
28
+ alias_method(:cs__patched_initialize, :initialize)
29
29
  def initialize app, options = {} # rubocop:disable Style/OptionHash
30
30
  Contrast::Framework::Rack::Patch::SessionCookie.analyze(options)
31
31
  cs__patched_initialize(app, options)
@@ -16,8 +16,19 @@ module Contrast
16
16
  def send_messages
17
17
  return unless (context = Contrast::Agent::REQUEST_TRACKER.current)
18
18
 
19
- [context.server_activity, context.activity, context.observed_route].each do |msg|
20
- Contrast::Agent.messaging_queue.send_event_immediately(msg)
19
+ if Contrast::Agent::Reporter.enabled?
20
+ [
21
+ context.new_observed_route,
22
+ Contrast::Agent::Reporting::DtmMessage.dtm_to_event(context.server_activity),
23
+ Contrast::Agent::Reporting::DtmMessage.dtm_to_event(context.activity.library_usages),
24
+ Contrast::Agent::Reporting::DtmMessage.dtm_to_event(context.activity)
25
+ ].each do |event|
26
+ Contrast::Agent.reporter&.send_event_immediately(event)
27
+ end
28
+ else
29
+ [context.server_activity, context.activity, context.observed_route].each do |msg|
30
+ Contrast::Agent.messaging_queue&.send_event_immediately(msg)
31
+ end
21
32
  end
22
33
  end
23
34
 
@@ -27,7 +38,7 @@ module Contrast
27
38
  # normally pre->in->post filters are applied however, in a streamed response we can run into a case
28
39
  # where it's pre -> in -> post -> more infilters in order to submit anything found during the
29
40
  # infilters after the response has been written we need to explicitly send them
30
- alias_method :cs__close, :close
41
+ alias_method(:cs__close, :close)
31
42
  def close
32
43
  Contrast::Framework::Rails::Patch::ActionControllerLiveBuffer.send_messages
33
44
  cs__close
@@ -49,7 +49,7 @@ module Contrast
49
49
  end
50
50
 
51
51
  def apply_session_timeout *args
52
- return if ::Contrast::ASSESS.rule_disabled? CS__SESSION_TIMEOUT_NAME
52
+ return if ::Contrast::ASSESS.rule_disabled?(CS__SESSION_TIMEOUT_NAME)
53
53
  return unless vulnerable_setting?(:expire_after, SAFE_SESSION_TIMEOUT, args,
54
54
  comparison_type: :greater_than, safe_default: false)
55
55
 
@@ -64,7 +64,7 @@ module Contrast
64
64
  end
65
65
 
66
66
  def apply_secure_cookie_disabled *args
67
- return if ::Contrast::ASSESS.rule_disabled? CS__SECURE_RULE_NAME
67
+ return if ::Contrast::ASSESS.rule_disabled?(CS__SECURE_RULE_NAME)
68
68
  return unless vulnerable_setting?(:secure, true, args)
69
69
 
70
70
  rails_session_settings = args[1]
@@ -78,7 +78,7 @@ module Contrast
78
78
  end
79
79
 
80
80
  def apply_httponly_disabled *args
81
- return if ::Contrast::ASSESS.rule_disabled? CS__HTTPONLY_RULE_NAME
81
+ return if ::Contrast::ASSESS.rule_disabled?(CS__HTTPONLY_RULE_NAME)
82
82
  return unless vulnerable_setting?(:httponly, true, args)
83
83
 
84
84
  rails_session_settings = args[1]
@@ -14,7 +14,7 @@ module Contrast
14
14
  def self.instrument
15
15
  @_instrument ||= begin
16
16
  ::Rails::Application::Configuration.class_eval do
17
- alias_method :cs__patched_session_store, :session_store
17
+ alias_method(:cs__patched_session_store, :session_store)
18
18
  def session_store *args, **kwargs
19
19
  ret = cs__patched_session_store(*args, **kwargs)
20
20
  Contrast::Framework::Rails::Patch::AssessConfiguration.analyze_session_store(*args, **kwargs)
@@ -20,56 +20,24 @@ module Contrast
20
20
  # (i.e., where we normally patch) we will miss the configuration
21
21
  # and will never be able to report session misconfiguration rules.
22
22
  Contrast::Framework::Rails::Patch::RailsApplicationConfiguration.instrument
23
- require 'contrast/framework/rails/railtie' if ::Rails::VERSION::MAJOR.to_i >= 3
23
+ require('contrast/framework/rails/railtie') if ::Rails::VERSION::MAJOR.to_i >= 3
24
24
  end
25
25
 
26
26
  # (See BaseSupport#after_load_patches)
27
27
  def after_load_patches
28
- patches = Set.new([
29
- Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
30
- 'ActionController::Live::Buffer',
31
- 'contrast/framework/rails/patch/action_controller_live_buffer',
32
- instrumenting_module:
33
- 'Contrast::Framework::Rails::Patch::ActionControllerLiveBuffer'),
34
- Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
35
- 'Rails::Application::Configuration',
36
- 'contrast/framework/rails/patch/rails_application_configuration',
37
- method_to_instrument: :session_store,
38
- instrumenting_module:
39
- 'Contrast::Framework::Rails::Patch::RailsApplicationConfiguration')
40
- ])
41
- patches.merge(special_after_load_patches) if RUBY_VERSION < '2.6.0'
42
- patches
43
- end
44
-
45
- def special_after_load_patches
46
- [
47
- # TODO: RUBY-714 remove w/ EOL of 2.5
48
- #
49
- # @deprecated Everything past here is used for Rewriting and can
50
- # be removed once we no longer support 2.5.
51
- Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
52
- 'ActionController::Railties::Helper::ClassMethods',
53
- 'contrast/framework/rails/rewrite/action_controller_railties_helper_inherited',
54
- method_to_instrument: :inherited,
55
- instrumenting_module:
56
- 'Contrast::Framework::Rails::Rewrite::ActionControllerRailtiesHelperInherited'),
57
- Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
58
- 'ActiveRecord::AttributeMethods::Read::ClassMethods',
59
- 'contrast/framework/rails/rewrite/active_record_attribute_methods_read',
60
- instrumenting_module:
61
- 'Contrast::Framework::Rails::Rewrite::ActiveRecordAttributeMethodsRead'),
62
- Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
63
- 'ActiveRecord::Scoping::Named::ClassMethods',
64
- 'contrast/framework/rails/rewrite/active_record_named',
65
- instrumenting_module: 'Contrast::Framework::Rails::Rewrite::ActiveRecordNamed'),
66
- Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
67
- 'ActiveRecord::AttributeMethods::TimeZoneConversion::ClassMethods',
68
- 'contrast/framework/rails/rewrite/active_record_time_zone_inherited',
69
- method_to_instrument: :inherited,
70
- instrumenting_module:
71
- 'Contrast::Framework::Rails::Rewrite::ActiveRecordTimeZoneInherited')
72
- ]
28
+ Set.new([
29
+ Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
30
+ 'ActionController::Live::Buffer',
31
+ 'contrast/framework/rails/patch/action_controller_live_buffer',
32
+ instrumenting_module:
33
+ 'Contrast::Framework::Rails::Patch::ActionControllerLiveBuffer'),
34
+ Contrast::Agent::Patching::Policy::AfterLoadPatch.new(
35
+ 'Rails::Application::Configuration',
36
+ 'contrast/framework/rails/patch/rails_application_configuration',
37
+ method_to_instrument: :session_store,
38
+ instrumenting_module:
39
+ 'Contrast::Framework::Rails::Patch::RailsApplicationConfiguration')
40
+ ])
73
41
  end
74
42
  end
75
43
  end
@@ -104,7 +104,7 @@ module Contrast
104
104
  end
105
105
 
106
106
  new_route_coverage = Contrast::Agent::Reporting::RouteCoverage.new
107
- new_route_coverage.attach_rails_data route, original_url
107
+ new_route_coverage.attach_rails_data(route, original_url)
108
108
  rescue StandardError => e
109
109
  logger.warn('Unable to determine the current route of this request', e)
110
110
  nil
@@ -153,7 +153,7 @@ module Contrast
153
153
  # If the current routing node points to a sub-app (::Rais::Engine), dive deeper.
154
154
  # Have sub-app route the remainder of the url.
155
155
  if engine_route?(route)
156
- new_req = retrieve_request request.env
156
+ new_req = retrieve_request(request.env)
157
157
  new_req.path_info = new_req.path_info.gsub(match.to_s, '')
158
158
  get_full_route(new_req, route.app.app.routes.router, path << match.to_s)
159
159
  else
@@ -101,7 +101,7 @@ module Contrast
101
101
  full_route ||= request.env[::Rack::PATH_INFO]
102
102
 
103
103
  new_route_coverage = Contrast::Agent::Reporting::RouteCoverage.new
104
- new_route_coverage.attach_rack_based_data final_controller, method, route_pattern, full_route
104
+ new_route_coverage.attach_rack_based_data(final_controller, method, route_pattern, full_route)
105
105
  end
106
106
 
107
107
  # Search object space for sinatra controllers--any class that subclasses ::Sinatra::Base.
@@ -0,0 +1,94 @@
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/telemetry/events/exceptions/telemetry_exceptions'
5
+ require 'contrast/agent/telemetry/events/exceptions/obfuscate'
6
+
7
+ module Contrast
8
+ module Logger
9
+ # Our decorator for the Ougai logger allowing for the catching, creating and saving Telemetry exceptions
10
+ module AliasedLogging
11
+ ALIASED_WARN = 'warn'.cs__freeze
12
+ ALIASED_ERROR = 'error'.cs__freeze
13
+ ALIASED_FATAL = 'fatal'.cs__freeze
14
+
15
+ # @param message [String] The message to log. Use default_message if not specified.
16
+ # @param exception [Exception] The exception or the error
17
+ # @param data [Object] Any structured data
18
+ def warn message = nil, exception = nil, data = nil, &block
19
+ # build Telemetry Exclusion
20
+ build_exclusion(ALIASED_WARN, message, exception, data)
21
+ super(message, exception, data, &block)
22
+ end
23
+
24
+ # @param message [String] The message to log. Use default_message if not specified.
25
+ # @param exception [Exception] The exception or the error
26
+ # @param data [Object] Any structured data
27
+ def error message = nil, exception = nil, data = nil, &block
28
+ # build Telemetry Exclusion
29
+ build_exclusion(ALIASED_ERROR, message, exception, data)
30
+ super(message, exception, data, &block)
31
+ end
32
+
33
+ # @param message [String] The message to log. Use default_message if not specified.
34
+ # @param exception [Exception] The exception or the error
35
+ # @param data [Object] Any structured data
36
+ def fatal message = nil, exception = nil, data = nil, &block
37
+ # build Telemetry Exclusion
38
+ build_exclusion(ALIASED_FATAL, message, exception, data)
39
+ super(message, exception, data, &block)
40
+ end
41
+
42
+ private
43
+
44
+ def build_exclusion _type, _message = nil, _exception = nil, _data = nil
45
+ # TODO: RUBY-1698
46
+ nil
47
+ # start = caller_locations&.find_index { |stack| stack.to_s.include?(type) }
48
+ # stack_trace = start ? caller_locations(start + 1, 20) : caller_locations(20, 20)
49
+ # stack_frame_type = Contrast::Agent::Telemetry::TelemetryException::Obfuscate.obfuscate_type(
50
+ # stack_trace[1].path.delete_prefix(Dir.pwd))
51
+ # message_exception_type = Contrast::Agent::Telemetry::TelemetryException::Obfuscate.obfuscate_exception_type(
52
+ # exception ? exception.cs__class.to_s : stack_frame_type.split('/').last)
53
+ # stack_frame_function = stack_trace[1].label
54
+ # key = "#{ stack_frame_type }|#{ stack_frame_function }|#{ message }"
55
+ # if TELEMETRY_EXCEPTIONS[key]
56
+ # TELEMETRY_EXCEPTIONS.increment(key)
57
+ # return
58
+ # end
59
+ #
60
+ # event_message = create_message(stack_frame_function,
61
+ # stack_frame_type, message_exception_type,
62
+ # data, exception,
63
+ # message)
64
+ # TELEMETRY_EXCEPTIONS[key] = event_message
65
+ # rescue StandardError => e
66
+ # debug('Unable to report exception to telemetry', e)
67
+ end
68
+
69
+ def create_message stack_frame_function, stack_frame_type, message_exception_type, data, exception, message
70
+ message_for_exception = if exception
71
+ exception.cs__respond_to?(:message) ? exception.message : exception
72
+ else
73
+ message
74
+ end
75
+ module_name = message_exception_type ? message_exception_type.split('::')[0] : nil
76
+ stack_frame = Contrast::Agent::Telemetry::TelemetryException::StackFrame.build(stack_frame_function,
77
+ stack_frame_type,
78
+ module_name)
79
+ message_exception = Contrast::Agent::Telemetry::TelemetryException::MessageException.build(
80
+ message_exception_type,
81
+ message_for_exception,
82
+ module_name,
83
+ stack_frame)
84
+ tags = if data
85
+ data
86
+ else
87
+ exception.cs__is_a?(Hash) ? exception : {}
88
+ end
89
+ message = Contrast::Agent::Telemetry::TelemetryException::Message.build(tags, [message_exception])
90
+ Contrast::Agent::Telemetry::TelemetryException::Event.new(message)
91
+ end
92
+ end
93
+ end
94
+ end
@@ -1,8 +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/utils/exclude_key'
5
-
6
4
  module Contrast
7
5
  module Logger
8
6
  # Our decorator for the Ougai logger allowing for the logging of the
@@ -31,8 +29,6 @@ module Contrast
31
29
  loggable = ::Contrast::CONFIG.loggable
32
30
  info('Current configuration', configuration: loggable)
33
31
  env_keys = ENV.keys.select do |env_key|
34
- next if Contrast::Utils::ExcludeKey.excludable? env_key.to_s
35
-
36
32
  env_key&.to_s&.start_with?(Contrast::Components::Config::CONTRAST_ENV_MARKER)
37
33
  end
38
34
  env_items = env_keys.map { |env_key| Contrast::Utils::EnvConfigurationItem.new(env_key, nil) }
@@ -30,7 +30,7 @@ module Contrast
30
30
  else
31
31
  cs__error(*args, **kwargs)
32
32
  end
33
- args.each { |arg| raise arg if arg && arg.cs__class < Exception }
33
+ args.each { |arg| raise(arg) if arg && arg.cs__class < Exception }
34
34
  end
35
35
  end
36
36
  end
@@ -69,11 +69,11 @@ module Contrast
69
69
  if @_cef_logger
70
70
  @_cef_logger.error('Unable to process update to LoggerManager.', e)
71
71
  else
72
- puts 'Unable to process update to LoggerManager.'
73
- raise e if ENV['CONTRAST__AGENT__RUBY_MORE_COWBELL']
72
+ puts('Unable to process update to LoggerManager.')
73
+ raise(e) if ENV['CONTRAST__AGENT__RUBY_MORE_COWBELL']
74
74
 
75
- puts e.message
76
- puts e.backtrace.join("\n")
75
+ puts(e.message)
76
+ puts(e.backtrace.join("\n"))
77
77
  end
78
78
  # rubocop:enable Rails/Output
79
79
  end
@@ -99,28 +99,28 @@ module Contrast
99
99
 
100
100
  def virtual_patch_message patch, outcome
101
101
  message = "Virtual Patch #{ patch.fetch(:name, '') } - #{ patch[:uuid] } was triggered by this request."
102
- log [message, patch, outcome], ::Logger::Severity::DEBUG
102
+ log([message, patch, outcome], ::Logger::Severity::DEBUG)
103
103
  end
104
104
 
105
105
  def bot_blocking_message matching_bot, outcome
106
106
  message = "User agent #{ matching_bot[:user_agent] } matched the disallowed value #{ matching_bot[:bot] }"
107
- log [message, matching_bot, outcome], ::Logger::Severity::DEBUG
107
+ log([message, matching_bot, outcome], ::Logger::Severity::DEBUG)
108
108
  end
109
109
 
110
110
  def ip_denylisted_message remote_ip, block_entry, outcome
111
111
  message = "IP Address #{ remote_ip } matched the disallowed value" \
112
112
  "#{ block_entry[:ip] } in the IP Blacklist #{ block_entry[:uuid] }"
113
- log [message, block_entry, outcome], ::Logger::Severity::DEBUG
113
+ log([message, block_entry, outcome], ::Logger::Severity::DEBUG)
114
114
  end
115
115
 
116
116
  def successful_attack rule_id, outcome, input_type = nil, input_value = nil
117
117
  if input_type.present? && input_value.present?
118
118
  successful_attack_with_input = "#{ input_type } had a value that successfully exploited" \
119
119
  "#{ rule_id } - #{ input_value }"
120
- log [successful_attack_with_input, rule_id, outcome], ::Logger::Severity::WARN
120
+ log([successful_attack_with_input, rule_id, outcome], ::Logger::Severity::WARN)
121
121
  else
122
122
  successful_attack_wo_input = "An effective attack was detected against #{ rule_id }"
123
- log [successful_attack_wo_input, rule_id, outcome], ::Logger::Severity::WARN
123
+ log([successful_attack_wo_input, rule_id, outcome], ::Logger::Severity::WARN)
124
124
  end
125
125
  end
126
126
 
@@ -128,10 +128,10 @@ module Contrast
128
128
  if input_type.present? && input_value.present?
129
129
  ineffective_attack_with_input = "#{ input_type } had a value that matched a signature for, " \
130
130
  "but did not successfully exploit #{ rule_id } - #{ input_value }"
131
- log [ineffective_attack_with_input, rule_id, outcome], ::Logger::Severity::WARN
131
+ log([ineffective_attack_with_input, rule_id, outcome], ::Logger::Severity::WARN)
132
132
  else
133
133
  ineffective_attack_wo_input = "An unsuccessful attack was detected against #{ rule_id }"
134
- log [ineffective_attack_wo_input, rule_id, outcome], ::Logger::Severity::WARN
134
+ log([ineffective_attack_wo_input, rule_id, outcome], ::Logger::Severity::WARN)
135
135
  end
136
136
  end
137
137
 
@@ -140,10 +140,10 @@ module Contrast
140
140
  if input_type.present? && input_value.present?
141
141
  suspicious_attack_with = "#{ input_type } included a potential attack value that was detected" \
142
142
  "as suspicious using #{ rule_id } - #{ input_value }"
143
- log [suspicious_attack_with, rule_id, outcome], ::Logger::WARN
143
+ log([suspicious_attack_with, rule_id, outcome], ::Logger::WARN)
144
144
  elsif input_value.present?
145
145
  suspicious_attack_without = "Suspicious activity indicates a potential attack using #{ rule_id }"
146
- log [suspicious_attack_without, rule_id, outcome], ::Logger::WARN
146
+ log([suspicious_attack_without, rule_id, outcome], ::Logger::WARN)
147
147
  end
148
148
  end
149
149
  end
@@ -10,6 +10,7 @@ module Contrast
10
10
  # Our format for the Ougai logger allowing for custom log format that
11
11
  # extends the behavior of the default Ougai logger
12
12
  class Format < Ougai::Formatters::Bunyan
13
+ NO_REQUEST_HASH = { request_id: -1 }.cs__freeze
13
14
  LOG_TRACKER = Contrast::Utils::ThreadTracker.new
14
15
  # Our override of the _call method to add in the extra data that we want,
15
16
  # based on
@@ -49,7 +50,6 @@ module Contrast
49
50
  hash
50
51
  end
51
52
 
52
- NO_REQUEST_HASH = { request_id: -1 }.cs__freeze
53
53
  def request_hash
54
54
  @request_tracker_defined ||= defined?(Contrast::Agent) && defined?(Contrast::Agent::REQUEST_TRACKER)
55
55
  return NO_REQUEST_HASH unless @request_tracker_defined
@@ -44,8 +44,8 @@ module Contrast
44
44
  untimed_func_symbol = "untimed_#{ meth_spec.method_name }".to_sym
45
45
  send_to = class_method ? meth_spec.clazz.cs__singleton_class : meth_spec.clazz
46
46
  meth_spec.clazz.class_eval do
47
- include Contrast::Components::Logger::InstanceMethods
48
- extend Contrast::Components::Logger::InstanceMethods
47
+ include(Contrast::Components::Logger::InstanceMethods)
48
+ extend(Contrast::Components::Logger::InstanceMethods)
49
49
 
50
50
  send_to.send(:alias_method, untimed_func_symbol, meth_spec.method_name)
51
51
  meth_spec.aliased = true
@@ -73,7 +73,7 @@ module Contrast
73
73
  next if meth_spec.aliased
74
74
 
75
75
  is_class_method = meth_spec.clazz.singleton_methods(false).include?(meth_spec.method_name)
76
- trace_time_class_method meth_spec, is_class_method
76
+ trace_time_class_method(meth_spec, is_class_method)
77
77
  end
78
78
  end
79
79
  end
@@ -96,7 +96,7 @@ module Contrast
96
96
  else
97
97
  cs__error(*args, **kwargs)
98
98
  end
99
- args.each { |arg| raise arg if arg && arg.cs__class < Exception }
99
+ args.each { |arg| raise(arg) if arg && arg.cs__class < Exception }
100
100
  end
101
101
  end
102
102
  end
@@ -142,11 +142,11 @@ module Contrast
142
142
  if logger
143
143
  logger.error('Unable to process update to LoggerManager.', e)
144
144
  else
145
- puts 'Unable to process update to LoggerManager.'
146
- raise e if ENV['CONTRAST__AGENT__RUBY_MORE_COWBELL']
145
+ puts('Unable to process update to LoggerManager.')
146
+ raise(e) if ENV['CONTRAST__AGENT__RUBY_MORE_COWBELL']
147
147
 
148
- puts e.message
149
- puts e.backtrace.join("\n")
148
+ puts(e.message)
149
+ puts(e.backtrace.join("\n"))
150
150
  end
151
151
  end
152
152
 
@@ -7,7 +7,7 @@ require 'contrast/agent/reporting/reporter'
7
7
 
8
8
  module Contrast
9
9
  # A Rake task to generate a contrast_security.yaml file with some basic settings
10
- module Config
10
+ module Config # rubocop:disable Metrics/ModuleLength
11
11
  extend Rake::DSL
12
12
  DEFAULT_CONFIG = {
13
13
  'api' => {
@@ -32,6 +32,7 @@ module Contrast
32
32
  }.cs__freeze
33
33
 
34
34
  SKIP_LOG = %w[service_key api_key].cs__freeze
35
+ REQUIRED = %i[url api_key service_key user_name].cs__freeze
35
36
 
36
37
  namespace :contrast do
37
38
  namespace :config do
@@ -62,20 +63,19 @@ module Contrast
62
63
  puts 'Validating Contrast Reporter Headers...'
63
64
  reporter = Contrast::Config.validate_headers
64
65
  puts '...done!'
65
- puts 'Testing Client Connection...'
66
+ puts 'Testing Reporter Client Connection...'
66
67
  Contrast::Config.test_connection(reporter) if reporter
67
68
  puts '...done!'
68
69
  end
69
70
  end
70
- def self.validate_config # rubocop:disable Metrics/PerceivedComplexity
71
+
72
+ def self.validate_config
71
73
  config = Contrast::Configuration.new
72
74
  abort('Unable to Build Config') unless config
73
-
74
- required = %i[url api_key service_key user_name]
75
-
76
75
  missing = []
77
- config.root.api.each do |key, value|
78
- puts "#{ key }::#{ value }" unless value.is_a?(Contrast::Config::BaseConfiguration) || SKIP_LOG.includes?(key)
76
+ api_hash = config.root.api.to_hash
77
+ api_hash.each_key do |key|
78
+ value = mask_keys(api_hash, key)
79
79
  if value.is_a?(Contrast::Config::ApiProxyConfiguration)
80
80
  Contrast::Config.validate_proxy(value)
81
81
  elsif value.is_a?(Contrast::Config::CertificationConfiguration)
@@ -84,7 +84,7 @@ module Contrast
84
84
  elsif value.is_a?(Contrast::Config::RequestAuditConfiguration)
85
85
  Contrast::Config.validate_audit(value)
86
86
  next
87
- elsif value == Contrast::Config::BaseConfiguration::EMPTY_VALUE && required.includes?(key.to_sym)
87
+ elsif value.nil? && REQUIRED.includes?(key.to_sym)
88
88
  missing << key
89
89
  end
90
90
  end
@@ -92,39 +92,40 @@ module Contrast
92
92
  end
93
93
 
94
94
  def self.validate_proxy config
95
- puts "Proxy Enabled: #{ config.enable }"
95
+ puts("Proxy Enabled: #{ config.enable }")
96
96
  return unless config.enable
97
97
 
98
- puts "Proxy URL: #{ config.url }"
98
+ puts("Proxy URL: #{ config.url }")
99
99
  abort('Proxy Enabled but no Proxy URL given') unless config.url
100
100
  end
101
101
 
102
102
  def self.validate_cert config
103
- puts "Certification Enabled: #{ config.enable }"
103
+ puts("Certification Enabled: #{ config.enable }")
104
104
  return unless config.enable
105
105
 
106
- puts "CA File: #{ config.ca_file }"
106
+ puts("CA File: #{ config.ca_file }")
107
107
  abort('CA file path not provided') unless config.ca_file
108
- puts "Cert File: #{ config.cert_file }"
108
+ puts("Cert File: #{ config.cert_file }")
109
109
  abort('Cert file path not provided') unless config.cert_file
110
- puts "Key File: #{ config.key_file }"
110
+ puts("Key File: #{ config.key_file }")
111
111
  abort('Key file path not provided') unless config.key_file
112
112
  end
113
113
 
114
114
  def self.validate_audit config
115
- puts "Request Audit Enabled: #{ config.enable }"
115
+ puts("Request Audit Enabled: #{ config.enable }")
116
116
  return unless config.enable
117
117
 
118
118
  config.each do |k, v|
119
- puts "#{ k }::#{ v }"
119
+ puts("#{ k }::#{ v }")
120
120
  end
121
121
  end
122
122
 
123
123
  def self.validate_headers
124
124
  missing = []
125
125
  reporter = Contrast::Agent::Reporter.new
126
- reporter.client.headers.to_hash.each_pair do |key, value|
127
- puts "#{ key }::#{ value }"
126
+ reporter_headers = reporter.client.headers.to_hash
127
+ reporter_headers.each_key do |key|
128
+ value = mask_keys(reporter_headers, key)
128
129
  missing << key if value.nil?
129
130
  end
130
131
  abort("Missing required header values: #{ missing.join(', ') }") unless missing.empty?
@@ -132,8 +133,16 @@ module Contrast
132
133
  end
133
134
 
134
135
  def self.test_connection reporter
135
- abort('Failed to Initialize Connection please check error logs for details') unless reporter.connection
136
- abort('Failed to Start Client please check error logs for details') unless reporter.client.startup!
136
+ connection = reporter.connection
137
+ abort('Failed to Initialize Connection please check error logs for details') unless connection
138
+ abort('Failed to Start Client please check error logs for details') unless reporter.client.startup!(connection)
139
+ end
140
+
141
+ def self.mask_keys hash, key
142
+ value = hash[key]
143
+ redacted_value = Contrast::Configuration::REDACTED if SKIP_LOG.include?(key.to_s)
144
+ puts("#{ key }::#{ redacted_value || value }") unless value.is_a?(Contrast::Config::BaseConfiguration)
145
+ value
137
146
  end
138
147
  end
139
148
  end
@@ -11,7 +11,7 @@ module Contrast
11
11
  extend Rake::DSL
12
12
  # Start the service if it is not already running
13
13
  def self.start_service
14
- puts 'Starting Contrast Service'
14
+ puts('Starting Contrast Service')
15
15
  service_log = ::Contrast::CONTRAST_SERVICE.logger_path
16
16
  if File.writable?(service_log)
17
17
  spawn('contrast_service', out: File::NULL, err: service_log)
@@ -23,7 +23,7 @@ module Contrast
23
23
  sleep(0.05) until Contrast::Utils::OS.running?
24
24
  end
25
25
  watcher.join(1)
26
- puts Contrast::Utils::OS.running? ? 'Contrast Service started successfully.' : 'Contrast Service did not start.'
26
+ puts(Contrast::Utils::OS.running? ? 'Contrast Service started successfully.' : 'Contrast Service did not start.')
27
27
  end
28
28
 
29
29
  # Stop the service if it is running
@@ -50,9 +50,9 @@ module Contrast
50
50
 
51
51
  idx += 1
52
52
  if Contrast::Utils::DuckUtils.iterable_hash?(obj)
53
- handle_hash obj, idx
53
+ handle_hash(obj, idx)
54
54
  elsif Contrast::Utils::DuckUtils.iterable_enumerable?(obj)
55
- handle_enumerable obj, idx
55
+ handle_enumerable(obj, idx)
56
56
  else
57
57
  Contrast::Agent::Assess::Tracker.tracked?(obj)
58
58
  end
@@ -79,9 +79,9 @@ module Contrast
79
79
 
80
80
  idx += 1
81
81
  if Contrast::Utils::DuckUtils.iterable_hash?(obj)
82
- handle_hash obj, idx
82
+ handle_hash(obj, idx)
83
83
  elsif Contrast::Utils::DuckUtils.iterable_enumerable?(obj)
84
- handle_enumerable obj, idx
84
+ handle_enumerable(obj, idx)
85
85
  else
86
86
  Contrast::Agent::Assess::Tracker.trackable?(obj)
87
87
  end