contrast-agent 5.2.0 → 6.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (228) hide show
  1. checksums.yaml +4 -4
  2. data/ext/cs__assess_array/cs__assess_array.c +7 -0
  3. data/ext/cs__assess_basic_object/cs__assess_basic_object.c +19 -5
  4. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +1 -1
  5. data/ext/cs__assess_hash/cs__assess_hash.c +3 -4
  6. data/ext/cs__assess_kernel/cs__assess_kernel.c +1 -2
  7. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +26 -12
  8. data/ext/cs__assess_module/cs__assess_module.c +1 -1
  9. data/ext/cs__assess_regexp/cs__assess_regexp.c +15 -2
  10. data/ext/cs__assess_regexp/cs__assess_regexp.h +2 -0
  11. data/ext/cs__assess_string/cs__assess_string.c +21 -1
  12. data/ext/cs__assess_test/cs__assess_test.h +9 -0
  13. data/ext/cs__assess_test/cs__assess_tests.c +22 -0
  14. data/ext/cs__assess_test/extconf.rb +5 -0
  15. data/ext/cs__common/cs__common.c +113 -11
  16. data/ext/cs__common/cs__common.h +29 -5
  17. data/ext/cs__contrast_patch/cs__contrast_patch.c +55 -44
  18. data/ext/cs__os_information/cs__os_information.c +13 -10
  19. data/ext/cs__scope/cs__scope.c +146 -97
  20. data/ext/cs__tests/cs__tests.c +12 -0
  21. data/ext/cs__tests/cs__tests.h +3 -0
  22. data/ext/cs__tests/extconf.rb +5 -0
  23. data/lib/contrast/agent/assess/contrast_object.rb +16 -16
  24. data/lib/contrast/agent/assess/events/source_event.rb +17 -19
  25. data/lib/contrast/agent/assess/finalizers/hash.rb +2 -0
  26. data/lib/contrast/agent/assess/policy/policy_node.rb +50 -27
  27. data/lib/contrast/agent/assess/policy/policy_node_utils.rb +51 -0
  28. data/lib/contrast/agent/assess/policy/policy_scanner.rb +2 -16
  29. data/lib/contrast/agent/assess/policy/preshift.rb +8 -2
  30. data/lib/contrast/agent/assess/policy/propagation_method.rb +47 -13
  31. data/lib/contrast/agent/assess/policy/propagator/buffer.rb +118 -0
  32. data/lib/contrast/agent/assess/policy/propagator/keep.rb +19 -4
  33. data/lib/contrast/agent/assess/policy/propagator/remove.rb +18 -2
  34. data/lib/contrast/agent/assess/policy/propagator/splat.rb +17 -3
  35. data/lib/contrast/agent/assess/policy/propagator/split.rb +15 -19
  36. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +1 -1
  37. data/lib/contrast/agent/assess/policy/propagator/substitution_utils.rb +1 -1
  38. data/lib/contrast/agent/assess/policy/propagator/trim.rb +1 -1
  39. data/lib/contrast/agent/assess/policy/propagator.rb +1 -0
  40. data/lib/contrast/agent/assess/policy/source_method.rb +7 -7
  41. data/lib/contrast/agent/assess/policy/trigger_method.rb +4 -10
  42. data/lib/contrast/agent/assess/property/tagged.rb +1 -1
  43. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +7 -2
  44. data/lib/contrast/agent/assess/rule/response/auto_complete_rule.rb +1 -1
  45. data/lib/contrast/agent/assess/rule/response/base_rule.rb +11 -3
  46. data/lib/contrast/agent/assess/rule/response/body_rule.rb +3 -3
  47. data/lib/contrast/agent/assess/rule/response/cache_control_header_rule.rb +60 -36
  48. data/lib/contrast/agent/assess/rule/response/framework/rails_support.rb +3 -3
  49. data/lib/contrast/agent/assess/rule/response/parameters_pollution_rule.rb +1 -1
  50. data/lib/contrast/agent/assess/rule/response/x_xss_protection_header_rule.rb +1 -2
  51. data/lib/contrast/agent/at_exit_hook.rb +1 -1
  52. data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +0 -7
  53. data/lib/contrast/agent/deadzone/policy/policy.rb +0 -6
  54. data/lib/contrast/agent/exclusion_matcher.rb +3 -3
  55. data/lib/contrast/agent/inventory/database_config.rb +10 -3
  56. data/lib/contrast/agent/middleware.rb +5 -3
  57. data/lib/contrast/agent/patching/policy/after_load_patch.rb +0 -2
  58. data/lib/contrast/agent/patching/policy/patch.rb +13 -12
  59. data/lib/contrast/agent/patching/policy/patcher.rb +4 -4
  60. data/lib/contrast/agent/patching/policy/policy_node.rb +15 -2
  61. data/lib/contrast/agent/protect/exploitable_collection.rb +38 -0
  62. data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +66 -9
  63. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -1
  64. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +2 -2
  65. data/lib/contrast/agent/protect/rule/base.rb +37 -5
  66. data/lib/contrast/agent/protect/rule/base_service.rb +3 -1
  67. data/lib/contrast/agent/protect/rule/cmd_injection.rb +13 -0
  68. data/lib/contrast/agent/protect/rule/cmdi/cmdi_input_classification.rb +83 -0
  69. data/lib/contrast/agent/protect/rule/cmdi/cmdi_worth_watching.rb +64 -0
  70. data/lib/contrast/agent/protect/rule/http_method_tampering/http_method_tampering_input_classification.rb +96 -0
  71. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +8 -0
  72. data/lib/contrast/agent/protect/rule/no_sqli/no_sqli_input_classification.rb +231 -0
  73. data/lib/contrast/agent/protect/rule/no_sqli.rb +27 -0
  74. data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +18 -54
  75. data/lib/contrast/agent/protect/rule/sqli/sqli_worth_watching.rb +1 -4
  76. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_input_classification.rb +82 -0
  77. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_matcher.rb +45 -0
  78. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +42 -0
  79. data/lib/contrast/agent/reporting/attack_result/attack_result.rb +63 -0
  80. data/lib/contrast/agent/reporting/attack_result/rasp_rule_sample.rb +52 -0
  81. data/lib/contrast/agent/reporting/attack_result/response_type.rb +29 -0
  82. data/lib/contrast/agent/reporting/attack_result/user_input.rb +87 -0
  83. data/lib/contrast/agent/reporting/masker/masker.rb +243 -0
  84. data/lib/contrast/agent/reporting/masker/masker_utils.rb +62 -0
  85. data/lib/contrast/agent/reporting/report.rb +2 -0
  86. data/lib/contrast/agent/reporting/reporter.rb +29 -22
  87. data/lib/contrast/agent/reporting/reporter_heartbeat.rb +49 -0
  88. data/lib/contrast/agent/reporting/reporting_events/agent_startup.rb +34 -0
  89. data/lib/contrast/agent/reporting/reporting_events/application_activity.rb +53 -0
  90. data/lib/contrast/agent/reporting/reporting_events/application_defend_activity.rb +48 -0
  91. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_activity.rb +64 -0
  92. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample.rb +70 -0
  93. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample_activity.rb +57 -0
  94. data/lib/contrast/agent/reporting/reporting_events/application_defend_attacker_activity.rb +56 -0
  95. data/lib/contrast/agent/reporting/reporting_events/application_inventory.rb +12 -4
  96. data/lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb +58 -0
  97. data/lib/contrast/agent/reporting/reporting_events/application_reporting_event.rb +27 -0
  98. data/lib/contrast/agent/reporting/reporting_events/application_startup.rb +50 -0
  99. data/lib/contrast/agent/reporting/reporting_events/application_startup_instrumentation.rb +27 -0
  100. data/lib/contrast/agent/reporting/reporting_events/application_update.rb +7 -12
  101. data/lib/contrast/agent/reporting/reporting_events/finding.rb +10 -4
  102. data/lib/contrast/agent/reporting/reporting_events/finding_event.rb +2 -4
  103. data/lib/contrast/agent/reporting/reporting_events/finding_event_object.rb +3 -3
  104. data/lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb +5 -5
  105. data/lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb +6 -2
  106. data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +16 -12
  107. data/lib/contrast/agent/reporting/reporting_events/poll.rb +6 -2
  108. data/lib/contrast/agent/reporting/reporting_events/preflight.rb +10 -8
  109. data/lib/contrast/agent/reporting/reporting_events/preflight_message.rb +8 -11
  110. data/lib/contrast/agent/reporting/reporting_events/reporting_event.rb +2 -1
  111. data/lib/contrast/agent/reporting/reporting_events/route_coverage.rb +8 -6
  112. data/lib/contrast/agent/reporting/reporting_events/server_activity.rb +12 -20
  113. data/lib/contrast/agent/reporting/reporting_events/server_reporting_event.rb +27 -0
  114. data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +17 -27
  115. data/lib/contrast/agent/reporting/reporting_utilities/build_preflight.rb +38 -0
  116. data/lib/contrast/agent/reporting/reporting_utilities/dtm_message.rb +8 -0
  117. data/lib/contrast/agent/reporting/reporting_utilities/endpoints.rb +6 -0
  118. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +23 -7
  119. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +64 -76
  120. data/lib/contrast/agent/reporting/reporting_utilities/reporting_storage.rb +1 -1
  121. data/lib/contrast/agent/reporting/reporting_utilities/response.rb +17 -7
  122. data/lib/contrast/agent/reporting/reporting_utilities/response_extractor.rb +100 -0
  123. data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +75 -13
  124. data/lib/contrast/agent/reporting/reporting_utilities/response_handler_mode.rb +63 -0
  125. data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +154 -113
  126. data/lib/contrast/agent/reporting/settings/application_settings.rb +9 -0
  127. data/lib/contrast/agent/reporting/settings/assess_server_feature.rb +5 -33
  128. data/lib/contrast/agent/reporting/settings/protect.rb +1 -1
  129. data/lib/contrast/agent/reporting/settings/protect_server_feature.rb +2 -2
  130. data/lib/contrast/agent/reporting/settings/sampling.rb +36 -0
  131. data/lib/contrast/agent/reporting/settings/sensitive_data_masking.rb +110 -0
  132. data/lib/contrast/agent/reporting/settings/sensitive_data_masking_rule.rb +58 -0
  133. data/lib/contrast/agent/request.rb +3 -3
  134. data/lib/contrast/agent/request_context.rb +1 -1
  135. data/lib/contrast/agent/request_context_extend.rb +2 -2
  136. data/lib/contrast/agent/request_handler.rb +7 -3
  137. data/lib/contrast/agent/response.rb +2 -0
  138. data/lib/contrast/agent/service_heartbeat.rb +6 -48
  139. data/lib/contrast/agent/static_analysis.rb +1 -1
  140. data/lib/contrast/agent/telemetry/base.rb +151 -0
  141. data/lib/contrast/agent/telemetry/events/event.rb +35 -0
  142. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_base.rb +59 -0
  143. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_event.rb +44 -0
  144. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message.rb +115 -0
  145. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message_exception.rb +83 -0
  146. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_stack_frame.rb +64 -0
  147. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exceptions.rb +20 -0
  148. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exceptions_report.rb +32 -0
  149. data/lib/contrast/agent/telemetry/events/metric_event.rb +28 -0
  150. data/lib/contrast/agent/telemetry/events/startup_metrics_event.rb +123 -0
  151. data/lib/contrast/agent/thread_watcher.rb +52 -68
  152. data/lib/contrast/agent/version.rb +1 -1
  153. data/lib/contrast/agent/worker_thread.rb +8 -0
  154. data/lib/contrast/agent.rb +4 -3
  155. data/lib/contrast/api/communication/messaging_queue.rb +28 -11
  156. data/lib/contrast/api/communication/response_processor.rb +7 -10
  157. data/lib/contrast/api/communication/speedracer.rb +1 -1
  158. data/lib/contrast/api/decorators/activity.rb +33 -0
  159. data/lib/contrast/api/decorators/address.rb +1 -1
  160. data/lib/contrast/api/decorators/http_request.rb +1 -1
  161. data/lib/contrast/api/decorators/response_type.rb +30 -0
  162. data/lib/contrast/api/decorators.rb +1 -0
  163. data/lib/contrast/components/app_context.rb +0 -4
  164. data/lib/contrast/components/assess.rb +14 -0
  165. data/lib/contrast/components/config.rb +13 -22
  166. data/lib/contrast/components/contrast_service.rb +9 -0
  167. data/lib/contrast/components/protect.rb +2 -2
  168. data/lib/contrast/components/sampling.rb +7 -11
  169. data/lib/contrast/components/settings.rb +116 -8
  170. data/lib/contrast/config/agent_configuration.rb +34 -41
  171. data/lib/contrast/config/api_configuration.rb +16 -75
  172. data/lib/contrast/config/api_proxy_configuration.rb +9 -48
  173. data/lib/contrast/config/application_configuration.rb +24 -95
  174. data/lib/contrast/config/assess_configuration.rb +21 -76
  175. data/lib/contrast/config/assess_rules_configuration.rb +13 -38
  176. data/lib/contrast/config/base_configuration.rb +11 -76
  177. data/lib/contrast/config/certification_configuration.rb +15 -68
  178. data/lib/contrast/config/exception_configuration.rb +15 -59
  179. data/lib/contrast/config/heap_dump_configuration.rb +19 -73
  180. data/lib/contrast/config/inventory_configuration.rb +11 -55
  181. data/lib/contrast/config/logger_configuration.rb +8 -41
  182. data/lib/contrast/config/protect_configuration.rb +23 -10
  183. data/lib/contrast/config/protect_rule_configuration.rb +23 -37
  184. data/lib/contrast/config/protect_rules_configuration.rb +39 -43
  185. data/lib/contrast/config/request_audit_configuration.rb +16 -55
  186. data/lib/contrast/config/root_configuration.rb +70 -13
  187. data/lib/contrast/config/ruby_configuration.rb +14 -47
  188. data/lib/contrast/config/sampling_configuration.rb +12 -65
  189. data/lib/contrast/config/server_configuration.rb +13 -45
  190. data/lib/contrast/config/service_configuration.rb +36 -17
  191. data/lib/contrast/configuration.rb +21 -13
  192. data/lib/contrast/extension/assess/string.rb +20 -1
  193. data/lib/contrast/extension/module.rb +0 -1
  194. data/lib/contrast/framework/manager.rb +2 -2
  195. data/lib/contrast/framework/rails/patch/support.rb +13 -45
  196. data/lib/contrast/logger/aliased_logging.rb +87 -0
  197. data/lib/contrast/logger/application.rb +1 -5
  198. data/lib/contrast/logger/cef_log.rb +1 -1
  199. data/lib/contrast/tasks/config.rb +100 -4
  200. data/lib/contrast/utils/assess/object_store.rb +36 -0
  201. data/lib/contrast/utils/assess/propagation_method_utils.rb +6 -0
  202. data/lib/contrast/utils/class_util.rb +5 -18
  203. data/lib/contrast/utils/input_classification.rb +73 -0
  204. data/lib/contrast/utils/invalid_configuration_util.rb +1 -1
  205. data/lib/contrast/utils/log_utils.rb +3 -1
  206. data/lib/contrast/utils/middleware_utils.rb +10 -9
  207. data/lib/contrast/utils/net_http_base.rb +1 -1
  208. data/lib/contrast/utils/object_share.rb +2 -1
  209. data/lib/contrast/utils/os.rb +0 -5
  210. data/lib/contrast/utils/patching/policy/patch_utils.rb +4 -5
  211. data/lib/contrast/utils/response_utils.rb +18 -33
  212. data/lib/contrast/utils/telemetry.rb +20 -2
  213. data/lib/contrast/utils/telemetry_client.rb +23 -11
  214. data/lib/contrast/utils/telemetry_hash.rb +41 -0
  215. data/lib/contrast/utils/telemetry_identifier.rb +16 -1
  216. data/lib/contrast.rb +9 -0
  217. data/resources/assess/policy.json +98 -0
  218. data/resources/deadzone/policy.json +0 -86
  219. data/ruby-agent.gemspec +10 -9
  220. data/service_executables/VERSION +1 -1
  221. data/service_executables/linux/contrast-service +0 -0
  222. data/service_executables/mac/contrast-service +0 -0
  223. metadata +98 -30
  224. data/lib/contrast/agent/metric_telemetry_event.rb +0 -26
  225. data/lib/contrast/agent/startup_metrics_telemetry_event.rb +0 -121
  226. data/lib/contrast/agent/telemetry.rb +0 -137
  227. data/lib/contrast/agent/telemetry_event.rb +0 -33
  228. data/lib/contrast/utils/exclude_key.rb +0 -20
@@ -0,0 +1,53 @@
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/components/logger'
5
+ require 'contrast/agent/reporting/reporting_events/application_reporting_event'
6
+ require 'contrast/agent/reporting/reporting_events/application_defend_activity'
7
+ require 'contrast/agent/reporting/reporting_events/application_inventory_activity'
8
+
9
+ module Contrast
10
+ module Agent
11
+ module Reporting
12
+ # This is the new ApplicationActivity class which will include all the needed information for the new reporting
13
+ # system to report
14
+ class ApplicationActivity < Contrast::Agent::Reporting::ApplicationReportingEvent
15
+ class << self
16
+ # @param app_activity_dtm [Contrast::Api::Dtm::Activity]
17
+ # @return [Contrast::Agent::Reporting::ApplicationActivity]
18
+ def convert app_activity_dtm
19
+ app_activity = new
20
+ app_activity.attach_data app_activity_dtm
21
+ app_activity
22
+ end
23
+ end
24
+
25
+ def initialize
26
+ @defend = []
27
+ @inventory = []
28
+ @event_type = :application_activity
29
+ @event_endpoint = Contrast::Agent::Reporting::Endpoints.application_activity
30
+ super
31
+ end
32
+
33
+ def file_name
34
+ 'activity-application'
35
+ end
36
+
37
+ def to_controlled_hash
38
+ {
39
+ lastUpdate: since_last_update,
40
+ defend: @defend.map(&:to_controlled_hash),
41
+ inventory: @inventory.map(&:to_controlled_hash)
42
+ }
43
+ end
44
+
45
+ # @param activity_dtm [Contrast::Api::Dtm::ApplicationActivity]
46
+ def attach_data activity_dtm
47
+ @defend << Contrast::Agent::Reporting::ApplicationDefendActivity.convert(activity_dtm)
48
+ @inventory << Contrast::Agent::Reporting::ApplicationInventoryActivity.convert(activity_dtm)
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,48 @@
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/components/logger'
5
+ require 'contrast/agent/reporting/reporting_events/application_defend_attacker_activity'
6
+
7
+ module Contrast
8
+ module Agent
9
+ module Reporting
10
+ # This is the new ApplicationDefendActivity class which includes information about the defense of the application
11
+ # which was discovered during exercise of the application during this activity period.
12
+ class ApplicationDefendActivity
13
+ # @return [Array<Contrast::Agent::Reporting::ApplicationDefendAttackerActivity>]
14
+ attr_reader :attackers
15
+
16
+ class << self
17
+ # @param activity_dtm [Contrast::Api::Dtm::ApplicationActivity]
18
+ # @return [Contrast::Agent::Reporting::ApplicationDefendActivity]
19
+ def convert activity_dtm
20
+ activity = new
21
+ activity.attach_data activity_dtm.results
22
+ activity
23
+ end
24
+ end
25
+
26
+ def initialize
27
+ @attackers = []
28
+ @event_type = :application_defend_activity
29
+ super
30
+ end
31
+
32
+ def to_controlled_hash
33
+ {
34
+ attackers: attackers.map(&:to_controlled_hash)
35
+ }
36
+ end
37
+
38
+ # @param attack_dtms [Contrast::Api::Dtm::AttackResult]
39
+ # @return [Contrast::Agent::Reporting::ApplicationDefendAttackerActivity]
40
+ def attach_data attack_dtms
41
+ attack_dtms.each do |attack|
42
+ @attackers << Contrast::Agent::Reporting::ApplicationDefendAttackerActivity.convert(attack)
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,64 @@
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/components/logger'
5
+ require 'contrast/agent/reporting/reporting_events/application_defend_attack_sample_activity'
6
+
7
+ module Contrast
8
+ module Agent
9
+ module Reporting
10
+ # This is the new ApplicationDefendAttackActivity class which will include the attacks sent by the source.
11
+ class ApplicationDefendAttackActivity
12
+ attr_reader :blocked, :exploited, :ineffective, :suspicious
13
+
14
+ class << self
15
+ def convert attack_result
16
+ activity = new
17
+ activity.attach_data attack_result
18
+ activity
19
+ end
20
+ end
21
+
22
+ def initialize
23
+ @start_time = start_time
24
+ @blocked = []
25
+ @exploited = []
26
+ @ineffective = []
27
+ @suspicious = []
28
+ super
29
+ end
30
+
31
+ def to_controlled_hash
32
+ {
33
+ startTime: @start_time,
34
+ blocked: blocked.map(&:to_controlled_hash),
35
+ exploited: exploited.map(&:to_controlled_hash),
36
+ ineffective: ineffective.map(&:to_controlled_hash),
37
+ suspicious: suspicious.map(&:to_controlled_hash)
38
+ }
39
+ end
40
+
41
+ # @param attack_result [Contrast::Agent::Reporting::AttackResult]
42
+ # @return [Contrast::Agent::Reporting::Defend::AttackSampleActivity]
43
+ def attach_data attack_result
44
+ attack_sample_activity =
45
+ Contrast::Agent::Reporting::ApplicationDefendAttackSampleActivity.convert(attack_result)
46
+ case attack_result.response
47
+ when Contrast::Agent::Reporting::ResponseType::BLOCKED
48
+ @blocked << attack_sample_activity
49
+ when Contrast::Agent::Reporting::ResponseType::EXPLOITED
50
+ @exploited << attack_sample_activity
51
+ when Contrast::Agent::Reporting::ResponseType::MONITORED
52
+ @ineffective << attack_sample_activity
53
+ when Contrast::Agent::Reporting::ResponseType::SUSPICIOUS
54
+ @suspicious << attack_sample_activity
55
+ end
56
+ end
57
+
58
+ def start_time
59
+ Contrast::Agent::REQUEST_TRACKER.current&.timer&.start_ms
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,70 @@
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/components/logger'
5
+
6
+ module Contrast
7
+ module Agent
8
+ module Reporting
9
+ # This is the new ApplicationDefendAttackSample class which includes a samples of an attack for the given rule of
10
+ # the given result observed in the activity period.
11
+ class ApplicationDefendAttackSample
12
+ include Contrast::Agent::Reporting::InputType
13
+
14
+ class << self
15
+ def convert attack_result
16
+ activity = new
17
+ activity.attach_data attack_result
18
+ activity
19
+ end
20
+ end
21
+
22
+ def initialize
23
+ @blocked = false
24
+ @event_type = :application_defend_attack_sample
25
+ end
26
+
27
+ def to_controlled_hash
28
+ {
29
+ blocked: @blocked,
30
+ input: @input,
31
+ request: @request.to_controlled_hash,
32
+ stack: @stack,
33
+ timeStamp: @time_stamp
34
+ }
35
+ end
36
+
37
+ # @param attack_result [Contrast::Api::Dtm::AttackResult]
38
+ def attach_data attack_result
39
+ rasp_rule = attack_result.samples[0]
40
+ @blocked = attack_result.response == Contrast::Agent::Reporting::ResponseType::BLOCKED
41
+ @input = build_input(rasp_rule)
42
+ @time_stamp = build_time_stamp(rasp_rule.timestamp_ms)
43
+ @request = FindingRequest.convert(Contrast::Agent::REQUEST_TRACKER.current&.request)
44
+ @stack = Contrast::Utils::StackTraceUtils.build_protect_stack_array
45
+ end
46
+
47
+ def build_time_stamp start
48
+ {
49
+ start: start,
50
+ elapsed: Contrast::Utils::Timer.now_ms - start
51
+ }
52
+ end
53
+
54
+ def build_input rasp_rule
55
+ user_input = rasp_rule.user_input
56
+ {
57
+ details: Contrast::Api::Dtm::RaspRuleSample.to_controlled_hash(rasp_rule),
58
+ documentPath: user_input.path,
59
+ documentType: user_input.document_type,
60
+ filters: user_input.matcher_ids,
61
+ name: user_input.key,
62
+ time: rasp_rule.timestamp_ms,
63
+ type: user_input.input_type,
64
+ value: user_input.value
65
+ }
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,57 @@
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/components/logger'
5
+ require 'contrast/agent/reporting/reporting_events/application_defend_attack_sample'
6
+
7
+ module Contrast
8
+ module Agent
9
+ module Reporting
10
+ # This is the new AttackerSampleActivity class which will include Sample of the given attacks in the activity
11
+ # period.
12
+ class ApplicationDefendAttackSampleActivity
13
+ class << self
14
+ def convert attack_samples
15
+ activity = new
16
+ activity.attach_data attack_samples
17
+ activity
18
+ end
19
+ end
20
+
21
+ def initialize
22
+ @samples = []
23
+ @start_time = (Contrast::Agent::REQUEST_TRACKER.current&.timer&.start_ms || 0)
24
+ @event_type = :application_defend_attack_sample_activity
25
+ super
26
+ end
27
+
28
+ def to_controlled_hash
29
+ {
30
+ attackTimeMap: attack_time_map,
31
+ samples: @samples.map(&:to_controlled_hash),
32
+ startTime: @start_time,
33
+ total: 1 # there will only ever be 1 attack sample, until batching is done
34
+ }
35
+ end
36
+
37
+ # @param inventory_dtm [Contrast::Api::Dtm::ApplicationUpdate]
38
+ # @return [Contrast::Agent::Reporting::ApplicationInventory]
39
+ # TODO: RUBY-9999 update to handle batching
40
+ def attach_data attack_sample
41
+ @samples << Contrast::Agent::Reporting::ApplicationDefendAttackSample.convert(attack_sample)
42
+ end
43
+
44
+ def attack_time_map
45
+ {
46
+ second: duration,
47
+ count: 1 # there will only ever be 1 attack sample, until batching is done
48
+ }
49
+ end
50
+
51
+ def duration
52
+ Contrast::Utils::Timer.now_ms - @start_time
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,56 @@
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/components/logger'
5
+ require 'contrast/agent/reporting/reporting_events/application_defend_attack_activity'
6
+
7
+ module Contrast
8
+ module Agent
9
+ module Reporting
10
+ # This is the new AttackerActivity class which will includes the attacker information discovered during this
11
+ # activity period.
12
+ class ApplicationDefendAttackerActivity
13
+ attr_reader :attackers
14
+
15
+ class << self
16
+ def convert attack_result_dtm
17
+ activity = new
18
+ activity.attach_data attack_result_dtm
19
+ activity
20
+ end
21
+ end
22
+
23
+ def initialize
24
+ @protection_rules = {}
25
+ @request = Contrast::Agent::REQUEST_TRACKER.current.activity.http_request
26
+ @event_type = :application_defend_attacker_activity
27
+ super
28
+ end
29
+
30
+ def to_controlled_hash
31
+ {
32
+ protectionRules: process_protection_rules,
33
+ source: {
34
+ ip: @request.sender.ip,
35
+ xForwardedFor: @request.request_headers['X-Forwarded-For']
36
+ }
37
+ }
38
+ end
39
+
40
+ # @param attack_result [Contrast::Agent::Reporting::AttackResult]
41
+ def attach_data attack_result
42
+ attack_activity = Contrast::Agent::Reporting::ApplicationDefendAttackActivity.convert(attack_result)
43
+ @protection_rules[attack_result.rule_id] = attack_activity
44
+ end
45
+
46
+ def process_protection_rules
47
+ arr = []
48
+ @protection_rules.each_pair do |k, v|
49
+ arr << { k => v&.to_controlled_hash }
50
+ end
51
+ arr
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -9,9 +9,13 @@ module Contrast
9
9
  module Agent
10
10
  module Reporting
11
11
  # This is the new ApplicationInventory class which will include all the needed information
12
- # for the new reporting system to report
13
- class ApplicationInventory < Contrast::Agent::Reporting::ReportingEvent
14
- attr_accessor :routes, :agent_session_id_value
12
+ # for the new reporting system to report. Reporting those components or details discovered at
13
+ # startup, or as soon as possible, but not necessarily seen used by the application. Each of
14
+ # these messages should only be sent once per application.
15
+ class ApplicationInventory < Contrast::Agent::Reporting::ApplicationReportingEvent
16
+ # @param [Array<Contrast::Agent::Reporting::DiscoveredRoute>] the routes registered to this application, as
17
+ # discovered during first request processing.
18
+ attr_reader :routes
15
19
 
16
20
  class << self
17
21
  def convert app_update_dtm
@@ -21,6 +25,10 @@ module Contrast
21
25
  end
22
26
  end
23
27
 
28
+ def file_name
29
+ 'applications-inventory'
30
+ end
31
+
24
32
  def initialize
25
33
  @routes = []
26
34
  @event_type = :application_inventory
@@ -31,7 +39,7 @@ module Contrast
31
39
 
32
40
  def to_controlled_hash
33
41
  {
34
- session_id: agent_session_id_value,
42
+ session_id: @agent_session_id_value,
35
43
  routes: routes.map(&:to_controlled_hash)
36
44
  }
37
45
  end
@@ -0,0 +1,58 @@
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/components/logger'
5
+ require 'contrast/agent/reporting/reporting_events/application_reporting_event'
6
+ require 'contrast/agent/reporting/reporting_events/architecture_component'
7
+
8
+ module Contrast
9
+ module Agent
10
+ module Reporting
11
+ # This is the new ApplicationInventoryActivity class which will include all the information
12
+ # about the inventory of the application which was discovered during exercise of the application
13
+ # during this activity period.
14
+ class ApplicationInventoryActivity < Contrast::Agent::Reporting::ApplicationReportingEvent
15
+ # return [Contrast::Agent::Reporting::ArchitectureComponent]
16
+ attr_reader :components
17
+ # @ return [String, nil] - User-Agent Header value
18
+ attr_reader :browser
19
+
20
+ class << self
21
+ # @param activity_dtm [Contrast::Api::Dtm::ApplicationActivity]
22
+ # @return [Contrast::Agent::Reporting::ApplicationInventoryActivity]
23
+ def convert activity_dtm
24
+ inventory = new
25
+ inventory.attach_data activity_dtm
26
+ inventory
27
+ end
28
+ end
29
+
30
+ def initialize
31
+ @event_type = :application_inventory_activity
32
+ @components = []
33
+ super
34
+ end
35
+
36
+ def to_controlled_hash
37
+ {
38
+ activityDuration: duration,
39
+ browser: browser,
40
+ components: components.map(&:to_controlled_hash)
41
+ }
42
+ end
43
+
44
+ def attach_data activity
45
+ activity.architectures.each do |architecture|
46
+ @components << Contrast::Agent::Reporting::ArchitectureComponent.convert(architecture)
47
+ end
48
+ request_headers = activity.http_request&.request_headers
49
+ @browser = request_headers['USER_AGENT'] if request_headers
50
+ end
51
+
52
+ def duration
53
+ Contrast::Utils::Timer.now_ms - (Contrast::Agent::REQUEST_TRACKER.current&.timer&.start_ms || 0)
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,27 @@
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/reporting/reporting_events/reporting_event'
5
+ require 'contrast/utils/timer'
6
+
7
+ module Contrast
8
+ module Agent
9
+ module Reporting
10
+ # This is the new ApplicationReportingEvent class which will include all the needed and mutual information for
11
+ # those events which correspond to Applications, such as Application Activity or Application Update
12
+ #
13
+ # @abstract
14
+ class ApplicationReportingEvent < Contrast::Agent::Reporting::ReportingEvent
15
+ protected
16
+
17
+ # The timestamp field is a bit of a misnomer. It's really the time, in ms, since the settings for this
18
+ # application have been updated. If I've never updated, then it's been 0ms since then.
19
+ #
20
+ # @return [Integer]
21
+ def since_last_update
22
+ (update_time = Contrast::SETTINGS.last_app_update_ms) ? Contrast::Utils::Timer.now_ms - update_time : 0
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,50 @@
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/reporting/reporting_events/application_reporting_event'
5
+ require 'contrast/agent/reporting/reporting_events/application_startup_instrumentation'
6
+ require 'contrast/config'
7
+
8
+ module Contrast
9
+ module Agent
10
+ module Reporting
11
+ # This is the new ApplicationStartup class which will include all the needed information for the new reporting
12
+ # system to report an Application has started; creating a new one or marking an existing one as online in the
13
+ # Contrast UI
14
+ class ApplicationStartup < Contrast::Agent::Reporting::ApplicationReportingEvent
15
+ def initialize
16
+ @event_method = :PUT
17
+ @event_endpoint = Contrast::Agent::Reporting::Endpoints::NG_ENDPOINTS[:application_create]
18
+ super
19
+ end
20
+
21
+ def file_name
22
+ 'applications-create'
23
+ end
24
+
25
+ # Convert the instance variables on the class, and other information, into the identifiers required for
26
+ # TeamServer to process the JSON form of this message.
27
+ #
28
+ # @return [Hash]
29
+ # @raise [ArgumentError]
30
+ def to_controlled_hash
31
+ app_config = ::Contrast::CONFIG.root.application
32
+ hsh = {
33
+ code: app_config.code,
34
+ group: app_config.group,
35
+ instrumentation: Contrast::Agent::Reporting::ApplicationStartupInstrumentation.new.to_controlled_hash,
36
+ metadata: app_config.metadata,
37
+ tags: app_config.tags
38
+ }
39
+ if (session_id = ::Contrast::CONFIG.session_id)
40
+ hsh[:session_id] = session_id
41
+ end
42
+ if (session_metadata = ::Contrast::CONFIG.session_metadata)
43
+ hsh[:session_metadata] = session_metadata
44
+ end
45
+ hsh
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,27 @@
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/components/protect'
5
+
6
+ module Contrast
7
+ module Agent
8
+ module Reporting
9
+ # This is the new ApplicationStartupInstrumentation class which will include all the needed information for the
10
+ # system to report the instrumentation mode to which the agent was set by local configuration.
11
+ class ApplicationStartupInstrumentation
12
+ # Convert the instance variables on the class, and other information, into the identifiers required for
13
+ # TeamServer to process the JSON form of this message.
14
+ #
15
+ # @return [Hash]
16
+ # @raise [ArgumentError]
17
+ def to_controlled_hash
18
+ {
19
+ protect: {
20
+ enable: ::Contrast::PROTECT.enabled?
21
+ }
22
+ }
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/agent/reporting/reporting_events/architecture_component'
5
+ require 'contrast/agent/reporting/reporting_events/application_reporting_event'
5
6
  require 'contrast/agent/reporting/reporting_events/library_discovery'
6
7
  require 'contrast/agent/reporting/reporting_events/reporting_event'
7
8
  require 'contrast/agent/reporting/reporting_events/route_discovery'
@@ -17,7 +18,7 @@ module Contrast
17
18
  #
18
19
  # @attr_reader components [Array<Contrast::Agent::Reporting::ArchitectureComponent>]
19
20
  # @attr_reader libraries [Array<Contrast::Agent::Reporting::LibraryDiscovery>]
20
- class ApplicationUpdate < Contrast::Agent::Reporting::ReportingEvent
21
+ class ApplicationUpdate < Contrast::Agent::Reporting::ApplicationReportingEvent
21
22
  attr_reader :components, :libraries
22
23
 
23
24
  class << self
@@ -36,6 +37,10 @@ module Contrast
36
37
  super
37
38
  end
38
39
 
40
+ def file_name
41
+ 'update-application'
42
+ end
43
+
39
44
  # Attach the data from the protobuf models to this reporter so that it can be sent to TeamServer directly.
40
45
  #
41
46
  # @param app_update_dtm [Contrast::Api::Dtm::ApplicationUpdate]
@@ -58,7 +63,7 @@ module Contrast
58
63
  {
59
64
  components: components.map(&:to_controlled_hash),
60
65
  libraries: libraries.map(&:to_controlled_hash),
61
- timestamp: timestamp
66
+ timestamp: since_last_update
62
67
  }
63
68
  end
64
69
 
@@ -66,16 +71,6 @@ module Contrast
66
71
  #
67
72
  # @raise [ArgumentError]
68
73
  def validate; end
69
-
70
- private
71
-
72
- # The timestamp field is a bit of a misnomer. It's really the time, in ms, since the settings for this
73
- # application have been updated.
74
- #
75
- # @return [Integer]
76
- def timestamp
77
- Contrast::Utils::Timer.now_ms - (Contrast::Agent.reporter&.client&.response_handler&.last_app_update_ms || 0)
78
- end
79
74
  end
80
75
  end
81
76
  end
@@ -3,9 +3,9 @@
3
3
 
4
4
  require 'json'
5
5
  require 'contrast/components/logger'
6
+ require 'contrast/agent/reporting/reporting_events/application_reporting_event'
6
7
  require 'contrast/agent/reporting/reporting_events/finding_event'
7
8
  require 'contrast/agent/reporting/reporting_events/finding_request'
8
- require 'contrast/agent/reporting/reporting_events/reporting_event'
9
9
  require 'contrast/agent/assess/events/event_data'
10
10
  require 'contrast/utils/timer'
11
11
 
@@ -16,7 +16,7 @@ module Contrast
16
16
  # relay this information in the Finding/Trace messages. These findings are used by TeamServer to construct the
17
17
  # vulnerability information for the assess feature. They represent those parts of the application, either through
18
18
  # configuration, method invocation, or dataflow, which are determined to be insecure.
19
- class Finding < Contrast::Agent::Reporting::ReportingEvent
19
+ class Finding < Contrast::Agent::Reporting::ApplicationReportingEvent
20
20
  include Contrast::Components::Logger::InstanceMethods
21
21
 
22
22
  # @return [Integer] the time, in ms, that this object was initialized
@@ -75,6 +75,10 @@ module Contrast
75
75
  super()
76
76
  end
77
77
 
78
+ def file_name
79
+ 'traces'
80
+ end
81
+
78
82
  # Some reports require specific additional headers to be used. To that end, we'll attach them here, letting
79
83
  # each handle their own.
80
84
  #
@@ -100,7 +104,7 @@ module Contrast
100
104
  return unless request
101
105
 
102
106
  @request = Contrast::Agent::Reporting::FindingRequest.convert(request)
103
- @routes << Contrast::Agent::Reporting::RouteDiscovery.convert(request.route)
107
+ @routes << Contrast::Agent::Reporting::RouteDiscovery.convert(request.route) if request.route
104
108
  end
105
109
 
106
110
  # Attach the data from a Contrast::Api::Dtm::Finding required for property based findings generated during
@@ -148,7 +152,9 @@ module Contrast
148
152
  # @raise [ArgumentError]
149
153
  def validate
150
154
  raise(ArgumentError, "#{ self } did not have a proper rule. Unable to continue.") unless @rule_id
151
-
155
+ unless @agent_session_id_value
156
+ raise(ArgumentError, "#{ self } did not have a proper session id. Unable to continue.")
157
+ end
152
158
  if event_based? && events.empty?
153
159
  raise(ArgumentError, "#{ self } did not have proper events for #{ @rule_id }. Unable to continue.")
154
160
  end
@@ -278,14 +278,12 @@ module Contrast
278
278
  unless parent_object_ids
279
279
  raise(ArgumentError, "#{ self } did not have a proper parentObjectIds. Unable to continue.")
280
280
  end
281
- unless taint_ranges && !taint_ranges.empty?
282
- raise(ArgumentError, "#{ self } did not have a proper taintRanges. Unable to continue.")
283
- end
281
+ raise(ArgumentError, "#{ self } did not have a proper taintRanges. Unable to continue.") unless taint_ranges
284
282
  raise(ArgumentError, "#{ self } did not have a proper args. Unable to continue.") unless args
285
283
  raise(ArgumentError, "#{ self } did not have a proper object. Unable to continue.") unless object
286
284
  raise(ArgumentError, "#{ self } did not have a proper signature. Unable to continue.") unless signature
287
285
  raise(ArgumentError, "#{ self } did not have a proper stack. Unable to continue.") unless stack
288
- raise(ArgumentError, "#{ self } did not have a proper tags. Unable to continue.") unless tags && !tags.empty?
286
+ raise(ArgumentError, "#{ self } did not have a proper tags. Unable to continue.") unless tags
289
287
  end
290
288
  end
291
289
  end