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
@@ -0,0 +1,36 @@
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/config/base_configuration'
5
+
6
+ module Contrast
7
+ module Components
8
+ # Common Configuration settings. Those in this section pertain to the
9
+ # disabled assess rule functionality of the Agent.
10
+ module AssessRules
11
+ class Interface # :nodoc:
12
+ include Contrast::Config::BaseConfiguration
13
+
14
+ SPEC_KEY = :disabled_rules.cs__freeze
15
+ # @return [Array, nil] list of disabled assess rules
16
+ attr_accessor :disabled_rules
17
+
18
+ def initialize hsh = {}
19
+ return unless hsh
20
+
21
+ @disabled_rules = cast_disabled_rules(hsh)
22
+ end
23
+
24
+ private
25
+
26
+ def cast_disabled_rules hsh
27
+ return unless hsh
28
+ return unless hsh.key?(SPEC_KEY)
29
+ return hsh[SPEC_KEY] if hsh[SPEC_KEY].cs__is_a?(Array)
30
+
31
+ hsh[SPEC_KEY].split(',').map(&:strip) if hsh[SPEC_KEY].cs__is_a?(String)
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -34,6 +34,9 @@ module Contrast
34
34
  API_KEY = "Invalid configuration. Missing a required connection value 'api_key' is not set."
35
35
  API_SERVICE_KEY = "Invalid configuration. Missing a required connection value 'service_tag' is not set."
36
36
  API_USERNAME = "Invalid configuration. Missing a required connection value 'user_name' is not set."
37
+
38
+ attr_reader :config
39
+
37
40
  def initialize
38
41
  build
39
42
  end
@@ -62,9 +65,39 @@ module Contrast
62
65
  end
63
66
  alias_method :rebuild, :build
64
67
 
65
- # @return [Contrast::Config::RootConfiguration]
66
- def root
67
- @config.root
68
+ # @return [Contrast::Components::Api::Interface]
69
+ def api
70
+ @config.api
71
+ end
72
+
73
+ # @return [Contrast::Components::Agent::Interface]
74
+ def agent
75
+ @config.agent
76
+ end
77
+
78
+ # @return [Contrast::Components::AppContext::Interface]
79
+ def application
80
+ @config.application
81
+ end
82
+
83
+ # @return [Contrast::Config::ServerConfiguration]
84
+ def server
85
+ @config.server
86
+ end
87
+
88
+ # @return [Contrast::Components::Assess::Interface]
89
+ def assess
90
+ @config.assess
91
+ end
92
+
93
+ # @return [Contrast::Components::Inventory::Interface]
94
+ def inventory
95
+ @config.inventory
96
+ end
97
+
98
+ # @return [Contrast::Components::Protect::Interface]
99
+ def protect
100
+ @config.protect
68
101
  end
69
102
 
70
103
  def valid?
@@ -72,6 +105,10 @@ module Contrast
72
105
  @_valid
73
106
  end
74
107
 
108
+ def enable
109
+ @config.enable
110
+ end
111
+
75
112
  def invalid?
76
113
  !valid?
77
114
  end
@@ -85,12 +122,12 @@ module Contrast
85
122
  #
86
123
  # @return [String,nil] the value of the session id set in the configuration, or nil if unset
87
124
  def session_id
88
- root.application.session_id
125
+ application.session_id
89
126
  end
90
127
 
91
128
  # @return [String,nil] the value of the session metadata set in the configuration, or nil if unset
92
129
  def session_metadata
93
- root.application.session_metadata
130
+ application.session_metadata
94
131
  end
95
132
 
96
133
  private
@@ -115,13 +152,10 @@ module Contrast
115
152
  true
116
153
  end
117
154
 
118
- # If the agent is to use the bypass to communicate with TeamServer directly, than it must have the
119
- # configuration values required for that connection.
155
+ # The agent must have the configuration values required for the connection to TeamServer.
120
156
  #
121
157
  # @return [boolean]
122
158
  def valid_api?
123
- return true unless bypass
124
-
125
159
  msg = []
126
160
  msg << API_URL unless api_url
127
161
  msg << API_KEY unless api_key
@@ -138,7 +172,7 @@ module Contrast
138
172
  next unless env_key.to_s.start_with?(CONTRAST_ENV_MARKER)
139
173
 
140
174
  config_item = Contrast::Utils::EnvConfigurationItem.new(env_key, env_value)
141
- assign_value_to_path_array(root, config_item.dot_path_array, config_item.value)
175
+ assign_value_to_path_array(self, config_item.dot_path_array, config_item.value)
142
176
  end
143
177
  end
144
178
 
@@ -148,7 +182,7 @@ module Contrast
148
182
  #
149
183
  # @return [String, nil]
150
184
  def api_url
151
- root.api.url
185
+ api.url
152
186
  end
153
187
 
154
188
  # Typically, the following values would be accessed through Contrast::Components::AppContext
@@ -157,7 +191,7 @@ module Contrast
157
191
  #
158
192
  # @return [String, nil]
159
193
  def api_key
160
- root.api.api_key
194
+ api.api_key
161
195
  end
162
196
 
163
197
  # Typically, the following values would be accessed through Contrast::Components::AppContext
@@ -166,7 +200,7 @@ module Contrast
166
200
  #
167
201
  # @return [String, nil]
168
202
  def api_service_key
169
- root.api.service_key
203
+ api.service_key
170
204
  end
171
205
 
172
206
  # Typically, the following values would be accessed through Contrast::Components::AppContext
@@ -175,16 +209,7 @@ module Contrast
175
209
  #
176
210
  # @return [String, nil]
177
211
  def api_username
178
- root.api.user_name
179
- end
180
-
181
- # Typically, the following values would be accessed through Contrast::Components::AppContext
182
- # and Contrast::Components::API, but we're too early in the initialization of the Agent to use
183
- # that mechanism, so we look it up directly for ourselves.
184
- #
185
- # @return [String, nil]
186
- def bypass
187
- root.agent.service.bypass
212
+ api.user_name
188
213
  end
189
214
 
190
215
  # Typically, the following values would be accessed through Contrast::Components::AppContext
@@ -193,7 +218,7 @@ module Contrast
193
218
  #
194
219
  # @return [String, nil]
195
220
  def logger_path
196
- root.agent.logger.path
221
+ agent.logger.path
197
222
  end
198
223
 
199
224
  # Assign the value from an ENV variable to the Contrast::Config::RootConfiguration object, when
@@ -71,7 +71,7 @@ module Contrast
71
71
 
72
72
  def heap_dump_control
73
73
  @_heap_dump_control ||= begin
74
- config = ::Contrast::CONFIG.root&.agent&.heap_dump
74
+ config = ::Contrast::CONFIG&.agent&.heap_dump
75
75
  {
76
76
  enabled: true?(config&.enable),
77
77
  path: File.absolute_path(config&.path),
@@ -16,6 +16,8 @@ module Contrast
16
16
 
17
17
  # @return [Boolean, nil]
18
18
  attr_accessor :enable
19
+ # @return [Boolean, nil]
20
+ attr_accessor :agent_lib
19
21
 
20
22
  def initialize hsh = {}
21
23
  return unless hsh
@@ -23,6 +25,7 @@ module Contrast
23
25
  @_exceptions = Contrast::Config::ExceptionConfiguration.new(hsh[:exceptions])
24
26
  @_rules = Contrast::Config::ProtectRulesConfiguration.new(hsh[:rules])
25
27
  @enable = hsh[:enable]
28
+ @agent_lib = hsh[:agent_lib]
26
29
  end
27
30
 
28
31
  # @return [Contrast::Config::ExceptionConfiguration]
@@ -31,7 +34,7 @@ module Contrast
31
34
  end
32
35
 
33
36
  # Name is kept the same - rules to correspond to config,
34
- # mapping. - root.protect.rules
37
+ # mapping. - protect.rules
35
38
  #
36
39
  # @return [Contrast::Config::ProtectRulesConfiguration]
37
40
  def rules
@@ -55,7 +58,7 @@ module Contrast
55
58
  end
56
59
 
57
60
  def rule_config
58
- ::Contrast::CONFIG.root.protect.rules
61
+ ::Contrast::CONFIG.protect.rules
59
62
  end
60
63
 
61
64
  # Returns Protect array of all initialized
@@ -69,9 +72,9 @@ module Contrast
69
72
 
70
73
  def rule_mode rule_id
71
74
  str = rule_id.tr('-', '_')
72
- ::Contrast::CONFIG.root.protect.rules[str]&.applicable_mode ||
75
+ ::Contrast::CONFIG.protect.rules[str]&.applicable_mode ||
73
76
  ::Contrast::SETTINGS.application_state.modes_by_id[rule_id] ||
74
- Contrast::Api::Settings::ProtectionRule::Mode::NO_ACTION
77
+ :NO_ACTION
75
78
  end
76
79
 
77
80
  def rule name
@@ -98,7 +101,7 @@ module Contrast
98
101
  def forcibly_disabled?
99
102
  return @_forcibly_disabled unless @_forcibly_disabled.nil?
100
103
 
101
- @_forcibly_disabled = false?(::Contrast::CONFIG.root.protect.enable)
104
+ @_forcibly_disabled = false?(::Contrast::CONFIG.protect.enable)
102
105
  end
103
106
 
104
107
  private
@@ -106,7 +109,7 @@ module Contrast
106
109
  def forcibly_enabled?
107
110
  return @_forcibly_enabled unless @_forcibly_enabled.nil?
108
111
 
109
- @_forcibly_enabled ||= true?(::Contrast::CONFIG.root.protect.enable)
112
+ @_forcibly_enabled ||= true?(::Contrast::CONFIG.protect.enable)
110
113
  end
111
114
  end
112
115
  end
@@ -0,0 +1,81 @@
1
+ # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
+ # frozen_string_literal: true
3
+
4
+ module Contrast
5
+ module Components
6
+ module Ruby
7
+ # A wrapper build around the Common Agent Configuration project to allow
8
+ # for access of the values contained in its
9
+ # parent_configuration_spec.yaml.
10
+ # Those in this section pertain to the specific settings that apply to Ruby
11
+ class Interface
12
+ include Contrast::Components::ComponentBase
13
+
14
+ DISABLED_RAKE_TASK_LIST = %w[
15
+ about assets:clean assets:clobber assets:environment
16
+ assets:precompile assets:precompile:all db:create db:drop db:fixtures:load db:migrate
17
+ db:migrate:status db:rollback db:schema:cache:clear db:schema:cache:dump db:schema:dump
18
+ db:schema:load db:seed db:setup db:structure:dump db:version doc:app graphql:install graphql:object
19
+ log:clear middleware notes notes:custom rails:template rails:update routes secret spec spec:features
20
+ spec:requests spec:controllers spec:helpers spec:models spec:views spec:routing spec:rcov stats
21
+ test test:all test:all:db test:recent test:single test:uncommitted time:zones:all tmp:clear
22
+ tmp:create webpacker:compile
23
+ ].cs__freeze
24
+
25
+ DEFAULT_UNINSTRUMENTED_NAMESPACES = %w[FactoryGirl FactoryBot].cs__freeze
26
+
27
+ attr_writer :disabled_agent_rake_tasks, :exceptions, :propagate_yield, :require_scan,
28
+ :non_request_tracking, :uninstrument_namespace
29
+
30
+ def initialize hsh = {}
31
+ return unless hsh
32
+
33
+ @disabled_agent_rake_tasks = hsh[:disabled_agent_rake_tasks]
34
+ @exceptions = Contrast::Config::ExceptionConfiguration.new(hsh[:exceptions])
35
+ @propagate_yield = hsh[:propagate_yield]
36
+ @require_scan = hsh[:require_scan]
37
+ @non_request_tracking = hsh[:non_request_tracking]
38
+ @uninstrument_namespace = hsh[:uninstrument_namespace]
39
+ end
40
+
41
+ # These commands being detected will result the agent disabling instrumentation, generally any command
42
+ # that doesn't result in the application listening on a port can be added here, this normally includes tasks
43
+ # that are ran pre-startup(like migrations) or to show information about the application(such as routes)
44
+ # @return [Array, DISABLED_RAKE_TASK_LIST]
45
+ def disabled_agent_rake_tasks
46
+ @disabled_agent_rake_tasks.nil? ? DISABLED_RAKE_TASK_LIST : @disabled_agent_rake_tasks
47
+ end
48
+
49
+ # rubocop:disable Naming/MemoizedInstanceVariableName
50
+ # @return [Contrast::Config::ExceptionConfiguration]
51
+ def exceptions
52
+ @exceptions ||= Contrast::Config::ExceptionConfiguration.new
53
+ end
54
+ # rubocop:enable Naming/MemoizedInstanceVariableName
55
+
56
+ # controls whether or not we patch the rb_yield block to track split propagation
57
+ # @return [Boolean, Contrast::Utils::ObjectShare::TRUE]
58
+ def propagate_yield
59
+ @propagate_yield.nil? ? Contrast::Utils::ObjectShare::TRUE : @propagate_yield
60
+ end
61
+
62
+ # control whether or not we run file scanning rules on require
63
+ # @return [Boolean, Contrast::Utils::ObjectShare::TRUE]
64
+ def require_scan
65
+ @require_scan.nil? ? Contrast::Utils::ObjectShare::TRUE : @require_scan
66
+ end
67
+
68
+ # controls tracking outside of request
69
+ # @return [Boolean, Contrast::Utils::ObjectShare::FALSE]
70
+ def non_request_tracking
71
+ @non_request_tracking.nil? ? Contrast::Utils::ObjectShare::FALSE : @non_request_tracking
72
+ end
73
+
74
+ # @return [Array, DEFAULT_UNINSTRUMENTED_NAMESPACES]
75
+ def uninstrument_namespace
76
+ @uninstrument_namespace.nil? ? DEFAULT_UNINSTRUMENTED_NAMESPACES : @uninstrument_namespace
77
+ end
78
+ end
79
+ end
80
+ end
81
+ end
@@ -24,7 +24,7 @@ module Contrast
24
24
 
25
25
  def sampling_control
26
26
  @_sampling_control ||= begin
27
- config_settings = ::Contrast::CONFIG.root.assess&.sampling
27
+ config_settings = ::Contrast::CONFIG.assess&.sampling
28
28
  settings = ::Contrast::SETTINGS&.assess_state&.sampling_settings
29
29
  {
30
30
  enabled: enabled?(config_settings, settings),
@@ -0,0 +1,23 @@
1
+ # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
+ # frozen_string_literal: true
3
+
4
+ module Contrast
5
+ module Components
6
+ module SecurityLogger
7
+ # Here we will read and store the setting for the CEF Logging functionality
8
+ class Interface
9
+ # @return [String, nil]
10
+ attr_accessor :path
11
+ # @return [String, nil]
12
+ attr_accessor :level
13
+
14
+ def initialize hsh = {}
15
+ return unless hsh
16
+
17
+ @path = hsh[:path]
18
+ @level = hsh[:level]
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,8 +1,9 @@
1
1
  # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'contrast/api/settings.pb'
4
+ require 'contrast/agent/excluder'
5
5
  require 'contrast/agent/reporting/settings/sensitive_data_masking'
6
+ require 'contrast/components/config'
6
7
 
7
8
  module Contrast
8
9
  module Components
@@ -11,8 +12,7 @@ module Contrast
11
12
  # directives (likely provided by TeamServer) about product operation.
12
13
  # 'Settings' is not a generic term for 'configurable stuff'.
13
14
  module Settings
14
- APPLICATION_STATE_BASE = Struct.new(:modes_by_id, :exclusion_matchers).
15
- new(Hash.new(Contrast::Api::Settings::ProtectionRule::Mode::NO_ACTION), [])
15
+ APPLICATION_STATE_BASE = Struct.new(:modes_by_id).new(Hash.new(:NO_ACTION))
16
16
  PROTECT_STATE_BASE = Struct.new(:enabled, :rules).new(false, {})
17
17
  ASSESS_STATE_BASE = Struct.new(:enabled, :sampling_settings, :disabled_assess_rules, :session_id).new(false, nil,
18
18
  [], nil) do
@@ -53,30 +53,6 @@ module Contrast
53
53
  # Current Application State.
54
54
  #
55
55
  # modes_by_id [Hash<Rule_id => Mode] Returns Hash with rules and their current mode.
56
- # exclusion_matchers [Array] Array of all the exclusions.
57
- # code_exclusions [Array<CodeExclusion>] Array of CodeExclusion: {
58
- # name [String] The name of the exclusion as defined by the user in TS.
59
- # modes [String] If this exclusion applies to assess or protect. [assess, defend]
60
- # assess_rules [Array] Array of assess rules to which this exclusion applies. AssessRuleID [String]
61
- # denylist [String] The call, if in the stack, should result in the agent not taking action.
62
- # input_exclusions [Array<InputExclusions>] Array of InputExclusions: {
63
- # name [String] The name of the input.
64
- # modes [String] If this exclusion applies to assess or protect. [assess, defend]
65
- # assess_rules [Array] Array of assess rules to which this exclusion applies. AssessRuleID [String]
66
- # protect_rules [Array] Array of ProtectRuleID [String] The protect rules to which this exclusion applies.
67
- # urls [Array] Array of URLs to which the exclusions apply. URL [String]
68
- # match_strategy [String] If this exclusion applies to all URLs or only those specified. [ALL, ONLY]
69
- # type [String] The type of the input [COOKIE, PARAMETER, HEADER, BODY, QUERYSTRING]
70
- # }
71
- # url_exclusions [Array<UrlExclusions>] Array of UrlExclusions: {
72
- # name [String] The name of the input.
73
- # modes [String] If this exclusion applies to assess or protect. [assess, defend]
74
- # assess_rules [Array] Array of assess rules to which this exclusion applies. AssessRuleID [String]
75
- # protect_rules [Array] Array of ProtectRuleID [String] The protect rules to which this exclusion applies.
76
- # urls [Array] Array of URLs to which the exclusions apply. URL [String]
77
- # match_strategy [String] If this exclusion applies to all URLs or only those specified. [ALL, ONLY]
78
- # type [String] The type of the input [COOKIE, PARAMETER, HEADER, BODY, QUERYSTRING]
79
- # }
80
56
  attr_reader :application_state
81
57
  # This the structure that will hold the masking rules send from TS.
82
58
  #
@@ -90,39 +66,40 @@ module Contrast
90
66
  attr_reader :last_app_update_ms
91
67
  # @return [Integer] the time, in ms, that server settings last changed
92
68
  attr_reader :last_server_update_ms
69
+ # @return [Contrast::Agent::Excluder] a wrapper around the exclusion rules for the application
70
+ attr_reader :excluder
93
71
 
94
72
  def initialize
95
73
  reset_state
96
74
  end
97
75
 
98
76
  def code_exclusions
99
- @application_state.exclusion_matchers.select(&:code?)
77
+ excluder&.exclusions&.select(&:code?)
100
78
  end
101
79
 
102
- # @param features_response [Contrast::Api::Settings::ServerFeatures, Contrast::Agent::Reporting::Response]
80
+ # @param features_response [Contrast::Agent::Reporting::Response]
103
81
  def update_from_server_features features_response
104
- if features_response.cs__is_a?(Contrast::Agent::Reporting::Response)
105
- update_from_response(features_response)
106
- else
107
- @protect_state.enabled = features_response.protect_enabled?
108
- @assess_state.enabled = features_response.assess_enabled?
109
- @assess_state.sampling_settings = features_response.assess.sampling
110
- @last_server_update_ms = Contrast::Utils::Timer.now_ms
111
- end
82
+ return unless (server_features = features_response&.server_features)
83
+
84
+ log_file = server_features.log_file
85
+ log_level = server_features.log_level
86
+ Contrast::Logger::Log.instance.update(log_file, log_level) if log_file || log_level
87
+ @protect_state.enabled = server_features.protect.enabled?
88
+ @assess_state.enabled = server_features.assess.enabled?
89
+ @assess_state.sampling_settings = server_features.assess.sampling
112
90
  @last_server_update_ms = Contrast::Utils::Timer.now_ms
113
91
  end
114
92
 
115
- # @param settings_response [Contrast::Api::Settings::ApplicationSettings, Contrast::Agent::Reporting::Response]
93
+ # @param settings_response [Contrast::Agent::Reporting::Response]
116
94
  def update_from_application_settings settings_response
117
- if settings_response&.cs__class == Contrast::Agent::Reporting::Response
118
- update_from_response(settings_response)
119
- else
120
- new_vals = settings_response.application_state_translation
121
- @application_state.modes_by_id = new_vals[:modes_by_id]
122
- @application_state.exclusion_matchers = new_vals[:exclusion_matchers]
123
- @assess_state.disabled_assess_rules = new_vals[:disabled_assess_rules]
124
- @last_app_update_ms = Contrast::Utils::Timer.now_ms
125
- end
95
+ return unless (app_settings = settings_response&.application_settings)
96
+
97
+ @application_state.modes_by_id = app_settings.protect.protection_rules_to_settings_hash
98
+ update_exclusion_matchers(app_settings.exclusions)
99
+ update_sensitive_data_policy(app_settings.sensitive_data_masking)
100
+ @assess_state.disabled_assess_rules = app_settings.assess.disabled_rules
101
+ new_session_id = app_settings.assess.session_id
102
+ @assess_state.session_id = new_session_id if new_session_id && !new_session_id.blank?
126
103
  @last_app_update_ms = Contrast::Utils::Timer.now_ms
127
104
  end
128
105
 
@@ -133,12 +110,14 @@ module Contrast
133
110
  @application_state = APPLICATION_STATE_BASE.dup
134
111
  @tainted_columns = {}
135
112
  @sensitive_data_masking = SENSITIVE_DATA_MASKING_BASE.dup
113
+ @excluder = Contrast::Agent::Excluder.new
136
114
  end
137
115
 
138
116
  def build_protect_rules
139
117
  @protect_state.rules = {}
140
118
 
141
119
  # Rules. They add themselves on initialize.
120
+ Contrast::Agent::Protect::Rule::BotBlocker.new
142
121
  Contrast::Agent::Protect::Rule::CmdInjection.new
143
122
  Contrast::Agent::Protect::Rule::Deserialization.new
144
123
  Contrast::Agent::Protect::Rule::HttpMethodTampering.new
@@ -150,6 +129,21 @@ module Contrast
150
129
  Contrast::Agent::Protect::Rule::Xxe.new
151
130
  end
152
131
 
132
+ # @param exclusions [Contrast::Agent::Reporting::Settings::Exclusions]
133
+ def update_exclusion_matchers exclusions
134
+ matchers = []
135
+ exclusions.url_exclusions.each do |exclusion|
136
+ matchers << Contrast::Agent::ExclusionMatcher.new(exclusion)
137
+ end
138
+ exclusions.input_exclusions.each do |exclusion|
139
+ matchers << Contrast::Agent::ExclusionMatcher.new(exclusion)
140
+ end
141
+ exclusions.code_exclusions.each do |exclusion|
142
+ matchers << Contrast::Agent::ExclusionMatcher.new(exclusion)
143
+ end
144
+ @excluder = Contrast::Agent::Excluder.new(matchers)
145
+ end
146
+
153
147
  # Update the sensitive data masking policy from settings,
154
148
  # received from TS. In case the settings are empty,
155
149
  # keep current ones.
@@ -170,44 +164,6 @@ module Contrast
170
164
 
171
165
  private
172
166
 
173
- # @param response [Contrast::Agent::Reporting::Response]
174
- def update_from_response response
175
- if (server_features = response.server_features)
176
- update_server_features(server_features)
177
- end
178
- return unless (app_settings = response.application_settings)
179
-
180
- update_application_settings(app_settings)
181
- end
182
-
183
- # @param server_features [Contrast::Agent::Reporting::Settings::FeatureSettings]
184
- def update_server_features server_features
185
- return unless server_features
186
-
187
- log_file = server_features.log_file
188
- log_level = server_features.log_level
189
- Contrast::Logger::Log.instance.update(log_file, log_level) if log_file || log_level
190
- @protect_state.enabled = server_features.protect.enabled?
191
- @assess_state.enabled = server_features.assess.enabled?
192
- @assess_state.sampling_settings = server_features.assess.sampling
193
- @last_server_update_ms = Contrast::Utils::Timer.now_ms
194
- end
195
-
196
- # @param app_settings [Contrast::Agent::Reporting::Settings::ApplicationSettings]
197
- def update_application_settings app_settings
198
- return unless app_settings
199
-
200
- @application_state.modes_by_id = app_settings.protect.protection_rules_to_settings_hash
201
- # TODO: RUBY-1438 this needs to be translated
202
- # @application_state.exclusion_matchers = new_vals[:exclusion_matchers]
203
- update_sensitive_data_policy(app_settings.sensitive_data_masking)
204
- @assess_state.disabled_assess_rules = app_settings.assess.disabled_rules
205
- if app_settings.assess.session_id && !app_settings.assess.session_id.blank?
206
- @assess_state.session_id = app_settings.assess.session_id
207
- end
208
- @last_app_update_ms = Contrast::Utils::Timer.now_ms
209
- end
210
-
211
167
  # check if settings are empty and return true if so.
212
168
  #
213
169
  # @param settings [String, Boolean, Array, Hash]
@@ -12,7 +12,7 @@ module Contrast
12
12
  extend Forwardable
13
13
  AT_UNDERSCORE = '@_'
14
14
 
15
- def to_hash
15
+ def to_contrast_hash
16
16
  hsh = {}
17
17
  instance_variables.each do |iv|
18
18
  # strip the '@' of '@_' to get the key
@@ -33,24 +33,24 @@ module Contrast
33
33
  end
34
34
 
35
35
  # To convert the user input mode from config to a standard format used by TS & SR, we need to convert the given
36
- # String to its Contrast::Api::Settings::ProtectionRule::Mode equivalent. If a nonsense value is provided, it'll
36
+ # String to its recognized symbol equivalent. If a nonsense value is provided, it'll
37
37
  # be treated the same as disabling the rule.
38
38
  #
39
- # @return [Contrast::Api::Settings::ProtectionRule::Mode, nil]
39
+ # @return [Symbol]
40
40
  def applicable_mode
41
41
  return unless mode
42
42
 
43
43
  case mode
44
44
  when 'permit'
45
- Contrast::Api::Settings::ProtectionRule::Mode::PERMIT
45
+ :PERMIT
46
46
  when 'block_at_perimeter'
47
- Contrast::Api::Settings::ProtectionRule::Mode::BLOCK_AT_PERIMETER
47
+ :BLOCK_AT_PERIMETER
48
48
  when 'block'
49
- Contrast::Api::Settings::ProtectionRule::Mode::BLOCK
49
+ :BLOCK
50
50
  when 'monitor'
51
- Contrast::Api::Settings::ProtectionRule::Mode::MONITOR
51
+ :MONITOR
52
52
  else
53
- Contrast::Api::Settings::ProtectionRule::Mode::NO_ACTION
53
+ :NO_ACTION
54
54
  end
55
55
  end
56
56
  end