contrast-agent 5.3.0 → 6.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (306) 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_array/cs__assess_array.c +7 -0
  6. data/ext/cs__assess_basic_object/cs__assess_basic_object.c +24 -6
  7. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +1 -1
  8. data/ext/cs__assess_hash/cs__assess_hash.c +3 -4
  9. data/ext/cs__assess_kernel/cs__assess_kernel.c +1 -2
  10. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +26 -12
  11. data/ext/cs__assess_module/cs__assess_module.c +1 -1
  12. data/ext/cs__assess_regexp/cs__assess_regexp.c +15 -2
  13. data/ext/cs__assess_regexp/cs__assess_regexp.h +2 -0
  14. data/ext/cs__assess_string/cs__assess_string.c +21 -1
  15. data/ext/cs__assess_test/cs__assess_test.h +9 -0
  16. data/ext/cs__assess_test/cs__assess_tests.c +22 -0
  17. data/ext/cs__assess_test/extconf.rb +5 -0
  18. data/ext/cs__common/cs__common.c +113 -11
  19. data/ext/cs__common/cs__common.h +29 -5
  20. data/ext/cs__contrast_patch/cs__contrast_patch.c +55 -44
  21. data/ext/cs__os_information/cs__os_information.c +13 -10
  22. data/ext/cs__scope/cs__scope.c +146 -97
  23. data/ext/cs__tests/cs__tests.c +12 -0
  24. data/ext/cs__tests/cs__tests.h +3 -0
  25. data/ext/cs__tests/extconf.rb +5 -0
  26. data/ext/extconf_common.rb +1 -1
  27. data/lib/contrast/agent/assess/contrast_object.rb +16 -16
  28. data/lib/contrast/agent/assess/events/source_event.rb +17 -19
  29. data/lib/contrast/agent/assess/finalizers/hash.rb +4 -2
  30. data/lib/contrast/agent/assess/policy/policy.rb +9 -10
  31. data/lib/contrast/agent/assess/policy/policy_node.rb +58 -36
  32. data/lib/contrast/agent/assess/policy/policy_node_utils.rb +51 -0
  33. data/lib/contrast/agent/assess/policy/policy_scanner.rb +2 -16
  34. data/lib/contrast/agent/assess/policy/preshift.rb +8 -2
  35. data/lib/contrast/agent/assess/policy/propagation_method.rb +48 -14
  36. data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -3
  37. data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
  38. data/lib/contrast/agent/assess/policy/propagator/buffer.rb +119 -0
  39. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +1 -1
  40. data/lib/contrast/agent/assess/policy/propagator/keep.rb +19 -4
  41. data/lib/contrast/agent/assess/policy/propagator/remove.rb +18 -2
  42. data/lib/contrast/agent/assess/policy/propagator/splat.rb +17 -3
  43. data/lib/contrast/agent/assess/policy/propagator/split.rb +17 -21
  44. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +1 -1
  45. data/lib/contrast/agent/assess/policy/propagator/substitution_utils.rb +1 -1
  46. data/lib/contrast/agent/assess/policy/propagator/trim.rb +2 -2
  47. data/lib/contrast/agent/assess/policy/propagator.rb +1 -0
  48. data/lib/contrast/agent/assess/policy/source_method.rb +7 -7
  49. data/lib/contrast/agent/assess/policy/source_node.rb +1 -1
  50. data/lib/contrast/agent/assess/policy/trigger_method.rb +11 -17
  51. data/lib/contrast/agent/assess/policy/trigger_node.rb +16 -16
  52. data/lib/contrast/agent/assess/policy/trigger_validation/redos_validator.rb +1 -1
  53. data/lib/contrast/agent/assess/property/evented.rb +2 -2
  54. data/lib/contrast/agent/assess/property/tagged.rb +3 -3
  55. data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +6 -8
  56. data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +6 -7
  57. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +12 -7
  58. data/lib/contrast/agent/assess/rule/response/auto_complete_rule.rb +1 -1
  59. data/lib/contrast/agent/assess/rule/response/base_rule.rb +13 -6
  60. data/lib/contrast/agent/assess/rule/response/body_rule.rb +3 -3
  61. data/lib/contrast/agent/assess/rule/response/cache_control_header_rule.rb +66 -43
  62. data/lib/contrast/agent/assess/rule/response/click_jacking_header_rule.rb +4 -4
  63. data/lib/contrast/agent/assess/rule/response/csp_header_insecure_rule.rb +6 -6
  64. data/lib/contrast/agent/assess/rule/response/csp_header_missing_rule.rb +4 -4
  65. data/lib/contrast/agent/assess/rule/response/hsts_header_rule.rb +4 -4
  66. data/lib/contrast/agent/assess/rule/response/parameters_pollution_rule.rb +1 -1
  67. data/lib/contrast/agent/assess/rule/response/x_content_type_header_rule.rb +4 -4
  68. data/lib/contrast/agent/assess/rule/response/x_xss_protection_header_rule.rb +3 -4
  69. data/lib/contrast/agent/assess/tag.rb +13 -14
  70. data/lib/contrast/agent/at_exit_hook.rb +12 -1
  71. data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +0 -7
  72. data/lib/contrast/agent/deadzone/policy/policy.rb +0 -6
  73. data/lib/contrast/agent/exclusion_matcher.rb +3 -3
  74. data/lib/contrast/agent/inventory/database_config.rb +10 -3
  75. data/lib/contrast/agent/middleware.rb +10 -5
  76. data/lib/contrast/agent/patching/policy/after_load_patch.rb +3 -5
  77. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +2 -2
  78. data/lib/contrast/agent/patching/policy/method_policy_extend.rb +4 -4
  79. data/lib/contrast/agent/patching/policy/patch.rb +20 -19
  80. data/lib/contrast/agent/patching/policy/patch_status.rb +10 -3
  81. data/lib/contrast/agent/patching/policy/patcher.rb +4 -4
  82. data/lib/contrast/agent/patching/policy/policy.rb +13 -15
  83. data/lib/contrast/agent/patching/policy/policy_node.rb +32 -21
  84. data/lib/contrast/agent/patching/policy/trigger_node.rb +1 -1
  85. data/lib/contrast/agent/protect/exploitable_collection.rb +38 -0
  86. data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +132 -75
  87. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +4 -3
  88. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +3 -3
  89. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +1 -1
  90. data/lib/contrast/agent/protect/policy/rule_applicator.rb +4 -4
  91. data/lib/contrast/agent/protect/rule/base.rb +53 -9
  92. data/lib/contrast/agent/protect/rule/base_service.rb +31 -12
  93. data/lib/contrast/agent/protect/rule/cmd_injection.rb +23 -3
  94. data/lib/contrast/agent/protect/rule/cmdi/cmdi_input_classification.rb +83 -0
  95. data/lib/contrast/agent/protect/rule/cmdi/cmdi_worth_watching.rb +64 -0
  96. data/lib/contrast/agent/protect/rule/default_scanner.rb +2 -1
  97. data/lib/contrast/agent/protect/rule/deserialization.rb +18 -7
  98. data/lib/contrast/agent/protect/rule/http_method_tampering/http_method_tampering_input_classification.rb +96 -0
  99. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +72 -46
  100. data/lib/contrast/agent/protect/rule/no_sqli/no_sqli_input_classification.rb +231 -0
  101. data/lib/contrast/agent/protect/rule/no_sqli.rb +28 -2
  102. data/lib/contrast/agent/protect/rule/path_traversal.rb +13 -3
  103. data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +18 -54
  104. data/lib/contrast/agent/protect/rule/sqli/sqli_worth_watching.rb +2 -5
  105. data/lib/contrast/agent/protect/rule/sqli.rb +16 -23
  106. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_input_classification.rb +82 -0
  107. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_matcher.rb +45 -0
  108. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +42 -0
  109. data/lib/contrast/agent/protect/rule/xss.rb +17 -0
  110. data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +14 -13
  111. data/lib/contrast/agent/protect/rule/xxe.rb +25 -3
  112. data/lib/contrast/agent/reaction_processor.rb +1 -1
  113. data/lib/contrast/agent/reporting/attack_result/attack_result.rb +63 -0
  114. data/lib/contrast/agent/reporting/attack_result/rasp_rule_sample.rb +52 -0
  115. data/lib/contrast/agent/reporting/attack_result/response_type.rb +29 -0
  116. data/lib/contrast/agent/reporting/attack_result/user_input.rb +87 -0
  117. data/lib/contrast/agent/reporting/masker/masker.rb +243 -0
  118. data/lib/contrast/agent/reporting/masker/masker_utils.rb +62 -0
  119. data/lib/contrast/agent/reporting/report.rb +2 -0
  120. data/lib/contrast/agent/reporting/reporter.rb +29 -22
  121. data/lib/contrast/agent/reporting/reporter_heartbeat.rb +49 -0
  122. data/lib/contrast/agent/reporting/reporting_events/agent_startup.rb +34 -0
  123. data/lib/contrast/agent/reporting/reporting_events/application_activity.rb +51 -0
  124. data/lib/contrast/agent/reporting/reporting_events/application_defend_activity.rb +96 -0
  125. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_activity.rb +70 -0
  126. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample.rb +182 -0
  127. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample_activity.rb +56 -0
  128. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample_stack.rb +22 -0
  129. data/lib/contrast/agent/reporting/reporting_events/application_defend_attacker_activity.rb +70 -0
  130. data/lib/contrast/agent/reporting/reporting_events/application_inventory.rb +13 -5
  131. data/lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb +60 -0
  132. data/lib/contrast/agent/reporting/reporting_events/application_reporting_event.rb +27 -0
  133. data/lib/contrast/agent/reporting/reporting_events/application_startup.rb +44 -0
  134. data/lib/contrast/agent/reporting/reporting_events/application_startup_instrumentation.rb +27 -0
  135. data/lib/contrast/agent/reporting/reporting_events/application_update.rb +7 -12
  136. data/lib/contrast/agent/reporting/reporting_events/discovered_route.rb +1 -1
  137. data/lib/contrast/agent/reporting/reporting_events/finding.rb +10 -4
  138. data/lib/contrast/agent/reporting/reporting_events/finding_event.rb +2 -4
  139. data/lib/contrast/agent/reporting/reporting_events/finding_event_object.rb +3 -3
  140. data/lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb +5 -5
  141. data/lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb +6 -2
  142. data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +16 -12
  143. data/lib/contrast/agent/reporting/reporting_events/poll.rb +6 -2
  144. data/lib/contrast/agent/reporting/reporting_events/preflight.rb +10 -8
  145. data/lib/contrast/agent/reporting/reporting_events/preflight_message.rb +8 -11
  146. data/lib/contrast/agent/reporting/reporting_events/reporting_event.rb +2 -1
  147. data/lib/contrast/agent/reporting/reporting_events/route_coverage.rb +8 -6
  148. data/lib/contrast/agent/reporting/reporting_events/server_activity.rb +12 -20
  149. data/lib/contrast/agent/reporting/reporting_events/server_reporting_event.rb +27 -0
  150. data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +17 -27
  151. data/lib/contrast/agent/reporting/reporting_utilities/build_preflight.rb +38 -0
  152. data/lib/contrast/agent/reporting/reporting_utilities/dtm_message.rb +8 -0
  153. data/lib/contrast/agent/reporting/reporting_utilities/endpoints.rb +6 -0
  154. data/lib/contrast/agent/reporting/reporting_utilities/headers.rb +1 -2
  155. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +29 -13
  156. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +64 -76
  157. data/lib/contrast/agent/reporting/reporting_utilities/reporting_storage.rb +1 -1
  158. data/lib/contrast/agent/reporting/reporting_utilities/response.rb +17 -7
  159. data/lib/contrast/agent/reporting/reporting_utilities/response_extractor.rb +100 -0
  160. data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +75 -13
  161. data/lib/contrast/agent/reporting/reporting_utilities/response_handler_mode.rb +63 -0
  162. data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +163 -122
  163. data/lib/contrast/agent/reporting/settings/application_settings.rb +10 -1
  164. data/lib/contrast/agent/reporting/settings/assess.rb +5 -5
  165. data/lib/contrast/agent/reporting/settings/assess_server_feature.rb +7 -35
  166. data/lib/contrast/agent/reporting/settings/exclusions.rb +3 -3
  167. data/lib/contrast/agent/reporting/settings/protect.rb +21 -6
  168. data/lib/contrast/agent/reporting/settings/protect_server_feature.rb +6 -6
  169. data/lib/contrast/agent/reporting/settings/reaction.rb +3 -3
  170. data/lib/contrast/agent/reporting/settings/sampling.rb +36 -0
  171. data/lib/contrast/agent/reporting/settings/sensitive_data_masking.rb +110 -0
  172. data/lib/contrast/agent/reporting/settings/sensitive_data_masking_rule.rb +58 -0
  173. data/lib/contrast/agent/reporting/settings/server_features.rb +2 -2
  174. data/lib/contrast/agent/request.rb +5 -5
  175. data/lib/contrast/agent/request_context.rb +25 -21
  176. data/lib/contrast/agent/request_context_extend.rb +12 -25
  177. data/lib/contrast/agent/request_handler.rb +7 -3
  178. data/lib/contrast/agent/response.rb +2 -0
  179. data/lib/contrast/agent/rule_set.rb +2 -2
  180. data/lib/contrast/agent/scope.rb +1 -1
  181. data/lib/contrast/agent/service_heartbeat.rb +6 -48
  182. data/lib/contrast/agent/static_analysis.rb +1 -1
  183. data/lib/contrast/agent/telemetry/base.rb +155 -0
  184. data/lib/contrast/agent/telemetry/events/event.rb +35 -0
  185. data/lib/contrast/agent/telemetry/events/exceptions/obfuscate.rb +119 -0
  186. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_base.rb +59 -0
  187. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_event.rb +44 -0
  188. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message.rb +115 -0
  189. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message_exception.rb +83 -0
  190. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_stack_frame.rb +64 -0
  191. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exceptions.rb +20 -0
  192. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exceptions_report.rb +30 -0
  193. data/lib/contrast/agent/telemetry/events/metric_event.rb +28 -0
  194. data/lib/contrast/agent/telemetry/events/startup_metrics_event.rb +123 -0
  195. data/lib/contrast/agent/thread_watcher.rb +52 -68
  196. data/lib/contrast/agent/version.rb +1 -1
  197. data/lib/contrast/agent/worker_thread.rb +8 -0
  198. data/lib/contrast/agent.rb +4 -3
  199. data/lib/contrast/api/communication/messaging_queue.rb +29 -12
  200. data/lib/contrast/api/communication/response_processor.rb +7 -10
  201. data/lib/contrast/api/communication/service_lifecycle.rb +1 -1
  202. data/lib/contrast/api/communication/socket.rb +1 -1
  203. data/lib/contrast/api/communication/socket_client.rb +1 -1
  204. data/lib/contrast/api/communication/speedracer.rb +3 -3
  205. data/lib/contrast/api/decorators/activity.rb +33 -0
  206. data/lib/contrast/api/decorators/address.rb +1 -1
  207. data/lib/contrast/api/decorators/agent_startup.rb +10 -9
  208. data/lib/contrast/api/decorators/application_settings.rb +1 -1
  209. data/lib/contrast/api/decorators/application_startup.rb +4 -4
  210. data/lib/contrast/api/decorators/http_request.rb +1 -1
  211. data/lib/contrast/api/decorators/response_type.rb +17 -0
  212. data/lib/contrast/api/decorators.rb +1 -0
  213. data/lib/contrast/components/agent.rb +1 -1
  214. data/lib/contrast/components/app_context.rb +0 -4
  215. data/lib/contrast/components/assess.rb +14 -0
  216. data/lib/contrast/components/base.rb +1 -1
  217. data/lib/contrast/components/config.rb +19 -28
  218. data/lib/contrast/components/contrast_service.rb +13 -1
  219. data/lib/contrast/components/protect.rb +2 -2
  220. data/lib/contrast/components/sampling.rb +8 -12
  221. data/lib/contrast/components/settings.rb +151 -19
  222. data/lib/contrast/config/agent_configuration.rb +34 -41
  223. data/lib/contrast/config/api_configuration.rb +16 -75
  224. data/lib/contrast/config/api_proxy_configuration.rb +9 -48
  225. data/lib/contrast/config/application_configuration.rb +24 -95
  226. data/lib/contrast/config/assess_configuration.rb +21 -76
  227. data/lib/contrast/config/assess_rules_configuration.rb +13 -38
  228. data/lib/contrast/config/base_configuration.rb +11 -76
  229. data/lib/contrast/config/certification_configuration.rb +15 -68
  230. data/lib/contrast/config/exception_configuration.rb +15 -59
  231. data/lib/contrast/config/heap_dump_configuration.rb +19 -73
  232. data/lib/contrast/config/inventory_configuration.rb +11 -55
  233. data/lib/contrast/config/logger_configuration.rb +8 -41
  234. data/lib/contrast/config/protect_configuration.rb +23 -10
  235. data/lib/contrast/config/protect_rule_configuration.rb +23 -37
  236. data/lib/contrast/config/protect_rules_configuration.rb +39 -43
  237. data/lib/contrast/config/request_audit_configuration.rb +16 -55
  238. data/lib/contrast/config/root_configuration.rb +71 -14
  239. data/lib/contrast/config/ruby_configuration.rb +14 -47
  240. data/lib/contrast/config/sampling_configuration.rb +12 -65
  241. data/lib/contrast/config/server_configuration.rb +13 -45
  242. data/lib/contrast/config/service_configuration.rb +18 -54
  243. data/lib/contrast/configuration.rb +25 -17
  244. data/lib/contrast/extension/assess/array.rb +1 -1
  245. data/lib/contrast/extension/assess/erb.rb +1 -1
  246. data/lib/contrast/extension/assess/marshal.rb +1 -1
  247. data/lib/contrast/extension/assess/string.rb +20 -1
  248. data/lib/contrast/extension/extension.rb +2 -2
  249. data/lib/contrast/extension/module.rb +0 -1
  250. data/lib/contrast/framework/base_support.rb +8 -8
  251. data/lib/contrast/framework/grape/support.rb +3 -3
  252. data/lib/contrast/framework/manager.rb +7 -7
  253. data/lib/contrast/framework/manager_extend.rb +1 -1
  254. data/lib/contrast/framework/rack/patch/session_cookie.rb +1 -1
  255. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +14 -3
  256. data/lib/contrast/framework/rails/patch/assess_configuration.rb +3 -3
  257. data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +1 -1
  258. data/lib/contrast/framework/rails/patch/support.rb +14 -46
  259. data/lib/contrast/framework/rails/support.rb +2 -2
  260. data/lib/contrast/framework/sinatra/support.rb +1 -1
  261. data/lib/contrast/logger/aliased_logging.rb +94 -0
  262. data/lib/contrast/logger/application.rb +1 -5
  263. data/lib/contrast/logger/cef_log.rb +15 -15
  264. data/lib/contrast/logger/format.rb +1 -1
  265. data/lib/contrast/logger/log.rb +8 -8
  266. data/lib/contrast/tasks/config.rb +100 -4
  267. data/lib/contrast/tasks/service.rb +2 -2
  268. data/lib/contrast/utils/assess/object_store.rb +36 -0
  269. data/lib/contrast/utils/assess/propagation_method_utils.rb +6 -0
  270. data/lib/contrast/utils/assess/tracking_util.rb +4 -4
  271. data/lib/contrast/utils/class_util.rb +9 -22
  272. data/lib/contrast/utils/findings.rb +3 -3
  273. data/lib/contrast/utils/hash_digest.rb +6 -7
  274. data/lib/contrast/utils/head_dump_utils_extend.rb +1 -1
  275. data/lib/contrast/utils/input_classification.rb +73 -0
  276. data/lib/contrast/utils/invalid_configuration_util.rb +2 -2
  277. data/lib/contrast/utils/log_utils.rb +7 -5
  278. data/lib/contrast/utils/lru_cache.rb +1 -1
  279. data/lib/contrast/utils/metrics_hash.rb +1 -1
  280. data/lib/contrast/utils/middleware_utils.rb +15 -14
  281. data/lib/contrast/utils/net_http_base.rb +5 -5
  282. data/lib/contrast/utils/object_share.rb +2 -1
  283. data/lib/contrast/utils/os.rb +1 -6
  284. data/lib/contrast/utils/patching/policy/patch_utils.rb +6 -7
  285. data/lib/contrast/utils/request_utils.rb +2 -2
  286. data/lib/contrast/utils/response_utils.rb +18 -33
  287. data/lib/contrast/utils/sha256_builder.rb +4 -4
  288. data/lib/contrast/utils/stack_trace_utils.rb +31 -13
  289. data/lib/contrast/utils/telemetry.rb +22 -7
  290. data/lib/contrast/utils/telemetry_client.rb +28 -16
  291. data/lib/contrast/utils/telemetry_hash.rb +41 -0
  292. data/lib/contrast/utils/telemetry_identifier.rb +18 -3
  293. data/lib/contrast/utils/timer.rb +1 -1
  294. data/lib/contrast.rb +9 -0
  295. data/resources/assess/policy.json +99 -1
  296. data/resources/deadzone/policy.json +0 -86
  297. data/ruby-agent.gemspec +10 -9
  298. data/service_executables/VERSION +1 -1
  299. data/service_executables/linux/contrast-service +0 -0
  300. data/service_executables/mac/contrast-service +0 -0
  301. metadata +99 -29
  302. data/lib/contrast/agent/metric_telemetry_event.rb +0 -26
  303. data/lib/contrast/agent/startup_metrics_telemetry_event.rb +0 -121
  304. data/lib/contrast/agent/telemetry.rb +0 -137
  305. data/lib/contrast/agent/telemetry_event.rb +0 -33
  306. data/lib/contrast/utils/exclude_key.rb +0 -20
@@ -0,0 +1,82 @@
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/utils/object_share'
5
+ require 'contrast/agent/protect/rule/unsafe_file_upload'
6
+ require 'contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_matcher'
7
+ require 'contrast/agent/protect/input_analyzer/input_analyzer'
8
+ require 'contrast/utils/input_classification'
9
+
10
+ module Contrast
11
+ module Agent
12
+ module Protect
13
+ module Rule
14
+ # This module will do the Input Classification stage of Unsafe File Upload
15
+ # rule. As a result input would be marked as DEFINITEATTACK or IGNORE.
16
+ module UnsafeFileUploadInputClassification
17
+ # UNSAFE_UPLOAD_MATCH = 'unsafe-file-upload-input-tracing-v1'
18
+ #
19
+ # class << self
20
+ # include InputClassificationBase
21
+ # include Contrast::Agent::Protect::Rule::UnsafeFileUploadMatcher
22
+ #
23
+ # # Input Classification stage is done to determine if an user input is
24
+ # # DEFINITEATTACK or to be ignored.
25
+ # #
26
+ # # @param input_type [Contrast::Agent::Reporting::InputType] The type of the user input.
27
+ # # @param value [String, Array<String>] the value of the input.
28
+ # # @param input_analysis [Contrast::Agent::Reporting::InputAnalysis] Holds all the results from the
29
+ # # agent analysis from the current
30
+ # # Request.
31
+ # # @return ia [Contrast::Agent::Reporting::InputAnalysis] with updated results.
32
+ # def classify input_type, value, input_analysis
33
+ # unless Contrast::Agent::Protect::Rule::UnsafeFileUpload::APPLICABLE_USER_INPUTS.include?(input_type)
34
+ # return
35
+ # end
36
+ # return unless input_analysis.request
37
+ #
38
+ # rule_id = Contrast::Agent::Protect::Rule::UnsafeFileUpload::NAME
39
+ # results = []
40
+ #
41
+ # Array(value).each do |val|
42
+ # Array(val).each do |v|
43
+ # results << create_new_input_result(input_analysis.request, rule_id, input_type, v)
44
+ # end
45
+ # end
46
+ #
47
+ # input_analysis.results = results
48
+ # input_analysis
49
+ # end
50
+ #
51
+ # private
52
+ #
53
+ # # This methods checks if input is tagged DEFINITEATTACK or IGNORE matches value with it's
54
+ # # key if needed and Creates new isntance of InputAnalysisResult.
55
+ # #
56
+ # # @param request [Contrast::Agent::Request] the current request context.
57
+ # # @param rule_id [String] The name of the Protect Rule.
58
+ # # @param input_type [Contrast::Agent::Reporting::InputType] The type of the user input.
59
+ # # @param value [String, Array<String>] the value of the input.
60
+ # #
61
+ # # @return res [Contrast::Agent::Reporting::InputAnalysisResult]
62
+ # def create_new_input_result request, rule_id, input_type, value
63
+ # ia_result = new_ia_result rule_id, input_type, request.path, value
64
+ # if unsafe_match? value
65
+ # ia_result.score_level = DEFINITEATTACK
66
+ # ia_result.ids << UNSAFE_UPLOAD_MATCH
67
+ # else
68
+ # ia_result.score_level = IGNORE
69
+ # end
70
+ # ia_result.key = if input_type == MULTIPART_FIELD_NAME
71
+ # Contrast::Agent::Protect::InputAnalyzer::DISPOSITION_FILENAME
72
+ # else
73
+ # Contrast::Agent::Protect::InputAnalyzer::DISPOSITION_NAME
74
+ # end
75
+ # ia_result
76
+ # end
77
+ # end
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,45 @@
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 Agent
6
+ module Protect
7
+ module Rule
8
+ # Here will be made the match of the user input provided by the
9
+ # Agent InputAnalysis.
10
+ module UnsafeFileUploadMatcher
11
+ # EXPLOIT_CHARS = %w[.. ; � < > ~ *].cs__freeze # rubocop:disable Style/AsciiComments
12
+ # # Extensions that can be executed on the server side or can be dangerous on the client side:
13
+ # # https://owasp.org/www-community/vulnerabilities/Unrestricted_File_Upload
14
+ # EXPLOITABLE_EXTENSIONS = %w[.php .exe .rb .jsp .pht .phtml .shtml .asa .cer .asax .swf .xap].cs__freeze
15
+ #
16
+ # # Match the user input to see if the filename
17
+ # # contains malicious file extension.
18
+ # #
19
+ # # @param input [String] The filename
20
+ # # extracted from the current request
21
+ # # @return true | false
22
+ # def unsafe_match? input
23
+ # suspicious_chars?(input) || suspicious_extensions?(input)
24
+ # end
25
+ #
26
+ # private
27
+ #
28
+ # # @param input [String] The filename
29
+ # # extracted from the current request
30
+ # # @return true | false
31
+ # def suspicious_chars? input
32
+ # input.chars.any? { |c| EXPLOIT_CHARS.include? c }
33
+ # end
34
+ #
35
+ # # @param input [String] The filename
36
+ # # extracted from the current request
37
+ # # @return true | false
38
+ # def suspicious_extensions? input
39
+ # EXPLOITABLE_EXTENSIONS.include? File.extname(input).downcase
40
+ # end
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -2,19 +2,61 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/agent/protect/rule/base_service'
5
+ require 'contrast/agent/reporting/input_analysis/input_type'
6
+ require 'contrast/agent/reporting/input_analysis/score_level'
5
7
 
6
8
  module Contrast
7
9
  module Agent
8
10
  module Protect
9
11
  module Rule
10
12
  # The Ruby implementation of the Protect Unsafe File Upload rule.
13
+ # The unsafe-file-upload rule can trigger the following results:
14
+ # BLOCKED in Blocking mode na SUSPICIOUS in Monitor mode.
11
15
  class UnsafeFileUpload < Contrast::Agent::Protect::Rule::BaseService
16
+ include Contrast::Agent::Reporting::InputType
17
+
12
18
  NAME = 'unsafe-file-upload'
13
19
  BLOCK_MESSAGE = 'Unsafe file upload rule triggered. Request blocked.'
20
+ APPLICABLE_USER_INPUTS = [MULTIPART_NAME, MULTIPART_FIELD_NAME].cs__freeze
14
21
 
15
22
  def rule_name
16
23
  NAME
17
24
  end
25
+
26
+ # This rule is solely based on input analysis, which the Service handles. When we move from the Service to the
27
+ # agent with protect library, we should re-enable these tests and that rule.
28
+ # TODO: RUBY-1574
29
+ def enabled?
30
+ super && false
31
+ end
32
+
33
+ # def block_message
34
+ # BLOCK_MESSAGE
35
+ # end
36
+ #
37
+ # def prefilter context
38
+ # return unless prefilter?(context)
39
+ #
40
+ # ia_results = gather_ia_results context
41
+ #
42
+ # ia_results.each do |ia_result|
43
+ # result = build_attack_result(context)
44
+ # build_attack_without_match context, ia_result, result
45
+ # append_to_activity context, result
46
+ #
47
+ # cef_logging result, :successful_attack
48
+ # raise Contrast::SecurityException.new(self, BLOCK_MESSAGE) if blocked?
49
+ # end
50
+ # end
51
+ #
52
+ # private
53
+ #
54
+ # def prefilter? _context
55
+ # return false unless enabled?
56
+ # return false if protect_excluded_by_code?
57
+ #
58
+ # true
59
+ # end
18
60
  end
19
61
  end
20
62
  end
@@ -12,6 +12,23 @@ module Contrast
12
12
  NAME = 'reflected-xss'
13
13
  BLOCK_MESSAGE = 'XSS rule triggered. Response blocked.'
14
14
 
15
+ class << self
16
+ # @param attack_sample [Contrast::Api::Dtm::RaspRuleSample]
17
+ # @return [Hash] the details for this specific rule
18
+ def extract_details attack_sample
19
+ {
20
+ input: attack_sample.xss.input,
21
+ matches: attack_sample.xss.matches.map do |match|
22
+ {
23
+ evidenceStart: match.evidence_start_ms,
24
+ evidence: match.evidence,
25
+ offset: match.offset
26
+ }
27
+ end
28
+ }
29
+ end
30
+ end
31
+
15
32
  def rule_name
16
33
  NAME
17
34
  end
@@ -11,6 +11,20 @@ module Contrast
11
11
  class EntityWrapper
12
12
  attr_reader :system_id, :public_id
13
13
 
14
+ DTD_MARKER = '.dtd'
15
+ FILE_START = 'file:'
16
+ FTP_START = 'ftp:'
17
+ GOPHER_START = 'gopher:'
18
+ JAR_START = 'jar:'
19
+ UP_DIR_LINUX = '../'
20
+ UP_DIR_WIN = '..\\'
21
+ # <!ENTITY name SYSTEM "URI">
22
+ SYSTEM_ID_REGEXP = /<!ENTITY\s+(?<name>[a-zA-Z0-f]+)\s+SYSTEM\s+"(?<id>.*?)">/.cs__freeze
23
+ # <!ENTITY name PUBLIC "public_ID" "URI">
24
+ PUBLIC_ID_REGEXP = /<!ENTITY\s+(?<name>[a-zA-Z0-f]+)\s+PUBLIC\s+".*?"\s+"(?<id>.*?)">/.cs__freeze
25
+ # we only use this against lowercase strings, removed A-Z for speed
26
+ FILE_PATTERN_WINDOWS = /^\\*[a-z]{1,3}:.*/.cs__freeze
27
+
14
28
  def initialize entity
15
29
  @system_id = parse_system_id(entity)
16
30
  # an entity cannot be system and public
@@ -30,29 +44,16 @@ module Contrast
30
44
  @_external_entity
31
45
  end
32
46
 
33
- # <!ENTITY name SYSTEM "URI">
34
- SYSTEM_ID_REGEXP = /<!ENTITY\s+(?<name>[a-zA-Z0-f]+)\s+SYSTEM\s+"(?<id>.*?)">/.cs__freeze
35
47
  def parse_system_id entity
36
48
  match = SYSTEM_ID_REGEXP.match(entity)
37
49
  match[:id] if match
38
50
  end
39
51
 
40
- # <!ENTITY name PUBLIC "public_ID" "URI">
41
- PUBLIC_ID_REGEXP = /<!ENTITY\s+(?<name>[a-zA-Z0-f]+)\s+PUBLIC\s+".*?"\s+"(?<id>.*?)">/.cs__freeze
42
52
  def parse_public_id entity
43
53
  match = PUBLIC_ID_REGEXP.match(entity)
44
54
  match[:id] if match
45
55
  end
46
56
 
47
- DTD_MARKER = '.dtd'
48
- FILE_START = 'file:'
49
- FTP_START = 'ftp:'
50
- GOPHER_START = 'gopher:'
51
- JAR_START = 'jar:'
52
- UP_DIR_LINUX = '../'
53
- UP_DIR_WIN = '..\\'
54
- # we only use this against lowercase strings, removed A-Z for speed
55
- FILE_PATTERN_WINDOWS = /^\\*[a-z]{1,3}:.*/.cs__freeze
56
57
  def external_id? entity_id
57
58
  return false unless entity_id
58
59
 
@@ -13,11 +13,34 @@ module Contrast
13
13
  # of unsafe external entity resolution.
14
14
  class Xxe < Contrast::Agent::Protect::Rule::Base
15
15
  include Contrast::Components::Logger::InstanceMethods
16
+ INPUT_NAME = 'XML Prolog'
16
17
 
17
18
  NAME = 'xxe'
18
19
  BLOCK_MESSAGE = 'XXE rule triggered. Response blocked.'
19
20
  EXTERNAL_ENTITY_PATTERN = /<!ENTITY\s+[a-zA-Z0-f]+\s+(?:SYSTEM|PUBLIC)\s+(.*?)>/.cs__freeze
20
21
 
22
+ class << self
23
+ # @param attack_sample [Contrast::Api::Dtm::RaspRuleSample]
24
+ # @return [Hash] the details for this specific rule
25
+ def extract_details attack_sample
26
+ {
27
+ xml: attack_sample.xxe.xml,
28
+ declaredEntities: attack_sample.xxe.declared_entities.map do |entity|
29
+ {
30
+ start: entity.start_idx,
31
+ end: entity.end_idx
32
+ }
33
+ end,
34
+ entitiesResolved: attack_sample.xxe.entities_resolved.map do |entity|
35
+ {
36
+ systemId: entity.system_id,
37
+ publicId: entity.public_id
38
+ }
39
+ end
40
+ }
41
+ end
42
+ end
43
+
21
44
  def rule_name
22
45
  NAME
23
46
  end
@@ -39,8 +62,8 @@ module Contrast
39
62
  append_to_activity(context, result)
40
63
  return unless blocked?
41
64
 
42
- cef_logging result, :successful_attack, xml
43
- raise Contrast::SecurityException.new(self, BLOCK_MESSAGE)
65
+ cef_logging(result, :successful_attack, xml)
66
+ raise(Contrast::SecurityException.new(self, BLOCK_MESSAGE))
44
67
  end
45
68
 
46
69
  protected
@@ -100,7 +123,6 @@ module Contrast
100
123
  sample
101
124
  end
102
125
 
103
- INPUT_NAME = 'XML Prolog'
104
126
  def build_user_input ia_result
105
127
  input = Contrast::Api::Dtm::UserInput.new
106
128
  input.key = INPUT_NAME
@@ -33,7 +33,7 @@ module Contrast
33
33
 
34
34
  case reaction.operation
35
35
  when Contrast::Api::Settings::Reaction::Operation::DISABLE
36
- Contrast::Agent::DisableReaction.run reaction, level
36
+ Contrast::Agent::DisableReaction.run(reaction, level)
37
37
  when Contrast::Api::Settings::Reaction::Operation::NOOP
38
38
  # NOOP
39
39
  else
@@ -0,0 +1,63 @@
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/utils/object_share'
5
+ require 'contrast/utils/timer'
6
+ require 'contrast/agent/reporting/attack_result/response_type'
7
+ require 'contrast/agent/reporting/attack_result/rasp_rule_sample'
8
+
9
+ module Contrast
10
+ module Agent
11
+ module Reporting
12
+ # This class will hold the new Attacks results generated by our
13
+ # protect rules.
14
+ class AttackResult
15
+ RESPONSE_TYPE = Contrast::Agent::Reporting::ResponseType
16
+ # Generated the attack result
17
+ #
18
+ # @return @_response_type [Contrast::Agent::Reporting::ResponseType]
19
+ def response
20
+ @_response ||= RESPONSE_TYPE::NO_ACTION
21
+ end
22
+
23
+ # sets the response_type
24
+ #
25
+ # @param response_type [Contrast::Agent::Reporting::Settings::InputAnalysisResult]
26
+ # @return @_response_type []
27
+ def response= response_type
28
+ @_response = response_type if RESPONSE_TYPE.to_a.include?(response_type)
29
+ end
30
+
31
+ # @return @_rule_id [String]
32
+ def rule_id
33
+ @_rule_id ||= Contrast::Utils::ObjectShare::EMPTY_STRING
34
+ end
35
+
36
+ # @param rule_id [String]
37
+ # @return @_rule_id [String]
38
+ def rule_id= rule_id
39
+ @_rule_id = rule_id if rule_id.is_a?(String)
40
+ end
41
+
42
+ # @return @_samples [Array<Contrast::Agent::Reporting::RaspRuleSample>]
43
+ def samples
44
+ @_samples ||= []
45
+ end
46
+
47
+ # @param samples [Array<Contrast::Agent::Reporting::RaspRuleSample>]
48
+ # @return @_samples [Array<Contrast::Agent::Reporting::RaspRuleSample>]
49
+ def samples= samples
50
+ @_samples = samples if samples.is_a?(Array)
51
+ end
52
+
53
+ def tags
54
+ @_tags ||= Contrast::Utils::ObjectShare::EMPTY_STRING
55
+ end
56
+
57
+ def tags= tags
58
+ @_tags = tags if tags.is_a?(String)
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,52 @@
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/utils/object_share'
5
+ require 'contrast/utils/timer'
6
+ require 'contrast/agent/reporting/attack_result/user_input'
7
+
8
+ module Contrast
9
+ module Agent
10
+ module Reporting
11
+ # This class will hold the new RaspRuleSample.
12
+ # protect rules.
13
+ class RaspRuleSample # rubocop:disable Lint/EmptyClass
14
+ # def timestamp
15
+ # @_timestamp ||= 0
16
+ # end
17
+ #
18
+ # def timestamp= timestamp_ms
19
+ # @_timestamp = timestamp_ms
20
+ # end
21
+ #
22
+ # def user_input
23
+ # @_user_input ||= Contrast::Agent::Reporting::UserInput.new
24
+ # end
25
+ #
26
+ # def user_input= input
27
+ # @_user_input = input if input.is_a?(Contrast::Agent::Reporting::UserInput)
28
+ # end
29
+ #
30
+ # def build context, ia_result
31
+ # sample = self
32
+ # sample.timestamp = context&.timer&.start_ms
33
+ # sample.user_input = build_user_input_from_ia(ia_result)
34
+ # sample.user_input.document_type = if context&.request
35
+ # Contrast::Utils::StringUtils.force_utf8(context.request.document_type)
36
+ # end
37
+ # sample
38
+ # end
39
+ #
40
+ # def build_user_input_from_ia ia_result
41
+ # user_input = Contrast::Agent::Reporting::UserInput.new
42
+ # user_input.input_type = ia_result.input_type
43
+ # user_input.matcher_ids = ia_result.ids
44
+ # user_input.path = ia_result.path
45
+ # user_input.key = ia_result.key if ia_result.key
46
+ # user_input.value = ia_result.value if ia_result.value
47
+ # user_input
48
+ # end
49
+ end
50
+ end
51
+ end
52
+ 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: true
3
+
4
+ require 'contrast/utils/object_share'
5
+
6
+ module Contrast
7
+ module Agent
8
+ module Reporting
9
+ # This module will hold the response types used to generate
10
+ # attack result.
11
+ module ResponseType
12
+ BLOCKED = :BLOCKED.cs__freeze
13
+ MONITORED = :MONITORED.cs__freeze
14
+ PROBED = :PROBED.cs__freeze
15
+ BLOCK_AT_PERIMETER = :BLOCK_AT_PERIMETER.cs__freeze
16
+ SUSPICIOUS = :SUSPICIOUS.cs__freeze
17
+ AGGREGATED = :AGGREGATED.cs__freeze
18
+ EXPLOITED = :EXPLOITED.cs__freeze
19
+ NO_ACTION = :NO_ACTION.cs__freeze
20
+
21
+ class << self
22
+ def to_a
23
+ [NO_ACTION, BLOCKED, MONITORED, PROBED, BLOCK_AT_PERIMETER, EXPLOITED, SUSPICIOUS, AGGREGATED]
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,87 @@
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/utils/object_share'
5
+ require 'contrast/agent/reporting/input_analysis/input_type'
6
+ require 'contrast/agent/request_context'
7
+
8
+ module Contrast
9
+ module Agent
10
+ module Reporting
11
+ # This class will hold the new Sqli detail used by RaspRuleSample
12
+ class UserInput
13
+ INPUT_TYPE = Contrast::Agent::Reporting::InputType
14
+ DOCUMENT_TYPE = { XML: :XML, JSON: :JSON, NORMAL: :NORMAL }.cs__freeze
15
+
16
+ # @return @_path [String]
17
+ def path
18
+ @_path ||= Contrast::Utils::ObjectShare::EMPTY_STRING
19
+ end
20
+
21
+ # @param path [String]
22
+ # @return @_path [String]
23
+ def path= path
24
+ @_path = path if path.is_a?(String)
25
+ end
26
+
27
+ # @return @_key [String]
28
+ def key
29
+ @_key ||= Contrast::Utils::ObjectShare::EMPTY_STRING
30
+ end
31
+
32
+ # @param key [String]
33
+ # @return @_key [String]
34
+ def key= key
35
+ @_key = key if key.is_a?(String)
36
+ end
37
+
38
+ # @return value [String]
39
+ def value
40
+ @_value ||= Contrast::Utils::ObjectShare::EMPTY_STRING
41
+ end
42
+
43
+ # @param value [String]
44
+ # @return value [String]
45
+ def value= value
46
+ @_value = value if value.is_a?(String)
47
+ end
48
+
49
+ # @return @_input_type [
50
+ # Symbol<Contrast::Agent::Reporting::Settings::InputAnalysis::InputAnalysisResult::InputType>]
51
+ def input_type
52
+ @_input_type ||= INPUT_TYPE::UNDEFINED_TYPE
53
+ end
54
+
55
+ # @param input_type [
56
+ # Symbol<Contrast::Agent::Reporting::Settings::InputAnalysis::InputAnalysisResult::InputType>]
57
+ # @return @_input_type [
58
+ # Symbol<Contrast::Agent::Reporting::Settings::InputAnalysis::InputAnalysisResult::InputType>]
59
+ def input_type= input_type
60
+ @_input_type = input_type if INPUT_TYPE.to_a.include?(input_type)
61
+ end
62
+
63
+ # type [Symbol<:XML, :JSON, :NORMAL>]
64
+ def document_type
65
+ @_document_type ||= DOCUMENT_TYPE[:NORMAL]
66
+ end
67
+
68
+ def document_type= type
69
+ @_document_type = type if DOCUMENT_TYPE.value?(type)
70
+ end
71
+
72
+ # Matchers IDs
73
+ # @return @_ids [Array<String>]
74
+ def matcher_ids
75
+ @_matcher_ids ||= []
76
+ end
77
+
78
+ # Matchers IDs
79
+ # @param ids [Array<String>]
80
+ # @return @_ids [Array<String>]
81
+ def matcher_ids= ids
82
+ @_matcher_ids = ids if ids.is_a?(Array) && ids.any?(String)
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end