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
@@ -10,57 +10,83 @@ module Contrast
10
10
  # The Ruby implementation of the Protect HTTP Method Tampering rule.
11
11
  class HttpMethodTampering < Contrast::Agent::Protect::Rule::BaseService
12
12
  NAME = 'method-tampering'
13
- STANDARD_METHODS = %w[GET HEAD POST PUT DELETE CONNECT OPTIONS TRACE PATCH].cs__freeze
13
+ # STANDARD_METHODS = %w[GET HEAD POST PUT DELETE CONNECT OPTIONS TRACE PATCH].cs__freeze
14
+ #
15
+ # APPLICABLE_METHODS_INPUTS = %w[
16
+ # ACL BASELINE-CONTROL CHECKIN CHECKOUT CONNECT COPY
17
+ # DELETE GET HEAD LABEL LOCK MERGE MKACTIVITY MKCALENDAR
18
+ # MKCOL MKWORKSPACE MOVE OPTIONS ORDERPATCH PATCH POST
19
+ # PROPFIND PROPPATCH PUT REPORT SEARCH TRACE UNCHECKOUT
20
+ # UNLOCK UPDATE VERSION-CONTROL
21
+ # ].cs__freeze
14
22
 
15
- def rule_name
16
- NAME
23
+ class << self
24
+ # @param attack_sample [Contrast::Api::Dtm::RaspRuleSample]
25
+ # @return [Hash] the details for this specific rule
26
+ def extract_details attack_sample
27
+ {
28
+ method: attack_sample.method_tampering.method, # rubocop:disable Security/Object/Method
29
+ responseCode: attack_sample.method_tampering.response_code
30
+ }
31
+ end
17
32
  end
18
33
 
19
- def postfilter context
20
- return unless enabled? && POSTFILTER_MODES.include?(mode)
21
- return if normal_request?(context)
22
-
23
- # The only way to be here in postfilter with a result is if the rule mode was MONITOR
24
- ia_results = gather_ia_results(context)
25
- return if ia_results.empty?
26
-
27
- # does the status code start with 4 or 5? Rails responds with 404 (but java is checking 501)
28
- response_code = context&.response&.response_code
29
- return unless response_code
30
-
31
- method = ia_results.first.value
32
- result = if response_code.to_s.start_with?('4', '5')
33
- build_attack_without_match(context, nil, nil, method: method, response_code: response_code)
34
- else
35
- build_attack_with_match(context, nil, nil, nil, method: method, response_code: response_code)
36
- end
37
-
38
- return unless result
39
-
40
- append_to_activity(context, result)
41
- cef_logging result, :ineffective_attack
42
- end
43
-
44
- protected
45
-
46
- def build_sample context, evaluation, _candidate_string, **kwargs
47
- sample = build_base_sample(context, evaluation)
48
- sample.user_input.value = kwargs[:method]
49
- sample.user_input.input_type = :METHOD
50
-
51
- sample.method_tampering = Contrast::Api::Dtm::HttpMethodTamperingDetails.new
52
- sample.method_tampering.method = Contrast::Utils::StringUtils.protobuf_safe_string(kwargs[:method])
53
- code = kwargs[:response_code] || -1
54
- sample.method_tampering.response_code = code.to_i
55
- sample
34
+ def rule_name
35
+ NAME
56
36
  end
57
37
 
58
- private
59
-
60
- def normal_request? context
61
- method = context.request.request_method
62
- context.request.static? || method.nil? || STANDARD_METHODS.include?(method.upcase)
63
- end
38
+ # This rule is solely based on input analysis, which the Service handles. When we move from the Service to the
39
+ # agent with protect library, we should re-enable these tests and that rule.
40
+ # TODO: RUBY-1574
41
+ # def enabled?
42
+ # super && false
43
+ # end
44
+ #
45
+ # def postfilter context
46
+ # return unless enabled? && POSTFILTER_MODES.include?(mode)
47
+ # return if normal_request?(context)
48
+ #
49
+ # # The only way to be here in postfilter with a result is if the rule mode was MONITOR
50
+ # ia_results = gather_ia_results(context)
51
+ # return if ia_results.empty?
52
+ #
53
+ # # does the status code start with 4 or 5? Rails responds with 404 (but java is checking 501)
54
+ # response_code = context&.response&.response_code
55
+ # return unless response_code
56
+ #
57
+ # method = ia_results.first.value
58
+ # result = if response_code.to_s.start_with?('4', '5')
59
+ # build_attack_without_match(context, nil, nil, method: method, response_code: response_code)
60
+ # else
61
+ # build_attack_with_match(context, nil, nil, nil, method: method, response_code: response_code)
62
+ # end
63
+ #
64
+ # return unless result
65
+ #
66
+ # append_to_activity(context, result)
67
+ # cef_logging result, :ineffective_attack
68
+ # end
69
+ #
70
+ # protected
71
+ #
72
+ # def build_sample context, evaluation, _candidate_string, **kwargs
73
+ # sample = build_base_sample(context, evaluation)
74
+ # sample.user_input.value = kwargs[:method]
75
+ # sample.user_input.input_type = :METHOD
76
+ #
77
+ # sample.method_tampering = Contrast::Api::Dtm::HttpMethodTamperingDetails.new
78
+ # sample.method_tampering.method = Contrast::Utils::StringUtils.protobuf_safe_string(kwargs[:method])
79
+ # code = kwargs[:response_code] || -1
80
+ # sample.method_tampering.response_code = code.to_i
81
+ # sample
82
+ # end
83
+ #
84
+ # private
85
+ #
86
+ # def normal_request? context
87
+ # method = context.request.request_method
88
+ # context.request.static? || method.nil? || STANDARD_METHODS.include?(method.upcase)
89
+ # end
64
90
  end
65
91
  end
66
92
  end
@@ -0,0 +1,231 @@
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/no_sqli'
6
+ require 'contrast/agent/protect/input_analyzer/input_analyzer'
7
+ require 'contrast/utils/input_classification'
8
+
9
+ module Contrast
10
+ module Agent
11
+ module Protect
12
+ module Rule
13
+ # This module will do the Input Classification stage of NoSQLI rule
14
+ # as a result input would be marked as WORTHWATCHING or IGNORE,
15
+ # to be analyzed at the sink level.
16
+ module NoSqliInputClassification
17
+ class << self
18
+ include InputClassificationBase
19
+
20
+ NOSQL_COMMENT_REGEXP = %r{"\s*(?:<--|//)}.cs__freeze
21
+ NOSQL_OR_REGEXP = /(?=(\s+\|\|\s+))/.cs__freeze
22
+ NOSQL_COMMENTS_AFTER_REGEXP = %r{(?:<--|//)}.cs__freeze
23
+
24
+ ZERO_OR_MORE_SPACES_REGEXP = /\s*/.cs__freeze
25
+ QUOTE_REGEXP = /['"’‘]/.cs__freeze
26
+ NUMBERS_AND_LETTERS_REGEXP = /[[:alnum:]]+/.cs__freeze
27
+ COMPARISON_REGEXP = /(?:==|>=|<=|>|<|)/.cs__freeze
28
+ NOSQL_QUOTED_REGEXP = /
29
+ #{ ZERO_OR_MORE_SPACES_REGEXP }
30
+ #{ QUOTE_REGEXP }
31
+ #{ NUMBERS_AND_LETTERS_REGEXP }
32
+ #{ QUOTE_REGEXP }
33
+ #{ ZERO_OR_MORE_SPACES_REGEXP }
34
+ #{ COMPARISON_REGEXP }
35
+ #{ ZERO_OR_MORE_SPACES_REGEXP }
36
+ #{ QUOTE_REGEXP }
37
+ #{ NUMBERS_AND_LETTERS_REGEXP }
38
+ #{ QUOTE_REGEXP }
39
+ /x.cs__freeze
40
+ NOSQL_NUMERIC_REGEXP = /
41
+ #{ ZERO_OR_MORE_SPACES_REGEXP }
42
+ #{ NUMBERS_AND_LETTERS_REGEXP }
43
+ #{ ZERO_OR_MORE_SPACES_REGEXP }
44
+ #{ COMPARISON_REGEXP }
45
+ #{ ZERO_OR_MORE_SPACES_REGEXP }
46
+ #{ NUMBERS_AND_LETTERS_REGEXP }
47
+ /x.cs__freeze
48
+
49
+ NOSQL_DEFINITE_THRESHOLD = 3
50
+ NOSQL_WORTH_WATCHING_THRESHOLD = 1
51
+ NOSQL_CONFIDENCE_THRESHOLD = 3
52
+ MAX_DISTANCE = 10
53
+
54
+ # Input Classification stage is done to determine if an user input is
55
+ # WORTHWATCHING or to be ignored.
56
+ #
57
+ # @param input_type [Contrast::Agent::Reporting::InputType] The type of the user input.
58
+ # @param value [String, Array<String>] the value of the input.
59
+ # @param input_analysis [Contrast::Agent::Reporting::InputAnalysis] Holds all the results from the
60
+ # agent analysis from the current
61
+ # Request.
62
+ # @return ia [Contrast::Agent::Reporting::InputAnalysis] with updated results.
63
+ def classify input_type, value, input_analysis
64
+ return unless input_analysis.request
65
+
66
+ rule_id = Contrast::Agent::Protect::Rule::NoSqli::NAME
67
+
68
+ # double check the input to avoid calling match? on array
69
+ Array(value).each do |val|
70
+ Array(val).each do |v|
71
+ input_analysis.results << nosqli_create_new_input_result(input_analysis.request,
72
+ rule_id,
73
+ input_type,
74
+ v)
75
+ end
76
+ end
77
+
78
+ input_analysis
79
+ end
80
+
81
+ private
82
+
83
+ # Creates a new instance of InputAnalysisResult with basic info.
84
+ #
85
+ # @param rule_id [String] The name of the Protect Rule.
86
+ # @param input_type [Contrast::Agent::Reporting::InputType] The type of the user input.
87
+ # @param score_level [Contrast::Agent::Reporting::ScoreLevel] the score tag after analysis.
88
+ # @param value [String, Array<String>] the value of the input.
89
+ # @param path [String] the path of the current request context.
90
+ #
91
+ # @return res [Contrast::Agent::Reporting::InputAnalysisResult]
92
+ def new_ia_result rule_id, input_type, score_level, path, value
93
+ super(rule_id, input_type, path, value).tap { |res| res.score_level = score_level }
94
+ end
95
+
96
+ # This methods checks if input should be tagged DEFINITEATTACK, WORTHWATCHING, or IGNORE,
97
+ # and creates a new instance of InputAnalysisResult.
98
+ #
99
+ # @param request [Contrast::Agent::Request] the current request context.
100
+ # @param rule_id [String] The name of the Protect Rule.
101
+ # @param input_type [Contrast::Agent::Reporting::InputType] The type of the user input.
102
+ # @param value [String, Array<String>] the value of the input.
103
+ #
104
+ # @return res [Contrast::Agent::Reporting::InputAnalysisResult]
105
+ def nosqli_create_new_input_result request, rule_id, input_type, value
106
+ score = evaluate_patterns(value)
107
+ score = evaluate_rules(value, score)
108
+
109
+ score_level = if definite_attack?(score)
110
+ DEFINITEATTACK
111
+ elsif worth_watching?(score)
112
+ WORTHWATCHING
113
+ else
114
+ IGNORE
115
+ end
116
+
117
+ new_ia_result(rule_id, input_type, score_level, request.path, value)
118
+ end
119
+
120
+ # This method evaluates the patterns relevant to NoSQL Injection to check whether
121
+ # the input is matched by any of them. The total score of all patterns matched is
122
+ # returned, unless the individual matching pattern score matches or exceeds
123
+ # NOSQL_CONFIDENCE_THRESHOLD *and* the total score for all evaluations matches or
124
+ # exceeds NOSQL_DEFINITE_THRESHOLD, in which case the total score achieved to that
125
+ # point is returned.
126
+ #
127
+ # @param value [String] the value of the input.
128
+ # @param value [Integer] the total score thus far.
129
+ #
130
+ # @return res [Integer]
131
+ def evaluate_patterns value, total_score = 0
132
+ applicable_patterns = nosqli_patterns
133
+ return total_score if applicable_patterns.nil?
134
+
135
+ total_patterns_score = 0
136
+ applicable_patterns.each do |pattern|
137
+ next unless value.match?(pattern[:value])
138
+
139
+ total_patterns_score += pattern[:score].to_i
140
+ total_score += pattern[:score].to_i
141
+
142
+ if pattern[:score].to_i >= NOSQL_CONFIDENCE_THRESHOLD && definite_attack?(total_score)
143
+ return total_score
144
+ end
145
+ end
146
+
147
+ total_score
148
+ end
149
+
150
+ def evaluate_comment_rule value
151
+ (value =~ NOSQL_COMMENT_REGEXP).nil? ? 0 : 2 # None/Medium
152
+ end
153
+
154
+ # This method evaluates the searcher rules relevant to NoSQL Injection to check whether
155
+ # the input is matched by any of them. The total score of all rules matched is
156
+ # returned, unless the individual matching rukle score matches or exceeds
157
+ # NOSQL_CONFIDENCE_THRESHOLD *and* the total score for all evaluations matches or
158
+ # exceeds NOSQL_DEFINITE_THRESHOLD, in which case the total score achieved to that
159
+ # point is returned.
160
+ #
161
+ # @param value [String] the value of the input.
162
+ # @param value [Integer] the total score thus far.
163
+ #
164
+ # @return res [Integer]
165
+ def evaluate_rules value, total_score = 0
166
+ total_rules_score = 0
167
+ %i[evaluate_comment_rule evaluate_or_rule].each do |method|
168
+ rule_score = send(method, value)
169
+ total_rules_score += rule_score
170
+ total_score += rule_score
171
+
172
+ return total_score if rule_score >= NOSQL_CONFIDENCE_THRESHOLD && definite_attack?(total_score)
173
+ end
174
+
175
+ total_score
176
+ end
177
+
178
+ # This method evaluates the input value for NoSQL Or searches. Each possible match is
179
+ # checked. If a match is found then a score of either 3 (High) or 4 (Critical) will
180
+ # be returned, depending on whether the regexp for finding comments is also matched.
181
+ #
182
+ # @param value [String] the value of the input.
183
+ #
184
+ # @return res [Integer]
185
+ def evaluate_or_rule value
186
+ score = 0
187
+
188
+ locs = matches_by_position(value, NOSQL_OR_REGEXP)
189
+ return score if locs.empty?
190
+
191
+ locs.each do |loc|
192
+ [NOSQL_QUOTED_REGEXP, NOSQL_NUMERIC_REGEXP].each do |pattern|
193
+ pattern_locs = matches_by_position(value[loc[1]..], pattern)
194
+ next unless !pattern_locs.empty? && pattern_locs[0][0] < MAX_DISTANCE
195
+
196
+ return 4 if value.match?(NOSQL_COMMENTS_AFTER_REGEXP, loc[1] + pattern_locs[0][1]) # Critical
197
+
198
+ score = 3 # High
199
+ break
200
+ end
201
+ end
202
+
203
+ score
204
+ end
205
+
206
+ # This method returns the patterns to be checked against the input value.
207
+ #
208
+ # @return res [Array, nil]
209
+ def nosqli_patterns
210
+ server_features = Contrast::Agent::Reporting::Settings::ServerFeatures.new
211
+ rule_definitions = server_features&.protect&.rule_definition_list
212
+ rule_definitions&.find { |r| r[:name] == Contrast::Agent::Protect::Rule::NoSqli::NAME }&.dig(:patterns)
213
+ end
214
+
215
+ def matches_by_position value, pattern
216
+ value.to_enum(:scan, pattern).map { Regexp.last_match.offset(Regexp.last_match.size - 1) }
217
+ end
218
+
219
+ def definite_attack? score
220
+ score >= NOSQL_DEFINITE_THRESHOLD
221
+ end
222
+
223
+ def worth_watching? score
224
+ score >= NOSQL_WORTH_WATCHING_THRESHOLD
225
+ end
226
+ end
227
+ end
228
+ end
229
+ end
230
+ end
231
+ end
@@ -18,6 +18,19 @@ module Contrast
18
18
 
19
19
  NAME = 'nosql-injection'
20
20
  BLOCK_MESSAGE = 'NoSQLi rule triggered. Response blocked.'
21
+ class << self
22
+ # @param attack_sample [Contrast::Api::Dtm::RaspRuleSample]
23
+ # @return [Hash] the details for this specific rule
24
+ def extract_details attack_sample
25
+ {
26
+ start: attack_sample.no_sqli.start_idx,
27
+ end: attack_sample.no_sqli.end_idx,
28
+ boundaryOverrunIndex: attack_sample.no_sqli.boundary_overrun_idx,
29
+ inputBoundaryIndex: attack_sample.no_sqli.input_boundary_idx,
30
+ query: attack_sample.no_sqli.query
31
+ }
32
+ end
33
+ end
21
34
 
22
35
  def rule_name
23
36
  NAME
@@ -35,8 +48,21 @@ module Contrast
35
48
 
36
49
  append_to_activity(context, result)
37
50
 
38
- cef_logging result, :successful_attack
39
- raise Contrast::SecurityException.new(self, BLOCK_MESSAGE) if blocked?
51
+ cef_logging(result, :successful_attack)
52
+ raise(Contrast::SecurityException.new(self, BLOCK_MESSAGE)) if blocked?
53
+ end
54
+
55
+ def build_attack_with_match context, input_analysis_result, result, candidate_string, **kwargs
56
+ if mode == Contrast::Api::Settings::ProtectionRule::Mode::NO_ACTION ||
57
+ mode == Contrast::Api::Settings::ProtectionRule::Mode::PERMIT
58
+
59
+ return result
60
+ end
61
+
62
+ result ||= build_attack_result(context)
63
+ update_successful_attack_response(context, input_analysis_result, result, candidate_string)
64
+ append_sample(context, input_analysis_result, result, candidate_string, **kwargs)
65
+ result
40
66
  end
41
67
 
42
68
  protected
@@ -25,6 +25,16 @@ module Contrast
25
25
  /windows/repair/
26
26
  ].cs__freeze
27
27
 
28
+ class << self
29
+ # @param attack_sample [Contrast::Api::Dtm::RaspRuleSample]
30
+ # @return [Hash] the details for this specific rule
31
+ def extract_details attack_sample
32
+ {
33
+ path: attack_sample.path_traversal.path
34
+ }
35
+ end
36
+ end
37
+
28
38
  def rule_name
29
39
  NAME
30
40
  end
@@ -38,9 +48,9 @@ module Contrast
38
48
  append_to_activity(context, result)
39
49
  return unless blocked?
40
50
 
41
- cef_logging result, :successful_attack, path
42
- raise Contrast::SecurityException.new(self,
43
- "Path Traversal rule triggered. Call to File.#{ method } blocked.")
51
+ cef_logging(result, :successful_attack, path)
52
+ raise(Contrast::SecurityException.new(self,
53
+ "Path Traversal rule triggered. Call to File.#{ method } blocked."))
44
54
  end
45
55
 
46
56
  protected
@@ -7,6 +7,8 @@ require 'contrast/agent/protect/rule/sqli'
7
7
  require 'contrast/agent/reporting/input_analysis/score_level'
8
8
  require 'contrast/agent/protect/rule/sqli/sqli_worth_watching'
9
9
  require 'contrast/agent/protect/input_analyzer/input_analyzer'
10
+ require 'contrast/utils/input_classification'
11
+ require 'contrast/components/logger'
10
12
 
11
13
  module Contrast
12
14
  module Agent
@@ -17,9 +19,9 @@ module Contrast
17
19
  # to be analyzed at the sink level.
18
20
  module SqliInputClassification
19
21
  class << self
20
- include Contrast::Agent::Reporting::InputType
21
- include Contrast::Agent::Reporting::ScoreLevel
22
+ include InputClassificationBase
22
23
  include Contrast::Agent::Protect::Rule::SqliWorthWatching
24
+ include Contrast::Components::Logger::InstanceMethods
23
25
 
24
26
  WORTHWATCHING_MATCH = 'sqli-worth-watching-v2'
25
27
  SQLI_KEYS_NEEDED = [
@@ -37,43 +39,25 @@ module Contrast
37
39
  # @return ia [Contrast::Agent::Reporting::InputAnalysis] with updated results.
38
40
  def classify input_type, value, input_analysis
39
41
  return unless Contrast::Agent::Protect::Rule::Sqli::APPLICABLE_USER_INPUTS.include?(input_type)
40
- return unless input_analysis.request
42
+ return unless super
41
43
 
42
44
  rule_id = Contrast::Agent::Protect::Rule::Sqli::NAME
43
- results = []
44
45
 
45
46
  # double check the input to avoid calling match? on array
46
47
  Array(value).each do |val|
47
48
  Array(val).each do |v|
48
- results << sqli_create_new_input_result(input_analysis.request, rule_id, input_type, v)
49
+ input_analysis.results << sqli_create_new_input_result(input_analysis.request, rule_id, input_type, v)
49
50
  end
50
51
  end
51
52
 
52
- input_analysis.results = results
53
53
  input_analysis
54
+ rescue StandardError => e
55
+ logger.debug('An Error was recorded in the input classification of the sqli.')
56
+ logger.debug(e)
54
57
  end
55
58
 
56
59
  private
57
60
 
58
- # Creates new isntance of InputAnalysisResult with basic info.
59
- #
60
- # @param rule_id [String] The name of the Protect Rule.
61
- # @param input_type [Contrast::Agent::Reporting::InputType] The type of the user input.
62
- # @param score_level [Contrast::Agent::Reporting::ScoreLevel] the score tag after analysis.
63
- # @param value [String, Array<String>] the value of the input.
64
- # @param path [String] the path of the current request context.
65
- #
66
- # @return res [Contrast::Agent::Reporting::InputAnalysisResult]
67
- def new_ia_result rule_id, input_type, score_level, path, value
68
- res = Contrast::Agent::Reporting::InputAnalysisResult.new
69
- res.rule_id = rule_id
70
- res.input_type = input_type
71
- res.path = path
72
- res.score_level = score_level
73
- res.value = value
74
- res
75
- end
76
-
77
61
  # This methods checks if input is tagged WORTHWATCHING or IGNORE matches value with it's
78
62
  # key if needed and Creates new isntance of InputAnalysisResult.
79
63
  #
@@ -84,37 +68,17 @@ module Contrast
84
68
  #
85
69
  # @return res [Contrast::Agent::Reporting::InputAnalysisResult]
86
70
  def sqli_create_new_input_result request, rule_id, input_type, value
87
- result = if sqli_worth_watching? value
88
- ia_result = new_ia_result(rule_id, input_type, WORTHWATCHING, request.path, value)
89
- ia_result.ids << WORTHWATCHING_MATCH
90
- ia_result
91
- else
92
- new_ia_result(rule_id, input_type, IGNORE, request.path, value)
93
- end
94
- if SQLI_KEYS_NEEDED.include? input_type
95
- result.key = sqli_add_needed_key request, result, input_type, value
96
- end
97
- result
98
- end
99
-
100
- # This methods checks if input is value that matches a key in the input.
101
- #
102
- # @param request [Contrast::Agent::Request] the current request context.
103
- # @param result [Contrast::Agent::Reporting::InputAnalysisResult] result to be updated.
104
- # @param input_type [Contrast::Agent::Reporting::InputType] The type of the user input.
105
- # @param value [String, Array<String>] the value of the input.
106
- #
107
- # @return result [Contrast::Agent::Reporting::InputAnalysisResult] updated with key result.
108
- def sqli_add_needed_key request, result, input_type, value
109
- case input_type
110
- when COOKIE_VALUE
111
- result.key = request.cookies.key(value)
112
- when PARAMETER_VALUE
113
- result.key = request.parameters.key(value)
71
+ ia_result = new_ia_result(rule_id, input_type, request.path, value)
72
+ if sqli_worth_watching?(value)
73
+ ia_result.ids << WORTHWATCHING_MATCH
74
+ ia_result.score_level = WORTHWATCHING
75
+ ia_result
114
76
  else
115
- result.key
77
+ ia_result.score_level = IGNORE
116
78
  end
117
- result.key
79
+
80
+ add_needed_key(request, ia_result, input_type, value) if SQLI_KEYS_NEEDED.include?(input_type)
81
+ ia_result
118
82
  end
119
83
  end
120
84
  end
@@ -91,7 +91,7 @@ module Contrast
91
91
  # @param input [String] the user input to be inspected
92
92
  # @return true | false
93
93
  def language_keywords? input
94
- contains_substring? input, SQL_KEYWORDS
94
+ contains_substring?(input, SQL_KEYWORDS)
95
95
  end
96
96
 
97
97
  # Helper method to find a substrings in given input.
@@ -99,9 +99,7 @@ module Contrast
99
99
  # @param substrings [Array] set of substrings to inspect.
100
100
  # @return true | false
101
101
  def contains_substring? input, substrings
102
- return true if substrings.any? { |sub| input.include?(sub) }
103
-
104
- false
102
+ substrings.any? { |sub| input.include?(sub) }
105
103
  end
106
104
 
107
105
  # Helper method to find the number of substrings.
@@ -111,7 +109,6 @@ module Contrast
111
109
  def number_of_substrings input, substring
112
110
  number = 0
113
111
  input.each_char.reduce(0) { |_acc, elem| number += 1 if contains_substring?(elem, substring) }
114
-
115
112
  number
116
113
  end
117
114
  end
@@ -31,6 +31,20 @@ module Contrast
31
31
  NAME = 'sql-injection'
32
32
  BLOCK_MESSAGE = 'SQLi rule triggered. Response blocked.'
33
33
 
34
+ class << self
35
+ # @param attack_sample [Contrast::Api::Dtm::RaspRuleSample]
36
+ # @return [Hash] the details for this specific rule
37
+ def extract_details attack_sample
38
+ {
39
+ start: attack_sample.sqli.start_idx,
40
+ end: attack_sample.sqli.end_idx,
41
+ boundaryOverrunIndex: attack_sample.sqli.boundary_overrun_idx,
42
+ inputBoundaryIndex: attack_sample.sqli.input_boundary_idx,
43
+ query: attack_sample.sqli.query
44
+ }
45
+ end
46
+ end
47
+
34
48
  def rule_name
35
49
  NAME
36
50
  end
@@ -47,29 +61,8 @@ module Contrast
47
61
 
48
62
  append_to_activity(context, result)
49
63
 
50
- cef_logging result, :successful_attack, query_string
51
- raise Contrast::SecurityException.new(self, BLOCK_MESSAGE) if blocked?
52
- end
53
-
54
- private
55
-
56
- def find_attacker context, potential_attack_string, **kwargs
57
- ia_results = gather_ia_results(context)
58
- find_attacker_with_results(context, potential_attack_string, ia_results, **kwargs)
59
- end
60
-
61
- def infilter? context
62
- return false unless context&.agent_input_analysis&.results
63
- return false unless enabled?
64
- return false if protect_excluded_by_code?
65
-
66
- true
67
- end
68
-
69
- def gather_ia_results context
70
- context.agent_input_analysis.results.select do |ia_result|
71
- ia_result.rule_id == rule_name
72
- end
64
+ cef_logging(result, :successful_attack, query_string)
65
+ raise(Contrast::SecurityException.new(self, BLOCK_MESSAGE)) if blocked?
73
66
  end
74
67
  end
75
68
  end