contrast-agent 6.6.4 → 6.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (340) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -2
  3. data/.gitmodules +0 -3
  4. data/.simplecov +0 -1
  5. data/Rakefile +0 -1
  6. data/ext/cs__assess_array/cs__assess_array.c +41 -10
  7. data/ext/cs__assess_array/cs__assess_array.h +4 -1
  8. data/ext/cs__scope/cs__scope.c +1 -1
  9. data/lib/contrast/agent/assess/contrast_event.rb +2 -24
  10. data/lib/contrast/agent/assess/events/source_event.rb +7 -61
  11. data/lib/contrast/agent/assess/finalizers/hash.rb +11 -0
  12. data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +0 -55
  13. data/lib/contrast/agent/assess/policy/policy_node.rb +3 -3
  14. data/lib/contrast/agent/assess/policy/policy_node_utils.rb +0 -1
  15. data/lib/contrast/agent/assess/policy/propagation_node.rb +4 -4
  16. data/lib/contrast/agent/assess/policy/source_method.rb +24 -1
  17. data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +7 -5
  18. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +6 -1
  19. data/lib/contrast/agent/assess/policy/trigger_method.rb +40 -121
  20. data/lib/contrast/agent/assess/policy/trigger_node.rb +3 -3
  21. data/lib/contrast/agent/assess/policy/trigger_validation/redos_validator.rb +1 -1
  22. data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +1 -1
  23. data/lib/contrast/agent/assess/policy/trigger_validation/xss_validator.rb +1 -1
  24. data/lib/contrast/agent/assess/property/evented.rb +2 -12
  25. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +42 -82
  26. data/lib/contrast/agent/assess/rule/response/base_rule.rb +11 -27
  27. data/lib/contrast/agent/assess/rule/response/body_rule.rb +1 -3
  28. data/lib/contrast/agent/assess/rule/response/cache_control_header_rule.rb +77 -62
  29. data/lib/contrast/agent/assess/rule/response/csp_header_insecure_rule.rb +1 -1
  30. data/lib/contrast/agent/assess/rule/response/framework/rails_support.rb +6 -1
  31. data/lib/contrast/agent/assess/rule/response/header_rule.rb +5 -5
  32. data/lib/contrast/agent/assess/rule/response/hsts_header_rule.rb +1 -1
  33. data/lib/contrast/agent/assess/rule/response/x_xss_protection_header_rule.rb +1 -1
  34. data/lib/contrast/agent/assess/tracker.rb +1 -7
  35. data/lib/contrast/agent/at_exit_hook.rb +1 -7
  36. data/lib/contrast/agent/excluder.rb +224 -0
  37. data/lib/contrast/agent/exclusion_matcher.rb +25 -7
  38. data/lib/contrast/agent/inventory/database_config.rb +18 -23
  39. data/lib/contrast/agent/middleware.rb +4 -5
  40. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +6 -0
  41. data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +146 -127
  42. data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +4 -0
  43. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +20 -0
  44. data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +1 -0
  45. data/lib/contrast/agent/protect/policy/rule_applicator.rb +1 -1
  46. data/lib/contrast/agent/protect/rule/base.rb +98 -66
  47. data/lib/contrast/agent/protect/rule/base_service.rb +49 -24
  48. data/lib/contrast/agent/protect/rule/bot_blocker/bot_blocker_input_classification.rb +98 -0
  49. data/lib/contrast/agent/protect/rule/bot_blocker.rb +81 -0
  50. data/lib/contrast/agent/protect/rule/cmd_injection.rb +30 -99
  51. data/lib/contrast/agent/protect/rule/cmdi/cmdi_backdoors.rb +132 -0
  52. data/lib/contrast/agent/protect/rule/cmdi/cmdi_base_rule.rb +169 -0
  53. data/lib/contrast/agent/protect/rule/cmdi/cmdi_chained_command.rb +69 -0
  54. data/lib/contrast/agent/protect/rule/cmdi/cmdi_dangerous_path.rb +68 -0
  55. data/lib/contrast/agent/protect/rule/cmdi/cmdi_input_classification.rb +2 -58
  56. data/lib/contrast/agent/protect/rule/default_scanner.rb +1 -1
  57. data/lib/contrast/agent/protect/rule/deserialization.rb +10 -19
  58. data/lib/contrast/agent/protect/rule/http_method_tampering/http_method_tampering_input_classification.rb +2 -2
  59. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +0 -11
  60. data/lib/contrast/agent/protect/rule/no_sqli/no_sqli_input_classification.rb +29 -34
  61. data/lib/contrast/agent/protect/rule/no_sqli.rb +25 -18
  62. data/lib/contrast/agent/protect/rule/path_traversal/path_traversal_input_classification.rb +61 -0
  63. data/lib/contrast/agent/protect/rule/path_traversal/path_traversal_semantic_security_bypass.rb +114 -0
  64. data/lib/contrast/agent/protect/rule/path_traversal.rb +46 -18
  65. data/lib/contrast/agent/protect/rule/sql_sample_builder.rb +49 -29
  66. data/lib/contrast/agent/protect/rule/sqli/sqli_base_rule.rb +37 -0
  67. data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +2 -62
  68. data/lib/contrast/agent/protect/rule/sqli/sqli_semantic/sqli_dangerous_functions.rb +67 -0
  69. data/lib/contrast/agent/protect/rule/sqli.rb +67 -22
  70. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_input_classification.rb +39 -63
  71. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +6 -33
  72. data/lib/contrast/agent/protect/rule/xss/reflected_xss_input_classification.rb +58 -0
  73. data/lib/contrast/agent/protect/rule/xss.rb +14 -20
  74. data/lib/contrast/agent/protect/rule/xxe.rb +15 -30
  75. data/lib/contrast/agent/protect/rule.rb +3 -1
  76. data/lib/contrast/agent/reporting/attack_result/attack_result.rb +8 -0
  77. data/lib/contrast/agent/reporting/attack_result/rasp_rule_sample.rb +70 -36
  78. data/lib/contrast/agent/reporting/attack_result/response_type.rb +9 -9
  79. data/lib/contrast/agent/reporting/attack_result/user_input.rb +11 -0
  80. data/lib/contrast/agent/reporting/details/bot_blocker_details.rb +29 -0
  81. data/lib/contrast/agent/reporting/details/cmd_injection_details.rb +30 -0
  82. data/lib/contrast/agent/reporting/details/details.rb +18 -0
  83. data/lib/contrast/agent/reporting/details/http_method_tempering_details.rb +27 -0
  84. data/lib/contrast/agent/reporting/details/ip_denylist_details.rb +35 -0
  85. data/lib/contrast/agent/reporting/details/no_sqli_details.rb +36 -0
  86. data/lib/contrast/agent/reporting/details/path_traversal_details.rb +24 -0
  87. data/lib/contrast/agent/reporting/details/path_traversal_semantic_analysis_details.rb +32 -0
  88. data/lib/contrast/agent/reporting/details/protect_rule_details.rb +17 -0
  89. data/lib/contrast/agent/reporting/details/sqli_dangerous_functions.rb +22 -0
  90. data/lib/contrast/agent/reporting/details/sqli_details.rb +36 -0
  91. data/lib/contrast/agent/reporting/details/untrusted_deserialization_details.rb +27 -0
  92. data/lib/contrast/agent/reporting/details/virtual_patch_details.rb +30 -0
  93. data/lib/contrast/agent/reporting/details/xss_details.rb +33 -0
  94. data/lib/contrast/agent/reporting/details/xss_match.rb +30 -0
  95. data/lib/contrast/agent/reporting/details/xxe_details.rb +36 -0
  96. data/lib/contrast/agent/reporting/details/xxe_match.rb +25 -0
  97. data/lib/contrast/agent/reporting/details/xxe_wrapper.rb +25 -0
  98. data/lib/contrast/agent/reporting/input_analysis/details/bot_blocker_details.rb +27 -0
  99. data/lib/contrast/agent/reporting/input_analysis/details/protect_rule_details.rb +15 -0
  100. data/lib/contrast/agent/reporting/input_analysis/input_analysis.rb +1 -2
  101. data/lib/contrast/agent/reporting/input_analysis/input_analysis_result.rb +17 -3
  102. data/lib/contrast/agent/reporting/masker/masker.rb +80 -65
  103. data/lib/contrast/agent/reporting/masker/masker_utils.rb +1 -30
  104. data/lib/contrast/agent/reporting/reporter.rb +1 -15
  105. data/lib/contrast/agent/reporting/reporting_events/agent_startup.rb +2 -2
  106. data/lib/contrast/agent/reporting/reporting_events/application_activity.rb +84 -15
  107. data/lib/contrast/agent/reporting/reporting_events/application_defend_activity.rb +13 -25
  108. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_activity.rb +19 -24
  109. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample.rb +46 -126
  110. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample_activity.rb +5 -16
  111. data/lib/contrast/agent/reporting/reporting_events/application_defend_attacker_activity.rb +10 -18
  112. data/lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb +6 -14
  113. data/lib/contrast/agent/reporting/reporting_events/application_startup.rb +1 -1
  114. data/lib/contrast/agent/reporting/reporting_events/application_update.rb +0 -2
  115. data/lib/contrast/agent/reporting/reporting_events/architecture_component.rb +7 -22
  116. data/lib/contrast/agent/reporting/reporting_events/finding.rb +23 -53
  117. data/lib/contrast/agent/reporting/reporting_events/finding_event.rb +12 -9
  118. data/lib/contrast/agent/reporting/reporting_events/finding_event_signature.rb +1 -1
  119. data/lib/contrast/agent/reporting/reporting_events/finding_event_source.rb +23 -21
  120. data/lib/contrast/agent/reporting/reporting_events/finding_event_stack.rb +5 -18
  121. data/lib/contrast/agent/reporting/reporting_events/finding_event_taint_range.rb +1 -0
  122. data/lib/contrast/{api/decorators/trace_taint_range_tags.rb → agent/reporting/reporting_events/finding_event_taint_range_tags.rb} +7 -6
  123. data/lib/contrast/agent/reporting/reporting_events/finding_request.rb +40 -10
  124. data/lib/contrast/agent/reporting/reporting_events/library_discovery.rb +0 -1
  125. data/lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb +1 -1
  126. data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +2 -2
  127. data/lib/contrast/agent/reporting/reporting_events/poll.rb +1 -11
  128. data/lib/contrast/agent/reporting/reporting_events/preflight_message.rb +10 -14
  129. data/lib/contrast/agent/reporting/reporting_events/reporting_event.rb +11 -0
  130. data/lib/contrast/agent/reporting/reporting_events/route_coverage.rb +3 -1
  131. data/lib/contrast/agent/reporting/reporting_events/route_discovery.rb +12 -25
  132. data/lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb +8 -27
  133. data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +3 -3
  134. data/lib/contrast/agent/reporting/reporting_utilities/build_preflight.rb +4 -7
  135. data/lib/contrast/agent/reporting/reporting_utilities/headers.rb +1 -1
  136. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +2 -1
  137. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +3 -3
  138. data/lib/contrast/agent/reporting/reporting_utilities/response.rb +1 -1
  139. data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +0 -3
  140. data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +1 -0
  141. data/lib/contrast/agent/reporting/settings/code_exclusion.rb +6 -1
  142. data/lib/contrast/agent/reporting/settings/exclusion_base.rb +18 -0
  143. data/lib/contrast/agent/reporting/settings/exclusions.rb +2 -1
  144. data/lib/contrast/agent/reporting/settings/input_exclusion.rb +9 -3
  145. data/lib/contrast/agent/reporting/settings/protect.rb +15 -15
  146. data/lib/contrast/agent/request.rb +4 -14
  147. data/lib/contrast/agent/request_context.rb +18 -24
  148. data/lib/contrast/agent/request_context_extend.rb +23 -164
  149. data/lib/contrast/agent/request_handler.rb +1 -11
  150. data/lib/contrast/agent/response.rb +0 -18
  151. data/lib/contrast/agent/telemetry/events/event.rb +1 -1
  152. data/lib/contrast/agent/telemetry/events/metric_event.rb +1 -1
  153. data/lib/contrast/agent/telemetry/events/startup_metrics_event.rb +3 -3
  154. data/lib/contrast/agent/thread_watcher.rb +3 -18
  155. data/lib/contrast/agent/version.rb +1 -1
  156. data/lib/contrast/agent.rb +0 -11
  157. data/lib/contrast/agent_lib/api/command_injection.rb +46 -0
  158. data/lib/contrast/agent_lib/api/init.rb +101 -0
  159. data/lib/contrast/agent_lib/api/input_tracing.rb +267 -0
  160. data/lib/contrast/agent_lib/api/method_tempering.rb +29 -0
  161. data/lib/contrast/agent_lib/api/panic.rb +87 -0
  162. data/lib/contrast/agent_lib/api/path_semantic_file_security_bypass.rb +40 -0
  163. data/lib/contrast/agent_lib/interface.rb +260 -0
  164. data/lib/contrast/agent_lib/interface_base.rb +118 -0
  165. data/lib/contrast/agent_lib/return_types/eval_result.rb +44 -0
  166. data/lib/contrast/agent_lib/test.rb +29 -0
  167. data/lib/contrast/api/communication/connection_status.rb +5 -5
  168. data/lib/contrast/components/agent.rb +13 -23
  169. data/lib/contrast/components/api.rb +10 -10
  170. data/lib/contrast/components/app_context.rb +9 -11
  171. data/lib/contrast/components/app_context_extend.rb +1 -26
  172. data/lib/contrast/components/assess.rb +92 -38
  173. data/lib/contrast/components/assess_rules.rb +36 -0
  174. data/lib/contrast/components/config.rb +49 -24
  175. data/lib/contrast/components/heap_dump.rb +1 -1
  176. data/lib/contrast/components/protect.rb +9 -6
  177. data/lib/contrast/components/ruby_component.rb +81 -0
  178. data/lib/contrast/components/sampling.rb +1 -1
  179. data/lib/contrast/components/security_logger.rb +23 -0
  180. data/lib/contrast/components/settings.rb +41 -85
  181. data/lib/contrast/config/base_configuration.rb +1 -1
  182. data/lib/contrast/config/protect_rule_configuration.rb +7 -7
  183. data/lib/contrast/config/protect_rules_configuration.rb +24 -48
  184. data/lib/contrast/config/server_configuration.rb +1 -1
  185. data/lib/contrast/config.rb +0 -6
  186. data/lib/contrast/configuration.rb +73 -18
  187. data/lib/contrast/extension/assess/array.rb +9 -0
  188. data/lib/contrast/extension/assess/exec_trigger.rb +3 -1
  189. data/lib/contrast/extension/assess/marshal.rb +3 -2
  190. data/lib/contrast/extension/assess/string.rb +0 -1
  191. data/lib/contrast/extension/delegator.rb +2 -0
  192. data/lib/contrast/extension/extension.rb +1 -1
  193. data/lib/contrast/framework/base_support.rb +0 -5
  194. data/lib/contrast/framework/grape/support.rb +1 -23
  195. data/lib/contrast/framework/manager.rb +3 -11
  196. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +1 -6
  197. data/lib/contrast/framework/rails/railtie.rb +0 -1
  198. data/lib/contrast/framework/rails/support.rb +5 -59
  199. data/lib/contrast/framework/sinatra/support.rb +2 -21
  200. data/lib/contrast/logger/cef_log.rb +21 -3
  201. data/lib/contrast/logger/log.rb +1 -11
  202. data/lib/contrast/tasks/config.rb +5 -10
  203. data/lib/contrast/utils/assess/event_limit_utils.rb +28 -12
  204. data/lib/contrast/utils/assess/trigger_method_utils.rb +10 -18
  205. data/lib/contrast/utils/duck_utils.rb +1 -0
  206. data/lib/contrast/utils/findings.rb +6 -5
  207. data/lib/contrast/utils/hash_digest.rb +9 -24
  208. data/lib/contrast/utils/hash_digest_extend.rb +6 -6
  209. data/lib/contrast/utils/input_classification_base.rb +156 -0
  210. data/lib/contrast/utils/invalid_configuration_util.rb +21 -58
  211. data/lib/contrast/utils/log_utils.rb +47 -17
  212. data/lib/contrast/utils/net_http_base.rb +2 -2
  213. data/lib/contrast/utils/os.rb +0 -20
  214. data/lib/contrast/utils/patching/policy/patch_utils.rb +3 -2
  215. data/lib/contrast/utils/response_utils.rb +0 -16
  216. data/lib/contrast/utils/stack_trace_utils.rb +3 -40
  217. data/lib/contrast/utils/string_utils.rb +19 -7
  218. data/lib/contrast/utils/telemetry_client.rb +13 -7
  219. data/lib/contrast.rb +7 -13
  220. data/resources/protect/policy.json +1 -2
  221. data/ruby-agent.gemspec +2 -5
  222. metadata +78 -137
  223. data/exe/contrast_service +0 -23
  224. data/lib/contrast/agent/protect/rule/cmdi/cmdi_worth_watching.rb +0 -64
  225. data/lib/contrast/agent/protect/rule/sqli/sqli_worth_watching.rb +0 -118
  226. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_matcher.rb +0 -45
  227. data/lib/contrast/agent/reaction_processor.rb +0 -47
  228. data/lib/contrast/agent/reporting/reporting_events/trace_event_source.rb +0 -30
  229. data/lib/contrast/agent/reporting/reporting_utilities/dtm_message.rb +0 -43
  230. data/lib/contrast/agent/service_heartbeat.rb +0 -35
  231. data/lib/contrast/api/communication/messaging_queue.rb +0 -129
  232. data/lib/contrast/api/communication/response_processor.rb +0 -90
  233. data/lib/contrast/api/communication/service_lifecycle.rb +0 -77
  234. data/lib/contrast/api/communication/socket.rb +0 -44
  235. data/lib/contrast/api/communication/socket_client.rb +0 -130
  236. data/lib/contrast/api/communication/speedracer.rb +0 -142
  237. data/lib/contrast/api/communication/tcp_socket.rb +0 -32
  238. data/lib/contrast/api/communication/unix_socket.rb +0 -28
  239. data/lib/contrast/api/communication.rb +0 -20
  240. data/lib/contrast/api/decorators/activity.rb +0 -33
  241. data/lib/contrast/api/decorators/address.rb +0 -59
  242. data/lib/contrast/api/decorators/agent_startup.rb +0 -57
  243. data/lib/contrast/api/decorators/application_settings.rb +0 -42
  244. data/lib/contrast/api/decorators/application_startup.rb +0 -56
  245. data/lib/contrast/api/decorators/architecture_component.rb +0 -36
  246. data/lib/contrast/api/decorators/bot_blocker.rb +0 -37
  247. data/lib/contrast/api/decorators/finding.rb +0 -29
  248. data/lib/contrast/api/decorators/http_request.rb +0 -137
  249. data/lib/contrast/api/decorators/input_analysis.rb +0 -18
  250. data/lib/contrast/api/decorators/instrumentation_mode.rb +0 -35
  251. data/lib/contrast/api/decorators/ip_denylist.rb +0 -37
  252. data/lib/contrast/api/decorators/message.rb +0 -71
  253. data/lib/contrast/api/decorators/rasp_rule_sample.rb +0 -58
  254. data/lib/contrast/api/decorators/response_type.rb +0 -17
  255. data/lib/contrast/api/decorators/route_coverage.rb +0 -91
  256. data/lib/contrast/api/decorators/server_features.rb +0 -25
  257. data/lib/contrast/api/decorators/trace_event.rb +0 -120
  258. data/lib/contrast/api/decorators/trace_event_object.rb +0 -63
  259. data/lib/contrast/api/decorators/trace_event_signature.rb +0 -69
  260. data/lib/contrast/api/decorators/trace_taint_range.rb +0 -52
  261. data/lib/contrast/api/decorators/user_input.rb +0 -51
  262. data/lib/contrast/api/decorators/virtual_patch.rb +0 -34
  263. data/lib/contrast/api/decorators.rb +0 -28
  264. data/lib/contrast/api/dtm.pb.rb +0 -852
  265. data/lib/contrast/api/settings.pb.rb +0 -500
  266. data/lib/contrast/api.rb +0 -16
  267. data/lib/contrast/components/contrast_service.rb +0 -88
  268. data/lib/contrast/config/assess_configuration.rb +0 -93
  269. data/lib/contrast/config/assess_rules_configuration.rb +0 -32
  270. data/lib/contrast/config/root_configuration.rb +0 -90
  271. data/lib/contrast/config/ruby_configuration.rb +0 -81
  272. data/lib/contrast/config/service_configuration.rb +0 -49
  273. data/lib/contrast/tasks/service.rb +0 -84
  274. data/lib/contrast/utils/input_classification.rb +0 -73
  275. data/lib/contrast/utils/preflight_util.rb +0 -13
  276. data/lib/protobuf/code_generator.rb +0 -129
  277. data/lib/protobuf/decoder.rb +0 -28
  278. data/lib/protobuf/deprecation.rb +0 -117
  279. data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +0 -79
  280. data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +0 -360
  281. data/lib/protobuf/descriptors.rb +0 -3
  282. data/lib/protobuf/encoder.rb +0 -11
  283. data/lib/protobuf/enum.rb +0 -365
  284. data/lib/protobuf/exceptions.rb +0 -9
  285. data/lib/protobuf/field/base_field.rb +0 -380
  286. data/lib/protobuf/field/base_field_object_definitions.rb +0 -504
  287. data/lib/protobuf/field/bool_field.rb +0 -64
  288. data/lib/protobuf/field/bytes_field.rb +0 -67
  289. data/lib/protobuf/field/double_field.rb +0 -25
  290. data/lib/protobuf/field/enum_field.rb +0 -56
  291. data/lib/protobuf/field/field_array.rb +0 -102
  292. data/lib/protobuf/field/field_hash.rb +0 -122
  293. data/lib/protobuf/field/fixed32_field.rb +0 -25
  294. data/lib/protobuf/field/fixed64_field.rb +0 -28
  295. data/lib/protobuf/field/float_field.rb +0 -43
  296. data/lib/protobuf/field/int32_field.rb +0 -21
  297. data/lib/protobuf/field/int64_field.rb +0 -34
  298. data/lib/protobuf/field/integer_field.rb +0 -23
  299. data/lib/protobuf/field/message_field.rb +0 -51
  300. data/lib/protobuf/field/sfixed32_field.rb +0 -27
  301. data/lib/protobuf/field/sfixed64_field.rb +0 -28
  302. data/lib/protobuf/field/signed_integer_field.rb +0 -29
  303. data/lib/protobuf/field/sint32_field.rb +0 -21
  304. data/lib/protobuf/field/sint64_field.rb +0 -21
  305. data/lib/protobuf/field/string_field.rb +0 -51
  306. data/lib/protobuf/field/uint32_field.rb +0 -21
  307. data/lib/protobuf/field/uint64_field.rb +0 -21
  308. data/lib/protobuf/field/varint_field.rb +0 -77
  309. data/lib/protobuf/field.rb +0 -74
  310. data/lib/protobuf/generators/base.rb +0 -85
  311. data/lib/protobuf/generators/enum_generator.rb +0 -39
  312. data/lib/protobuf/generators/extension_generator.rb +0 -27
  313. data/lib/protobuf/generators/field_generator.rb +0 -193
  314. data/lib/protobuf/generators/file_generator.rb +0 -262
  315. data/lib/protobuf/generators/group_generator.rb +0 -122
  316. data/lib/protobuf/generators/message_generator.rb +0 -104
  317. data/lib/protobuf/generators/option_generator.rb +0 -17
  318. data/lib/protobuf/generators/printable.rb +0 -160
  319. data/lib/protobuf/generators/service_generator.rb +0 -50
  320. data/lib/protobuf/lifecycle.rb +0 -33
  321. data/lib/protobuf/logging.rb +0 -39
  322. data/lib/protobuf/message/fields.rb +0 -233
  323. data/lib/protobuf/message/serialization.rb +0 -85
  324. data/lib/protobuf/message.rb +0 -241
  325. data/lib/protobuf/optionable.rb +0 -72
  326. data/lib/protobuf/tasks/compile.rake +0 -80
  327. data/lib/protobuf/tasks.rb +0 -1
  328. data/lib/protobuf/varint.rb +0 -20
  329. data/lib/protobuf/varint_pure.rb +0 -31
  330. data/lib/protobuf/version.rb +0 -3
  331. data/lib/protobuf/wire_type.rb +0 -10
  332. data/lib/protobuf.rb +0 -91
  333. data/proto/dynamic_discovery.proto +0 -46
  334. data/proto/google/protobuf/compiler/plugin.proto +0 -183
  335. data/proto/google/protobuf/descriptor.proto +0 -911
  336. data/proto/rpc.proto +0 -71
  337. data/service_executables/.gitkeep +0 -0
  338. data/service_executables/VERSION +0 -1
  339. data/service_executables/linux/contrast-service +0 -0
  340. data/service_executables/mac/contrast-service +0 -0
@@ -65,7 +65,7 @@ module Contrast
65
65
  @previous_path = current_path
66
66
  @previous_level = current_level_const
67
67
 
68
- progname = Contrast::CONFIG.root.agent.logger.progname
68
+ progname = Contrast::CONFIG.agent.logger.progname
69
69
  @_logger = build(path: current_path, level_const: current_level_const, progname: progname)
70
70
  # If we're logging to a new path, then let's start it w/ our helpful
71
71
  # data gathering messages
@@ -85,16 +85,6 @@ module Contrast
85
85
  def logger
86
86
  @_logger
87
87
  end
88
-
89
- # StringIO is a valid path because it logs directly to a string buffer
90
- def write_permission? path
91
- return false if path.nil?
92
- return true if path.is_a?(StringIO)
93
- return File.writable?(path) if File.exist?(path)
94
-
95
- dir_name = File.dirname(File.absolute_path(path))
96
- File.writable?(dir_name)
97
- end
98
88
  end
99
89
  end
100
90
  end
@@ -7,7 +7,7 @@ require 'contrast/agent/reporting/reporter'
7
7
 
8
8
  module Contrast
9
9
  # A Rake task to generate a contrast_security.yaml file with some basic settings
10
- module Config # rubocop:disable Metrics/ModuleLength
10
+ module Config
11
11
  extend Rake::DSL
12
12
  DEFAULT_CONFIG = {
13
13
  'api' => {
@@ -17,13 +17,6 @@ module Contrast
17
17
  'user_name' => 'Enter your Contrast user name'
18
18
  },
19
19
  'agent' => {
20
- 'service' => {
21
- 'logger' => {
22
- 'path' => 'contrast_service.log',
23
- 'level' => 'ERROR' # DEBUG | INFO | WARN | ERROR
24
- },
25
- 'socket' => '/tmp/contrast_service.sock'
26
- },
27
20
  'logger' => {
28
21
  'level' => 'ERROR',
29
22
  'path' => 'contrast_agent.log'
@@ -73,7 +66,9 @@ module Contrast
73
66
  config = Contrast::Configuration.new
74
67
  abort('Unable to Build Config') unless config
75
68
  missing = []
76
- api_hash = config.root.api.to_hash
69
+
70
+ api_hash = config.api.to_contrast_hash
71
+
77
72
  api_hash.each_key do |key|
78
73
  value = mask_keys(api_hash, key)
79
74
  if value.is_a?(Contrast::Config::ApiProxyConfiguration)
@@ -123,7 +118,7 @@ module Contrast
123
118
  def self.validate_headers
124
119
  missing = []
125
120
  reporter = Contrast::Agent::Reporter.new
126
- reporter_headers = reporter.client.headers.to_hash
121
+ reporter_headers = reporter.client.headers.to_contrast_hash
127
122
  reporter_headers.each_key do |key|
128
123
  value = mask_keys(reporter_headers, key)
129
124
  missing << key if value.nil?
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'contrast/components/logger'
5
+ require 'contrast/components/assess'
5
6
 
6
7
  module Contrast
7
8
  module Utils
@@ -16,30 +17,39 @@ module Contrast
16
17
  return false unless (context = Contrast::Agent::REQUEST_TRACKER.current)
17
18
 
18
19
  if method_policy.source_node
19
- max = (::Contrast::ASSESS.max_source_events ||
20
- Contrast::Config::AssessConfiguration::DEFAULT_MAX_SOURCE_EVENTS)
20
+ max = ::Contrast::ASSESS.max_context_source_events
21
21
  return at_limit?(method_policy, context.source_event_count, max)
22
22
 
23
23
  end
24
24
  if method_policy.propagation_node
25
- max = (::Contrast::ASSESS.max_propagation_events ||
26
- Contrast::Config::AssessConfiguration::DEFAULT_MAX_PROPAGATION_EVENTS)
25
+ max = ::Contrast::ASSESS.max_propagation_events
27
26
  return at_limit?(method_policy, context.propagation_event_count, max)
28
27
  end
29
28
 
30
29
  false # policy does not have limit
31
30
  end
32
31
 
33
- def event_limit_for_rule? rule_id
34
- if Contrast::Utils::Timer.now_ms > threshold_time_limit
35
- @_rule_counts = nil
36
- @_threshold_time_limit = nil
32
+ def event_limit_for_rule? rule_id # rubocop:disable Metrics/AbcSize
33
+ return false unless (context = Contrast::Agent::REQUEST_TRACKER.current)
34
+
35
+ saved_request_ids = rule_counts.keys.map { |k| k.to_s.split('_')[1].to_i }
36
+
37
+ # if we passed the threshold and we actually have records for that request - wipe them
38
+ if saved_request_ids.uniq.include?(context.request.__id__)
39
+ restore_defaults
37
40
  threshold_time_limit
38
41
  end
39
- rule_counts[rule_id] += 1
40
- # TODO: RUBY-1680 remove default
41
- rule_counts[rule_id] >=
42
- (::Contrast::ASSESS.max_rule_reported || Contrast::Config::AssessConfiguration::DEFAULT_MAX_RULE_REPORTED)
42
+
43
+ # if we have recorded rule counts, but none of them are for the current request_id
44
+ # eventually we can try and play with the time_limit_threshold -> DEFAULT_MAX_RULE_TIME_THRESHOLD
45
+ if !rule_counts.empty? && !saved_request_ids.include?(context.request.__id__)
46
+ restore_defaults
47
+ threshold_time_limit
48
+ end
49
+
50
+ rule_key = "#{ rule_id }_#{ context.request.__id__ }"
51
+ rule_counts[rule_key] += 1
52
+ rule_counts[rule_key] >= ::Contrast::ASSESS.max_rule_reported
43
53
  end
44
54
 
45
55
  # Increments the event count for the type of event that is being tracked
@@ -90,6 +100,12 @@ module Contrast
90
100
  def threshold_time_limit
91
101
  @_threshold_time_limit ||= Contrast::Utils::Timer.now_ms + (::Contrast::ASSESS.time_limit_threshold || 0)
92
102
  end
103
+
104
+ # @return nil
105
+ def restore_defaults
106
+ @_rule_counts = nil
107
+ @_threshold_time_limit = nil
108
+ end
93
109
  end
94
110
  end
95
111
  end
@@ -72,7 +72,8 @@ module Contrast
72
72
  elsif trigger_node.dataflow?
73
73
  apply_dataflow_rule(trigger_node, source, object, ret, *args)
74
74
  else # trigger rule - just calling the method is dangerous
75
- build_finding(trigger_node, source, object, ret, *args)
75
+ finding = build_finding(trigger_node, source, object, ret, *args)
76
+ Contrast::Agent::Assess::Policy::TriggerMethod.report_finding(finding) if finding
76
77
  end
77
78
  rescue StandardError => e
78
79
  logger.warn('Unable to apply trigger', e, node_id: trigger_node.id)
@@ -81,8 +82,8 @@ module Contrast
81
82
  # This is our method that actually checks the taint on the object our trigger_node targets for our Regexp
82
83
  # based rules.
83
84
  #
84
- # @param trigger_node [Contrast::Agent::Assess::Policy::TriggerNode] the node to direct applying this
85
- # trigger event
85
+ # @param trigger_node [Contrast::Agent::Assess::Policy::TriggerNode] the node to direct applying this trigger
86
+ # event
86
87
  # @param source [Object] the source of the Trigger Event
87
88
  # @param object [Object] the Object on which the method was invoked
88
89
  # @param ret [Object] the Return of the invoked method
@@ -92,7 +93,8 @@ module Contrast
92
93
  return if trigger_node.good_value && source.match?(trigger_node.good_value)
93
94
  return if trigger_node.bad_value && source !~ trigger_node.bad_value
94
95
 
95
- build_finding(trigger_node, source, object, ret, *args)
96
+ finding = build_finding(trigger_node, source, object, ret, *args)
97
+ Contrast::Agent::Assess::Policy::TriggerMethod.report_finding(finding) if finding
96
98
  end
97
99
 
98
100
  # This is our method that actually checks the taint on the object our trigger_node targets for our Dataflow
@@ -104,33 +106,23 @@ module Contrast
104
106
  # @param object [Object] the Object on which the method was invoked
105
107
  # @param ret [Object] the Return of the invoked method
106
108
  # @param args [Array<Object>] the Arguments with which the method was invoked
107
- def apply_dataflow_rule trigger_node, source, object, ret, *args # rubocop:disable Metrics/PerceivedComplexity
108
- return unless source
109
+ def apply_dataflow_rule trigger_node, source, object, ret, *args
110
+ return unless source && Contrast::Agent::Assess::Tracker.tracked?(source)
109
111
 
110
112
  if Contrast::Agent::Assess::Tracker.trackable?(source)
111
- return unless Contrast::Agent::Assess::Tracker.tracked?(source)
112
113
  return unless trigger_node.violated?(source)
113
114
 
114
- build_finding(trigger_node, source, object, ret, *args)
115
+ finding = build_finding(trigger_node, source, object, ret, *args)
116
+ report_finding(finding) if finding
115
117
  elsif Contrast::Utils::DuckUtils.iterable_hash?(source)
116
- return unless Contrast::Agent::Assess::Tracker.tracked?(source)
117
-
118
118
  source.each_pair do |key, value|
119
119
  apply_dataflow_rule(trigger_node, key, object, ret, *args)
120
120
  apply_dataflow_rule(trigger_node, value, object, ret, *args)
121
121
  end
122
122
  elsif Contrast::Utils::DuckUtils.iterable_enumerable?(source)
123
- return unless Contrast::Agent::Assess::Tracker.tracked?(source)
124
-
125
123
  source.each do |value|
126
124
  apply_dataflow_rule(trigger_node, value, object, ret, *args)
127
125
  end
128
- else
129
- logger.debug('Trigger source is untrackable. Unable to inspect.',
130
- node_id: trigger_node.id,
131
- source_id: source.__id__,
132
- source_type: source.cs__class.cs__name,
133
- frozen: source.cs__frozen?)
134
126
  end
135
127
  end
136
128
  end
@@ -13,6 +13,7 @@ module Contrast
13
13
  # @param method [Symbol]
14
14
  # @return [Boolean]
15
15
  def quacks_to? object, method
16
+ object.cs__respond_to?(method)
16
17
  return true if object.cs__respond_to?(method)
17
18
  return false unless object.is_a?(Delegator)
18
19
 
@@ -52,11 +52,12 @@ module Contrast
52
52
 
53
53
  while @_collection.any?
54
54
  finding = @_collection.pop
55
- Contrast::Agent::Assess::Policy::TriggerMethod.build_finding(finding[:trigger_node],
56
- finding[:source],
57
- finding[:object],
58
- finding[:ret],
59
- finding[:args])
55
+ collected = Contrast::Agent::Assess::Policy::TriggerMethod.build_finding(finding[:trigger_node],
56
+ finding[:source],
57
+ finding[:object],
58
+ finding[:ret],
59
+ finding[:args])
60
+ Contrast::Agent::Assess::Policy::TriggerMethod.report_finding(collected) if collected
60
61
  end
61
62
  true
62
63
  end
@@ -29,12 +29,10 @@ module Contrast
29
29
  @crc32 = 0
30
30
  end
31
31
 
32
- # Update to CRC checksum the finding route and verb if finding route
33
- # [Contrast::Api::Dtm::RouteCoverage] is available else update the passed
34
- # request or Contrast::REQUEST_TRACKER.current.request uri and used request
35
- # method.
32
+ # Update to CRC checksum the finding route and verb if finding route is available, else update the passed
33
+ # request or Contrast::REQUEST_TRACKER.current.request uri and used request method.
36
34
  #
37
- # @param finding [Contrast::Api::Dtm::Finding, Contrast::Agent::Reporting::Finding] finding to be reported
35
+ # @param finding [Contrast::Agent::Reporting::Finding] finding to be reported
38
36
  # @param request [Contrast::Agent::Request] our wrapper around the Rack::Request.
39
37
  # @return checksum [Integer, nil] returns nil if there is no request context or tracking
40
38
  # is disabled.
@@ -43,12 +41,9 @@ module Contrast
43
41
  return unless context || ::Contrast::ASSESS.non_request_tracking?
44
42
 
45
43
  if (route = finding.routes[0])
46
- if finding.cs__is_a?(Contrast::Agent::Reporting::Finding) && (observation = route.observations[0])
47
- update(observation.url)
44
+ update(route.signature)
45
+ if (observation = route.observations[0])
48
46
  update(observation.verb)
49
- else
50
- update(route.route) # the normalized URL used to access the method in the route.
51
- update(route.verb) # the HTTP Verb used to access the method in the route.
52
47
  end
53
48
  return
54
49
  end
@@ -60,24 +55,14 @@ module Contrast
60
55
  end
61
56
 
62
57
  # Update to CRC checksum the event source name and source type.
63
- # Expects Contrast::Api::Dtm::TraceEvent || Contrast::Agent::Assess::Events::SourceEvent
64
58
  #
65
- # @param events [Protobuf::Field::FieldArray<Contrast::Api::Dtm::TraceEvent>,
66
- # <Contrast::Agent::Assess::Events::SourceEvent>]
67
- # Array of TraceEvents
59
+ # @param events [Array<Contrast::Agent::Reporting::FindingEvent>]
68
60
  # @return checksum [Integer, nil] returns nil if there is no events
69
61
  def update_on_sources events
70
- return unless events&.any?
71
-
72
62
  events.each do |event|
73
- if event.cs__is_a?(Contrast::Api::Dtm::TraceEvent)
74
- event.event_sources&.each do |source|
75
- update(source.type)
76
- update(source.name) # rubocop:disable Security/Module/Name
77
- end
78
- elsif event.cs__is_a?(Contrast::Agent::Assess::Events::SourceEvent)
79
- update(event.source_type)
80
- update(event.source_name)
63
+ event.event_sources.each do |source|
64
+ update(source.type)
65
+ update(source.name) # rubocop:disable Security/Module/Name
81
66
  end
82
67
  end
83
68
  end
@@ -34,7 +34,7 @@ module Contrast
34
34
  # crypto(crypto-bad-ciphers, crypto-bad-mac) rules or trigger event
35
35
  # and returns string representation.
36
36
  #
37
- # @param finding [Contrast::Api::Dtm::Finding] to be reported
37
+ # @param finding [Contrast::Agent::Reporting::Finding] to be reported
38
38
  # @param source [Object] the source of the Trigger Event
39
39
  # @param request [Contrast::Agent::Request] our wrapper around the Rack::Request.
40
40
  # @return checksum [String] String representation of CRC32 checksum
@@ -50,7 +50,7 @@ module Contrast
50
50
  # Generates the hash checksum for configurations. Converts the finding rule_id, session_id and configPath and
51
51
  # to CRC32 checksum and returns string representation to be appended to Contrast::Api::Dtm::Finding
52
52
  #
53
- # @param finding [Contrast::Api::Dtm::Finding] to be reported
53
+ # @param finding [Contrast::Agent::Reporting::Finding] to be reported
54
54
  # @return checksum [String] String representation of CRC32 checksum.
55
55
  def generate_config_hash finding
56
56
  hash = new
@@ -65,7 +65,7 @@ module Contrast
65
65
  # Generates the hash checksum for class scanning. Converts the rule_id, finding.properties(source, name)
66
66
  # to CRC32 checksum and returns string representation.
67
67
  #
68
- # @param finding [Contrast::Api::Dtm::Finding] to be reported
68
+ # @param finding [Contrast::Agent::Reporting::Finding] to be reported
69
69
  # @return checksum [String] String representation of CRC32 checksum.
70
70
  def generate_class_scanning_hash finding
71
71
  hash = new
@@ -86,7 +86,7 @@ module Contrast
86
86
  # used in #generate_event_hash.
87
87
  #
88
88
  #
89
- # @param finding [Contrast::Api::Dtm::Finding] to be reported
89
+ # @param finding [Contrast::Agent::Reporting::Finding] to be reported
90
90
  # @param algorithm [Object] the source of the Trigger Event
91
91
  # @param request [Contrast::Agent::Request] our wrapper around the Rack::Request.
92
92
  # @return checksum [String] String representation of CRC32 checksum
@@ -101,7 +101,7 @@ module Contrast
101
101
  # Generates the hash checksum for dataflow when the finding events are more than one
102
102
  # used in #generate_event_hash.
103
103
  #
104
- # @param finding [Contrast::Api::Dtm::Finding] to be reported
104
+ # @param finding [Contrast::Agent::Reporting::Finding] to be reported
105
105
  # @param request [Contrast::Agent::Request] our wrapper around the Rack::Request.
106
106
  # @return checksum [String] String representation of CRC32 checksum
107
107
  def generate_dataflow_hash finding, request
@@ -115,7 +115,7 @@ module Contrast
115
115
  # Generates the hash checksum for trigger
116
116
  # used in #generate_event_hash.
117
117
  #
118
- # @param finding [Contrast::Api::Dtm::Finding] to be reported
118
+ # @param finding [Contrast::Agent::Reporting::Finding] to be reported
119
119
  # @param request [Contrast::Agent::Request] our wrapper around the Rack::Request.
120
120
  # @return checksum [String] String representation of CRC32 checksum
121
121
  def generate_trigger_hash finding, request
@@ -0,0 +1,156 @@
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/reporting/input_analysis/score_level'
7
+ require 'contrast/agent/protect/input_analyzer/input_analyzer'
8
+ require 'contrast/components/logger'
9
+
10
+ module Contrast
11
+ module Agent
12
+ module Protect
13
+ module Rule
14
+ # This module will include all the similar information for all input classifications
15
+ # between different rules
16
+ module InputClassificationBase
17
+ UNKNOWN_KEY = 'unknown'
18
+ THRESHOLD = 90.cs__freeze
19
+ WORTHWATCHING_THRESHOLD = 10.cs__freeze
20
+ include Contrast::Agent::Reporting::InputType
21
+ include Contrast::Agent::Reporting::ScoreLevel
22
+ include Contrast::Components::Logger::InstanceMethods
23
+
24
+ KEYS_NEEDED = [COOKIE_VALUE, PARAMETER_VALUE, JSON_VALUE, MULTIPART_VALUE, XML_VALUE, DWR_VALUE].cs__freeze
25
+
26
+ # Input Classification stage is done to determine if an user input is
27
+ # DEFINITEATTACK or to be ignored.
28
+ #
29
+ # @param rule_id [String] Name of the protect rule.
30
+ # @param input_type [Symbol, Contrast::Agent::Reporting::InputType] The type of the user input.
31
+ # @param value [String, Array<String>] the value of the input.
32
+ # @param input_analysis [Contrast::Agent::Reporting::InputAnalysis] Holds all the results from the
33
+ # agent analysis from the current
34
+ # Request.
35
+ # @return ia [Contrast::Agent::Reporting::InputAnalysis, nil] with updated results.
36
+ def classify rule_id, input_type, value, input_analysis
37
+ return unless (rule = Contrast::PROTECT.rule(rule_id))
38
+ return unless rule.applicable_user_inputs.include?(input_type)
39
+ return unless input_analysis.request
40
+
41
+ Array(value).each do |val|
42
+ Array(val).each do |v|
43
+ next unless v
44
+
45
+ result = create_new_input_result(input_analysis.request, rule.rule_name, input_type, v)
46
+ input_analysis.results << result unless result.nil?
47
+ end
48
+ end
49
+
50
+ input_analysis
51
+ rescue StandardError => e
52
+ logger.debug("An Error was recorded in the input classification of the #{ rule_id }")
53
+ logger.debug(e)
54
+ end
55
+
56
+ # Creates new isntance of InputAnalysisResult with basic info.
57
+ #
58
+ # @param rule_id [String] The name of the Protect Rule.
59
+ # @param input_type [Contrast::Agent::Reporting::InputType] The type of the user input.
60
+ # @param value [String, Array<String>] the value of the input.
61
+ # @param path [String] the path of the current request context.
62
+ #
63
+ # @return res [Contrast::Agent::Reporting::InputAnalysisResult]
64
+ def new_ia_result rule_id, input_type, path, value = nil
65
+ res = Contrast::Agent::Reporting::InputAnalysisResult.new
66
+ res.rule_id = rule_id
67
+ res.input_type = input_type
68
+ res.path = path
69
+ res.value = value
70
+ res
71
+ end
72
+
73
+ # This methods checks if input is value that matches a key in the input.
74
+ #
75
+ # @param request [Contrast::Agent::Request] the current request context.
76
+ # @param result [Contrast::Agent::Reporting::InputAnalysisResult] result to be updated.
77
+ # @param input_type [Contrast::Agent::Reporting::InputType] The type of the user input.
78
+ # @param value [String, Array<String>] the value of the input.
79
+ #
80
+ # @return result [Contrast::Agent::Reporting::InputAnalysisResult] updated with key result.
81
+ def add_needed_key request, result, input_type, value
82
+ case input_type
83
+ when COOKIE_VALUE
84
+ result.key = request.cookies.key(value)
85
+ when PARAMETER_VALUE, URL_PARAMETER
86
+ result.key = request.parameters.key(value)
87
+ when HEADER
88
+ result.key = request.headers.key(value)
89
+ when UNKNOWN
90
+ result.key = UNKNOWN_KEY
91
+ else
92
+ result.key
93
+ end
94
+ rescue StandardError => e
95
+ logger.warn('Could not find proper key for input traced value', message: e)
96
+ end
97
+
98
+ # Some input types are not yet supported from the AgentLib.
99
+ # This will convert the type to the closet possible if viable,
100
+ # so that the input tracing could be done.
101
+ #
102
+ # @param input_type [Contrast::Agent::Reporting::InputType] The type of the user input.
103
+ # @return [Integer<Contrast::AgentLib::Interface::INPUT_SET>]
104
+ def convert_input_type input_type
105
+ case input_type
106
+ when BODY, DWR_VALUE
107
+ Contrast::AGENT_LIB.input_set[:PARAMETER_VALUE]
108
+ when HEADER
109
+ Contrast::AGENT_LIB.input_set[:HEADER_VALUE]
110
+ when MULTIPART_VALUE, MULTIPART_FIELD_NAME
111
+ Contrast::AGENT_LIB.input_set[:MULTIPART_NAME]
112
+ else
113
+ Contrast::AGENT_LIB.input_set[input_type]
114
+ end
115
+ rescue StandardError
116
+ Contrast::AGENT_LIB.input_set[:PARAMETER_VALUE]
117
+ end
118
+
119
+ private
120
+
121
+ # This methods checks if input is tagged WORTHWATCHING or IGNORE matches value with it's
122
+ # key if needed and Creates new instance of InputAnalysisResult.
123
+ #
124
+ # @param request [Contrast::Agent::Request] the current request context.
125
+ # @param rule_id [String] The name of the Protect Rule.
126
+ # @param input_type [Contrast::Agent::Reporting::InputType] The type of the user input.
127
+ # @param value [String, Array<String>] the value of the input.
128
+ #
129
+ # @return res [Contrast::Agent::Reporting::InputAnalysisResult, nil]
130
+ def create_new_input_result request, rule_id, input_type, value
131
+ return unless Contrast::AGENT_LIB
132
+
133
+ input_eval = Contrast::AGENT_LIB.eval_input(value,
134
+ convert_input_type(input_type),
135
+ Contrast::AGENT_LIB.rule_set[rule_id],
136
+ Contrast::AGENT_LIB.
137
+ eval_option[:WORTHWATCHING])
138
+
139
+ ia_result = new_ia_result(rule_id, input_type, request.path, value)
140
+ score = input_eval&.score || 0
141
+ if score >= WORTHWATCHING_THRESHOLD
142
+ ia_result.score_level = WORTHWATCHING
143
+ ia_result.ids << self::WORTHWATCHING_MATCH
144
+ else
145
+ ia_result.score_level = IGNORE
146
+ return
147
+ end
148
+
149
+ add_needed_key(request, ia_result, input_type, value) if KEYS_NEEDED.include?(input_type)
150
+ ia_result
151
+ end
152
+ end
153
+ end
154
+ end
155
+ end
156
+ end
@@ -7,8 +7,8 @@ require 'contrast/components/scope'
7
7
 
8
8
  module Contrast
9
9
  module Utils
10
- # This utility allows us to report invalid configurations detected in
11
- # customer applications, as determined by Configuration Rules at runtime.
10
+ # This utility allows us to report invalid configurations detected in customer applications, as determined by
11
+ # Configuration Rules at runtime.
12
12
  module InvalidConfigurationUtil
13
13
  include Contrast::Components::Logger::InstanceMethods
14
14
  include Contrast::Components::Scope::InstanceMethods
@@ -20,64 +20,39 @@ module Contrast
20
20
  # Build and report a finding for the given rule
21
21
  #
22
22
  # @param rule_id [String] the rule that was violated by the configuration
23
- # @param user_provided_options [Hash] the configuration value(s) which
24
- # violated the rule
25
- # @param call_location [Thread::Backtrace::Location] the location where
26
- # the bad configuration was set
23
+ # @param user_provided_options [Hash] the configuration value(s) which violated the rule
24
+ # @param call_location [Thread::Backtrace::Location] the location where the bad configuration was set
27
25
  def cs__report_finding rule_id, user_provided_options, call_location
28
26
  with_contrast_scope do
29
- finding = Contrast::Api::Dtm::Finding.new
30
- finding.version = Contrast::Agent::Assess::Policy::TriggerMethod::CURRENT_FINDING_VERSION
31
- finding.rule_id = rule_id
32
- set_properties(finding, user_provided_options, call_location)
33
- hash = Contrast::Utils::HashDigest.generate_config_hash(finding)
34
- finding.hash_code = Contrast::Utils::StringUtils.force_utf8(hash)
35
- finding.preflight = Contrast::Utils::PreflightUtil.create_preflight(finding)
36
- if Contrast::Agent::Reporter.enabled? # TODO: RUBY-1438 -- remove
37
- cs__report_new_finding(hash, rule_id, user_provided_options, call_location)
38
- else
39
- Contrast::Agent::Assess::Policy::TriggerMethod.report_finding(finding)
40
- end
27
+ finding = build_finding(rule_id, user_provided_options, call_location)
28
+ return unless finding
29
+
30
+ Contrast::Agent::Assess::Policy::TriggerMethod.report_finding(finding)
41
31
  end
42
32
  rescue StandardError => e
43
33
  logger.error('Unable to build a finding', e, rule: rule_id)
44
34
  end
45
35
 
46
- def cs__report_new_finding hash_code, rule_id, user_provided_options, call_location
47
- new_preflight = Contrast::Agent::Reporting::Preflight.new
48
- new_preflight_message = Contrast::Agent::Reporting::PreflightMessage.new
49
- new_preflight_message.hash_code = hash_code
50
- new_preflight_message.data = "#{ rule_id },#{ hash_code }"
51
- new_preflight.messages << new_preflight_message
52
-
53
- ruby_finding = Contrast::Agent::Reporting::Finding.new(rule_id)
54
- ruby_finding.hash_code = hash_code
55
- set_new_finding_properties(ruby_finding, user_provided_options, call_location)
56
- Contrast::Agent.reporter&.send_event(new_preflight)
57
- Contrast::Agent::Reporting::ReportingStorage[hash_code] = ruby_finding
58
- end
59
-
60
36
  private
61
37
 
62
38
  # Set the properties needed to report and subsequently render this finding on the finding given.
63
39
  #
64
- # @param finding [Contrast::Api::Dtm::Finding] the configuration finding to populate
65
- # @param user_provided_options [Hash] the configuration value(s) which
66
- # violated the rule
67
- # @param call_location [Thread::Backtrace::Location] the location where
68
- # the bad configuration was set
69
- def set_properties finding, user_provided_options, call_location
70
- path = call_location.path
40
+ # @param rule_id [String] the rule that was violated by the configuration
41
+ # @param user_provided_options [Hash] the configuration value(s) which violated the rule
42
+ # @param call_location [Thread::Backtrace::Location] the location where the bad configuration was set
43
+ # @return [Contrast::Agent::Reporting::Finding]
44
+ def build_finding rule_id, user_provided_options, call_location
45
+ finding = Contrast::Agent::Reporting::Finding.new(rule_id)
46
+ finding.properties[CS__SESSION_ID] = user_provided_options[:key].to_s if user_provided_options
71
47
  # just get the file name, not the full path
72
- path = path.split(Contrast::Utils::ObjectShare::SLASH).last
73
- session_id = user_provided_options[:key].to_s if user_provided_options
74
- finding.properties[CS__SESSION_ID] = Contrast::Utils::StringUtils.force_utf8(session_id)
75
- finding.properties[CS__PATH] = Contrast::Utils::StringUtils.force_utf8(path)
76
- file_path = call_location.absolute_path
77
- snippet = file_snippet(file_path, call_location)
78
- finding.properties[CS__SNIPPET] = Contrast::Utils::StringUtils.force_utf8(snippet)
48
+ finding.properties[CS__PATH] = call_location.path.split(Contrast::Utils::ObjectShare::SLASH).last
49
+ finding.properties[CS__SNIPPET] = file_snippet(call_location.absolute_path, call_location)
50
+ finding.hash_code = Contrast::Utils::HashDigest.generate_config_hash(finding)
51
+ finding
79
52
  end
80
53
 
54
+ # @param file_path [String] full path to the file with the property
55
+ # @param call_location [Thread::Backtrace::Location] the location where the bad configuration was set
81
56
  def file_snippet file_path, call_location
82
57
  idx = call_location&.lineno
83
58
  if file_path && idx && File.exist?(file_path)
@@ -94,18 +69,6 @@ module Contrast
94
69
  end
95
70
  call_location&.label&.dup
96
71
  end
97
-
98
- def set_new_finding_properties finding, user_provided_options, call_location
99
- path = call_location.path
100
- # just get the file name, not the full path
101
- path = path.split(Contrast::Utils::ObjectShare::SLASH).last
102
- session_id = user_provided_options[:key].to_s if user_provided_options
103
- finding.properties[CS__SESSION_ID] = session_id
104
- finding.properties[CS__PATH] = path
105
- file_path = call_location.absolute_path
106
- snippet = file_snippet(file_path, call_location)
107
- finding.properties[CS__SNIPPET] = snippet
108
- end
109
72
  end
110
73
  end
111
74
  end