contrast-agent 3.13.0 → 3.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (241) hide show
  1. checksums.yaml +4 -4
  2. data/exe/contrast_service +1 -7
  3. data/ext/cs__assess_active_record_named/cs__active_record_named.c +8 -7
  4. data/ext/cs__assess_array/cs__assess_array.c +6 -5
  5. data/ext/cs__assess_basic_object/cs__assess_basic_object.c +5 -5
  6. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +2 -1
  7. data/ext/cs__assess_hash/cs__assess_hash.c +18 -17
  8. data/ext/cs__assess_hash/cs__assess_hash.h +2 -1
  9. data/ext/cs__assess_kernel/cs__assess_kernel.c +7 -8
  10. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +18 -16
  11. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.h +1 -0
  12. data/ext/cs__assess_module/cs__assess_module.c +6 -6
  13. data/ext/cs__assess_regexp/cs__assess_regexp.c +4 -4
  14. data/ext/cs__assess_string/cs__assess_string.c +31 -16
  15. data/ext/cs__assess_string/cs__assess_string.h +6 -1
  16. data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +4 -2
  17. data/ext/cs__assess_yield_track/cs__assess_yield_track.c +2 -2
  18. data/ext/cs__common/cs__common.c +48 -39
  19. data/ext/cs__common/cs__common.h +16 -21
  20. data/ext/cs__contrast_patch/cs__contrast_patch.c +27 -25
  21. data/ext/cs__contrast_patch/cs__contrast_patch.h +5 -7
  22. data/ext/cs__protect_kernel/cs__protect_kernel.c +11 -12
  23. data/ext/cs__protect_kernel/cs__protect_kernel.h +2 -2
  24. data/lib/contrast-agent.rb +1 -1
  25. data/lib/contrast.rb +13 -23
  26. data/lib/contrast/agent.rb +39 -46
  27. data/lib/contrast/agent/assess.rb +12 -12
  28. data/lib/contrast/agent/assess/contrast_event.rb +151 -85
  29. data/lib/contrast/agent/assess/events/event_factory.rb +2 -2
  30. data/lib/contrast/agent/assess/events/source_event.rb +3 -3
  31. data/lib/contrast/agent/assess/finalizers/freeze.rb +15 -0
  32. data/lib/contrast/agent/assess/finalizers/hash.rb +97 -0
  33. data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +11 -4
  34. data/lib/contrast/agent/assess/policy/patcher.rb +6 -6
  35. data/lib/contrast/agent/assess/policy/policy.rb +9 -11
  36. data/lib/contrast/agent/assess/policy/policy_node.rb +17 -12
  37. data/lib/contrast/agent/assess/policy/policy_scanner.rb +9 -4
  38. data/lib/contrast/agent/assess/policy/preshift.rb +13 -7
  39. data/lib/contrast/agent/assess/policy/propagation_method.rb +64 -44
  40. data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -2
  41. data/lib/contrast/agent/assess/policy/propagator.rb +18 -18
  42. data/lib/contrast/agent/assess/policy/propagator/append.rb +8 -5
  43. data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
  44. data/lib/contrast/agent/assess/policy/propagator/center.rb +9 -5
  45. data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
  46. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +6 -4
  47. data/lib/contrast/agent/assess/policy/propagator/insert.rb +7 -4
  48. data/lib/contrast/agent/assess/policy/propagator/keep.rb +4 -1
  49. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +7 -9
  50. data/lib/contrast/agent/assess/policy/propagator/next.rb +7 -5
  51. data/lib/contrast/agent/assess/policy/propagator/prepend.rb +13 -5
  52. data/lib/contrast/agent/assess/policy/propagator/remove.rb +8 -4
  53. data/lib/contrast/agent/assess/policy/propagator/replace.rb +5 -2
  54. data/lib/contrast/agent/assess/policy/propagator/reverse.rb +7 -5
  55. data/lib/contrast/agent/assess/policy/propagator/select.rb +13 -7
  56. data/lib/contrast/agent/assess/policy/propagator/splat.rb +10 -9
  57. data/lib/contrast/agent/assess/policy/propagator/split.rb +27 -22
  58. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +52 -35
  59. data/lib/contrast/agent/assess/policy/propagator/trim.rb +11 -5
  60. data/lib/contrast/agent/assess/policy/rewriter_patch.rb +5 -5
  61. data/lib/contrast/agent/assess/policy/source_method.rb +90 -72
  62. data/lib/contrast/agent/assess/policy/source_validation/cross_site_validator.rb +1 -1
  63. data/lib/contrast/agent/assess/policy/source_validation/source_validation.rb +1 -1
  64. data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +16 -12
  65. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +2 -2
  66. data/lib/contrast/agent/assess/policy/trigger_method.rb +81 -33
  67. data/lib/contrast/agent/assess/policy/trigger_node.rb +41 -46
  68. data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -1
  69. data/lib/contrast/agent/assess/policy/trigger_validation/trigger_validation.rb +2 -2
  70. data/lib/contrast/agent/assess/properties.rb +15 -5
  71. data/lib/contrast/agent/assess/property/evented.rb +7 -20
  72. data/lib/contrast/agent/assess/property/tagged.rb +13 -7
  73. data/lib/contrast/agent/assess/property/updated.rb +131 -0
  74. data/lib/contrast/agent/assess/rule.rb +2 -2
  75. data/lib/contrast/agent/assess/rule/base.rb +3 -4
  76. data/lib/contrast/agent/assess/rule/provider.rb +3 -3
  77. data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +58 -5
  78. data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +24 -9
  79. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +84 -16
  80. data/lib/contrast/agent/assess/tag.rb +1 -1
  81. data/lib/contrast/agent/assess/tracker.rb +66 -0
  82. data/lib/contrast/agent/at_exit_hook.rb +6 -6
  83. data/lib/contrast/agent/class_reopener.rb +14 -11
  84. data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +1 -1
  85. data/lib/contrast/agent/deadzone/policy/policy.rb +2 -2
  86. data/lib/contrast/agent/disable_reaction.rb +1 -1
  87. data/lib/contrast/agent/exclusion_matcher.rb +1 -1
  88. data/lib/contrast/agent/inventory/policy/datastores.rb +2 -2
  89. data/lib/contrast/agent/inventory/policy/policy.rb +3 -3
  90. data/lib/contrast/agent/inventory/policy/trigger_node.rb +1 -1
  91. data/lib/contrast/agent/middleware.rb +32 -32
  92. data/lib/contrast/agent/patching/policy/after_load_patch.rb +9 -9
  93. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +23 -22
  94. data/lib/contrast/agent/patching/policy/module_policy.rb +11 -11
  95. data/lib/contrast/agent/patching/policy/patch.rb +15 -15
  96. data/lib/contrast/agent/patching/policy/patcher.rb +43 -44
  97. data/lib/contrast/agent/patching/policy/policy.rb +23 -12
  98. data/lib/contrast/agent/patching/policy/policy_node.rb +1 -1
  99. data/lib/contrast/agent/patching/policy/trigger_node.rb +2 -2
  100. data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +6 -8
  101. data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +2 -2
  102. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -2
  103. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +3 -3
  104. data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +2 -2
  105. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +4 -4
  106. data/lib/contrast/agent/protect/policy/policy.rb +8 -8
  107. data/lib/contrast/agent/protect/policy/rule_applicator.rb +1 -1
  108. data/lib/contrast/agent/protect/policy/trigger_node.rb +1 -1
  109. data/lib/contrast/agent/protect/rule.rb +18 -18
  110. data/lib/contrast/agent/protect/rule/base.rb +4 -3
  111. data/lib/contrast/agent/protect/rule/base_service.rb +1 -1
  112. data/lib/contrast/agent/protect/rule/cmd_injection.rb +5 -5
  113. data/lib/contrast/agent/protect/rule/deserialization.rb +1 -1
  114. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +1 -1
  115. data/lib/contrast/agent/protect/rule/no_sqli.rb +1 -1
  116. data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +1 -0
  117. data/lib/contrast/agent/protect/rule/path_traversal.rb +4 -5
  118. data/lib/contrast/agent/protect/rule/sqli.rb +2 -2
  119. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +1 -1
  120. data/lib/contrast/agent/protect/rule/xss.rb +1 -1
  121. data/lib/contrast/agent/protect/rule/xxe.rb +3 -5
  122. data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +2 -2
  123. data/lib/contrast/agent/railtie.rb +1 -1
  124. data/lib/contrast/agent/reaction_processor.rb +2 -2
  125. data/lib/contrast/agent/request.rb +45 -43
  126. data/lib/contrast/agent/request_context.rb +10 -6
  127. data/lib/contrast/agent/response.rb +23 -12
  128. data/lib/contrast/agent/rewriter.rb +6 -9
  129. data/lib/contrast/agent/service_heartbeat.rb +2 -2
  130. data/lib/contrast/agent/static_analysis.rb +9 -9
  131. data/lib/contrast/agent/thread.rb +1 -1
  132. data/lib/contrast/agent/thread_watcher.rb +2 -2
  133. data/lib/contrast/agent/tracepoint_hook.rb +1 -1
  134. data/lib/contrast/agent/version.rb +1 -1
  135. data/lib/contrast/api.rb +4 -4
  136. data/lib/contrast/api/communication.rb +9 -9
  137. data/lib/contrast/api/communication/messaging_queue.rb +3 -6
  138. data/lib/contrast/api/communication/response_processor.rb +1 -1
  139. data/lib/contrast/api/communication/socket_client.rb +41 -6
  140. data/lib/contrast/api/communication/speedracer.rb +1 -1
  141. data/lib/contrast/api/communication/tcp_socket.rb +1 -1
  142. data/lib/contrast/api/communication/unix_socket.rb +1 -1
  143. data/lib/contrast/api/decorators.rb +14 -14
  144. data/lib/contrast/api/decorators/address.rb +20 -19
  145. data/lib/contrast/api/decorators/application_settings.rb +3 -2
  146. data/lib/contrast/api/decorators/application_update.rb +7 -8
  147. data/lib/contrast/api/decorators/http_request.rb +13 -12
  148. data/lib/contrast/api/decorators/input_analysis.rb +3 -2
  149. data/lib/contrast/api/decorators/message.rb +4 -2
  150. data/lib/contrast/api/decorators/rasp_rule_sample.rb +2 -1
  151. data/lib/contrast/api/decorators/route_coverage.rb +3 -2
  152. data/lib/contrast/api/decorators/server_features.rb +3 -2
  153. data/lib/contrast/api/decorators/trace_event.rb +28 -25
  154. data/lib/contrast/api/decorators/trace_event_object.rb +6 -5
  155. data/lib/contrast/api/decorators/trace_event_signature.rb +5 -4
  156. data/lib/contrast/api/decorators/trace_taint_range.rb +4 -3
  157. data/lib/contrast/api/decorators/user_input.rb +4 -4
  158. data/lib/contrast/common_agent_configuration.rb +2 -2
  159. data/lib/contrast/components/agent.rb +2 -2
  160. data/lib/contrast/components/app_context.rb +50 -39
  161. data/lib/contrast/components/config.rb +7 -17
  162. data/lib/contrast/components/contrast_service.rb +10 -10
  163. data/lib/contrast/components/interface.rb +15 -15
  164. data/lib/contrast/components/logger.rb +1 -1
  165. data/lib/contrast/components/scope.rb +3 -3
  166. data/lib/contrast/components/settings.rb +20 -23
  167. data/lib/contrast/config.rb +18 -18
  168. data/lib/contrast/config/application_configuration.rb +5 -2
  169. data/lib/contrast/config/base_configuration.rb +2 -2
  170. data/lib/contrast/config/protect_rule_configuration.rb +1 -1
  171. data/lib/contrast/config/service_configuration.rb +8 -0
  172. data/lib/contrast/configuration.rb +93 -52
  173. data/lib/contrast/extension/assess.rb +21 -22
  174. data/lib/contrast/extension/assess/array.rb +18 -11
  175. data/lib/contrast/extension/assess/erb.rb +11 -3
  176. data/lib/contrast/extension/assess/eval_trigger.rb +7 -7
  177. data/lib/contrast/extension/assess/exec_trigger.rb +2 -2
  178. data/lib/contrast/extension/assess/fiber.rb +14 -14
  179. data/lib/contrast/extension/assess/hash.rb +7 -6
  180. data/lib/contrast/extension/assess/kernel.rb +34 -28
  181. data/lib/contrast/extension/assess/marshal.rb +67 -0
  182. data/lib/contrast/extension/assess/regexp.rb +10 -9
  183. data/lib/contrast/extension/assess/string.rb +23 -23
  184. data/lib/contrast/extension/inventory.rb +4 -4
  185. data/lib/contrast/extension/kernel.rb +1 -1
  186. data/lib/contrast/extension/module.rb +1 -1
  187. data/lib/contrast/extension/protect.rb +3 -3
  188. data/lib/contrast/extension/protect/kernel.rb +4 -4
  189. data/lib/contrast/extension/protect/psych.rb +2 -2
  190. data/lib/contrast/framework/base_support.rb +1 -1
  191. data/lib/contrast/framework/manager.rb +10 -11
  192. data/lib/contrast/framework/rack/patch/session_cookie.rb +22 -28
  193. data/lib/contrast/framework/rack/patch/support.rb +1 -1
  194. data/lib/contrast/framework/rack/support.rb +2 -2
  195. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +13 -13
  196. data/lib/contrast/framework/rails/patch/assess_configuration.rb +6 -12
  197. data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +11 -11
  198. data/lib/contrast/framework/rails/patch/support.rb +4 -4
  199. data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +11 -11
  200. data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +12 -12
  201. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +4 -4
  202. data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +12 -12
  203. data/lib/contrast/framework/rails/support.rb +64 -14
  204. data/lib/contrast/framework/sinatra/patch/base.rb +12 -12
  205. data/lib/contrast/framework/sinatra/patch/support.rb +1 -1
  206. data/lib/contrast/framework/sinatra/support.rb +6 -6
  207. data/lib/contrast/funchook/funchook.rb +1 -1
  208. data/lib/contrast/logger/application.rb +13 -5
  209. data/lib/contrast/logger/format.rb +22 -9
  210. data/lib/contrast/logger/log.rb +17 -10
  211. data/lib/contrast/logger/request.rb +30 -0
  212. data/lib/contrast/tasks/config.rb +1 -1
  213. data/lib/contrast/tasks/service.rb +2 -2
  214. data/lib/contrast/utils/assess/sampling_util.rb +2 -2
  215. data/lib/contrast/utils/assess/tracking_util.rb +49 -4
  216. data/lib/contrast/utils/boolean_util.rb +1 -1
  217. data/lib/contrast/utils/class_util.rb +2 -2
  218. data/lib/contrast/utils/duck_utils.rb +0 -10
  219. data/lib/contrast/utils/env_configuration_item.rb +2 -1
  220. data/lib/contrast/utils/gemfile_reader.rb +5 -5
  221. data/lib/contrast/utils/hash_digest.rb +2 -1
  222. data/lib/contrast/utils/heap_dump_util.rb +2 -2
  223. data/lib/contrast/utils/invalid_configuration_util.rb +21 -22
  224. data/lib/contrast/utils/inventory_util.rb +4 -4
  225. data/lib/contrast/utils/io_util.rb +1 -1
  226. data/lib/contrast/utils/os.rb +1 -1
  227. data/lib/contrast/utils/ruby_ast_rewriter.rb +1 -1
  228. data/lib/contrast/utils/sha256_builder.rb +2 -2
  229. data/lib/contrast/utils/stack_trace_utils.rb +2 -2
  230. data/lib/contrast/utils/string_utils.rb +11 -6
  231. data/resources/assess/policy.json +31 -22
  232. data/resources/deadzone/policy.json +5 -0
  233. data/ruby-agent.gemspec +21 -19
  234. data/service_executables/VERSION +1 -1
  235. data/service_executables/linux/contrast-service +0 -0
  236. data/service_executables/mac/contrast-service +0 -0
  237. metadata +67 -29
  238. data/lib/contrast/agent/assess/insulator.rb +0 -49
  239. data/lib/contrast/agent/require_state.rb +0 -61
  240. data/lib/contrast/extension/assess/assess_extension.rb +0 -147
  241. data/lib/contrast/utils/freeze_util.rb +0 -32
@@ -1,12 +1,13 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/utils/string_utils'
4
+ require 'contrast/utils/string_utils'
5
5
 
6
6
  module Contrast
7
7
  module Api
8
8
  module Decorators
9
- # Used to decorate the ApplicationSettings protobuf model to handle setting translation
9
+ # Used to decorate the {Contrast::Api::Settings::ApplicationSettings}
10
+ # protobuf model to handle setting translation.
10
11
  module ApplicationSettings
11
12
  MODE_ALLOWLIST = [
12
13
  Contrast::Api::Settings::ProtectionRule::Mode::NO_ACTION,
@@ -1,14 +1,15 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/components/interface'
5
- cs__scoped_require 'contrast/utils/string_utils'
4
+ require 'contrast/components/interface'
5
+ require 'contrast/utils/string_utils'
6
6
 
7
7
  module Contrast
8
8
  module Api
9
9
  module Decorators
10
- # Used to decorate the ApplicationUpdate protobuf model so it can own some of the data massaging required for
11
- # AppUpdate dtm
10
+ # Used to decorate the {Contrast::Api::Dtm::ApplicationUpdate} protobuf
11
+ # model so it can own some of the data massaging required for AppUpdate
12
+ # dtm.
12
13
  module ApplicationUpdate
13
14
  include Contrast::Components::Interface
14
15
  access_component :config
@@ -17,10 +18,8 @@ module Contrast
17
18
  klass.extend(ClassMethods)
18
19
  end
19
20
 
20
- def append_library_update library_dtm_list, library_tags
21
- lib_tags = Contrast::Utils::StringUtils.protobuf_format(library_tags)
21
+ def append_library_update library_dtm_list
22
22
  library_dtm_list.each do |library_dtm|
23
- library_dtm.tags = lib_tags
24
23
  libraries[library_dtm.hash_code] = library_dtm
25
24
  end
26
25
  end
@@ -45,7 +44,7 @@ module Contrast
45
44
  msg = new
46
45
  msg.append_route_coverage_data(Contrast::Agent.framework_manager.find_route_discovery_data)
47
46
  msg.append_platform_version(Contrast::Agent.framework_manager.platform_version)
48
- msg.append_library_update(Contrast::Utils::GemfileReader.instance.library_pb_list, CONFIG.root.inventory.tags)
47
+ msg.append_library_update(Contrast::Utils::GemfileReader.instance.library_pb_list)
49
48
  msg
50
49
  end
51
50
  end
@@ -1,17 +1,18 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/api/dtm.pb'
5
- cs__scoped_require 'contrast/api/decorators/address'
6
- cs__scoped_require 'contrast/components/interface'
7
- cs__scoped_require 'contrast/utils/string_utils'
8
- cs__scoped_require 'contrast/utils/timer'
4
+ require 'contrast/api/dtm.pb'
5
+ require 'contrast/api/decorators/address'
6
+ require 'contrast/components/interface'
7
+ require 'contrast/utils/string_utils'
8
+ require 'contrast/utils/timer'
9
9
 
10
10
  module Contrast
11
11
  module Api
12
12
  module Decorators
13
- # Used to decorate the HttpRequest protobuf model so it can own some of
14
- # the data massaging required for Request dtm
13
+ # Used to decorate the {Contrast::Api::Dtm::HttpRequest} protobuf model
14
+ # so it can own some of the data massaging required for Request dtm. Only
15
+ # works as an extension of that class.
15
16
  module HttpRequest
16
17
  include Contrast::Components::Interface
17
18
  access_component :agent
@@ -24,7 +25,7 @@ module Contrast
24
25
 
25
26
  # Append the sender and receiver to self.
26
27
  #
27
- # @param request [Contrast::Api::Dtm::HttpRequest]
28
+ # @param request [Contrast::Agent::Request]
28
29
  def append_addresses request
29
30
  self.sender = Contrast::Api::Dtm::Address.build_sender(request)
30
31
  self.receiver = Contrast::Api::Dtm::Address.build_receiver
@@ -32,7 +33,7 @@ module Contrast
32
33
 
33
34
  # Append the connection to self.
34
35
  #
35
- # @param request [Contrast::Api::Dtm::HttpRequest]
36
+ # @param request [Contrast::Agent::Request]
36
37
  def append_connection request
37
38
  self.protocol = Contrast::Utils::StringUtils.force_utf8(request.scheme)
38
39
  self.version = '1.1' # currently not in rack request; hard-coding
@@ -43,7 +44,7 @@ module Contrast
43
44
  # Append the parameters to self, using the preferred
44
45
  # normalized_request_params field.
45
46
  #
46
- # @param request [Contrast::Api::Dtm::HttpRequest]
47
+ # @param request [Contrast::Agent::Request]
47
48
  def append_params request
48
49
  request.parameters.each do |k, v|
49
50
  append_pair(normalized_request_params, k, v)
@@ -53,7 +54,7 @@ module Contrast
53
54
  # Append the normalized headers to self, using the preferred
54
55
  # request_headers field.
55
56
  #
56
- # @param request [Contrast::Api::Dtm::HttpRequest]
57
+ # @param request [Contrast::Agent::Request]
57
58
  def append_headers request
58
59
  request.headers.each do |k, v|
59
60
  next unless k && v
@@ -72,7 +73,7 @@ module Contrast
72
73
  # Append the body to self, using the preferred
73
74
  # request_body_binary field.
74
75
  #
75
- # @param request [Contrast::Api::Dtm::HttpRequest]
76
+ # @param request [Contrast::Agent::Request]
76
77
  def append_body request
77
78
  self.document_type = Contrast::Utils::StringUtils.force_utf8(request.document_type)
78
79
 
@@ -1,12 +1,13 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/utils/string_utils'
4
+ require 'contrast/utils/string_utils'
5
5
 
6
6
  module Contrast
7
7
  module Api
8
8
  module Decorators
9
- # Used to decorate the InputAnalysis protobuf model so it can own the request which its data is for
9
+ # Used to decorate the {Contrast::Api::Settings::InputAnalysis} protobuf
10
+ # model so it can own the request which its data is for.
10
11
  module InputAnalysis
11
12
  attr_accessor :request
12
13
  end
@@ -1,12 +1,14 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/utils/string_utils'
4
+ require 'contrast/utils/object_share'
5
+ require 'contrast/utils/string_utils'
5
6
 
6
7
  module Contrast
7
8
  module Api
8
9
  module Decorators
9
- # Used to decorate the Message protobuf model so it can handle instance data massaging
10
+ # Used to decorate the {Contrast::Api::Dtm::Message} protobuf model so it
11
+ # can handle instance data massaging.
10
12
  module Message
11
13
  include Contrast::Components::Interface
12
14
  access_component :app_context, :logging
@@ -4,7 +4,8 @@
4
4
  module Contrast
5
5
  module Api
6
6
  module Decorators
7
- # Used to decorate the RaspRuleSample protobuf model
7
+ # Used to decorate the {Contrast::Api::Dtm::RaspRuleSample} protobuf
8
+ # model.
8
9
  module RaspRuleSample
9
10
  def self.included klass
10
11
  klass.extend(ClassMethods)
@@ -1,12 +1,13 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/utils/string_utils'
4
+ require 'contrast/utils/string_utils'
5
5
 
6
6
  module Contrast
7
7
  module Api
8
8
  module Decorators
9
- # Used to decorate the RouteCoverage protobuf model to handle conversion between framework route classes
9
+ # Used to decorate the {Contrast::Api::Dtm::RouteCoverage} protobuf model
10
+ # to handle conversion between framework route classes and the dtm.
10
11
  module RouteCoverage
11
12
  def self.included klass
12
13
  klass.extend(ClassMethods)
@@ -1,12 +1,13 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/utils/string_utils'
4
+ require 'contrast/utils/string_utils'
5
5
 
6
6
  module Contrast
7
7
  module Api
8
8
  module Decorators
9
- # Used to decorate the ServerFeatures protobuf model to handle setting translation
9
+ # Used to decorate the {Contrast::Api::Settings::ServerFeatures} protobuf
10
+ # model to handle setting translation to boolean values.
10
11
  module ServerFeatures
11
12
  # 'defend' is legacy for 'protect' in the dtm.
12
13
  def protect_enabled?
@@ -1,12 +1,13 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/utils/string_utils'
4
+ require 'contrast/utils/string_utils'
5
5
 
6
6
  module Contrast
7
7
  module Api
8
8
  module Decorators
9
- # Used to decorate the TraceEvent protobuf model
9
+ # Used to decorate the {Contrast::Api::Dtm::TraceEvent} protobuf model to
10
+ # convert our {Contrast::Agent::AssessContrastEvent} to the dtm.
10
11
  module TraceEvent
11
12
  def self.included klass
12
13
  klass.extend(ClassMethods)
@@ -31,25 +32,40 @@ module Contrast
31
32
 
32
33
  properties = case taint_target
33
34
  when Contrast::Utils::ObjectShare::OBJECT_KEY
34
- contrast_event.object.cs__properties
35
+ Contrast::Agent::Assess::Tracker.properties(contrast_event.object)
35
36
  when Contrast::Utils::ObjectShare::RETURN_KEY
36
- contrast_event.ret.cs__properties
37
+ Contrast::Agent::Assess::Tracker.properties(contrast_event.ret)
37
38
  else
38
39
  target = contrast_event.args[taint_target]
39
40
  if target.is_a?(Hash)
40
41
  if contrast_event.policy_node&.targets&.any?
41
- target[contrast_event.policy_node.targets[0]].cs__properties
42
+ Contrast::Agent::Assess::Tracker.properties(target[contrast_event.policy_node.targets[0]])
42
43
  else
43
- target[contrast_event.policy_node.sources[0]].cs__properties
44
+ Contrast::Agent::Assess::Tracker.properties(target[contrast_event.policy_node.sources[0]])
44
45
  end
45
46
  else
46
- target.cs__properties
47
+ Contrast::Agent::Assess::Tracker.properties(target)
47
48
  end
48
49
  end
50
+ return unless properties.tracked?
49
51
 
50
- return Contrast::Utils::ObjectShare::EMPTY_ARRAY unless properties.tracked?
52
+ self.taint_ranges += properties.tags_to_dtm
53
+ end
54
+
55
+ def build_parent_ids contrast_event
56
+ contrast_event&.parent_events&.each do |event|
57
+ next unless event
58
+
59
+ parent = Contrast::Api::Dtm::ParentObjectId.new
60
+ parent.id = event.event_id.to_i
61
+ parent_object_ids << parent
62
+ end
63
+ end
51
64
 
52
- properties.tags_to_dtm
65
+ def build_stack contrast_event
66
+ # We delayed doing this as long as possible b/c it's expensive
67
+ stack_dtms = Contrast::Utils::StackTraceUtils.build_assess_stack_array(contrast_event.stack_trace)
68
+ self.stack += stack_dtms
53
69
  end
54
70
 
55
71
  # Class methods for TraceEvent
@@ -70,23 +86,10 @@ module Contrast
70
86
  truncate_ret = Contrast::Utils::ObjectShare::RETURN_KEY != taint_target
71
87
  event_dtm.ret = Contrast::Api::Dtm::TraceEventObject.build(contrast_event.ret, truncate_ret)
72
88
  event_dtm.build_event_args(contrast_event, taint_target)
73
-
74
- taint_ranges = event_dtm.build_taint_ranges(contrast_event, taint_target)
75
- taint_ranges.each do |range|
76
- event_dtm.taint_ranges << range
77
- end
78
-
79
- # We delayed doing this as long as possible b/c it's expensive
80
- stack = Contrast::Utils::StackTraceUtils.build_assess_stack_array(contrast_event.stack_trace)
81
- event_dtm.stack += stack
82
-
89
+ event_dtm.build_parent_ids(contrast_event)
90
+ event_dtm.build_taint_ranges(contrast_event, taint_target)
91
+ event_dtm.build_stack(contrast_event)
83
92
  event_dtm.object_id = contrast_event.event_id.to_i
84
- contrast_event.parent_ids&.each do |id|
85
- parent = Contrast::Api::Dtm::ParentObjectId.new
86
- parent.id = id.to_i
87
- event_dtm.parent_object_ids << parent
88
- end
89
-
90
93
  event_dtm.signature = Contrast::Api::Dtm::TraceEventSignature.build(contrast_event.ret, contrast_event.policy_node, contrast_event.args)
91
94
  event_dtm
92
95
  end
@@ -1,15 +1,16 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/utils/string_utils'
5
- cs__scoped_require 'contrast/utils/assess/tracking_util'
6
- cs__scoped_require 'base64'
7
- cs__scoped_require 'contrast/components/interface'
4
+ require 'contrast/utils/string_utils'
5
+ require 'contrast/utils/assess/tracking_util'
6
+ require 'base64'
7
+ require 'contrast/components/interface'
8
8
 
9
9
  module Contrast
10
10
  module Api
11
11
  module Decorators
12
- # Used to decorate the TraceEventObject protobuf model
12
+ # Used to decorate the {Contrast::Api::Dtm::TraceEventObject} protobuf
13
+ # model.
13
14
  module TraceEventObject
14
15
  def self.included klass
15
16
  klass.extend(ClassMethods)
@@ -1,14 +1,15 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/utils/string_utils'
5
- cs__scoped_require 'contrast/utils/assess/tracking_util'
6
- cs__scoped_require 'base64'
4
+ require 'contrast/utils/string_utils'
5
+ require 'contrast/utils/assess/tracking_util'
6
+ require 'base64'
7
7
 
8
8
  module Contrast
9
9
  module Api
10
10
  module Decorators
11
- # Used to decorate the TraceEventSignature protobuf model
11
+ # Used to decorate the {Contrast::Api::Dtm::TraceEventSignature} protobuf
12
+ # model.
12
13
  module TraceEventSignature
13
14
  def self.included klass
14
15
  klass.extend(ClassMethods)
@@ -1,13 +1,14 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/utils/object_share'
5
- cs__scoped_require 'contrast/utils/string_utils'
4
+ require 'contrast/utils/object_share'
5
+ require 'contrast/utils/string_utils'
6
6
 
7
7
  module Contrast
8
8
  module Api
9
9
  module Decorators
10
- # Used to decorate the TraceTaintRange protobuf model
10
+ # Used to decorate the {Contrast::Api::Dtm::TraceTaintRange} protobuf
11
+ # model.
11
12
  module TraceTaintRange
12
13
  def self.included klass
13
14
  klass.extend(ClassMethods)
@@ -1,14 +1,14 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/utils/string_utils'
5
- cs__scoped_require 'contrast/utils/assess/tracking_util'
6
- cs__scoped_require 'base64'
4
+ require 'contrast/utils/string_utils'
5
+ require 'contrast/utils/assess/tracking_util'
6
+ require 'base64'
7
7
 
8
8
  module Contrast
9
9
  module Api
10
10
  module Decorators
11
- # Used to decorate the TraceEventObject protobuf model
11
+ # Used to decorate the {Contrast::Api::Dtm::UserInput} protobuf model.
12
12
  module UserInput
13
13
  UNKNOWN_USER_INPUT = Contrast::Api::Dtm::UserInput.new.tap do |user_input|
14
14
  user_input.input_type = :UNKNOWN
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- # rubocop:disable Style/MethodMissingSuper, Style/MissingRespondToMissing
4
+ # rubocop:disable Style/MissingRespondToMissing
5
5
  module Contrast
6
6
  # A wrapper build around the Common Agent Configuration project to allow for
7
7
  # access of the values contained in its parent_configuration_spec.yaml
@@ -83,4 +83,4 @@ module Contrast
83
83
  end
84
84
  end
85
85
  end
86
- # rubocop:enable Style/MethodMissingSuper, Style/MissingRespondToMissing
86
+ # rubocop:enable Style/MissingRespondToMissing
@@ -1,8 +1,8 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'rubygems/version'
5
- cs__scoped_require 'contrast/agent/rule_set'
4
+ require 'rubygems/version'
5
+ require 'contrast/agent/rule_set'
6
6
 
7
7
  module Contrast
8
8
  module Components
@@ -1,7 +1,8 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'rubygems/version'
4
+ require 'rubygems/version'
5
+ require 'contrast/utils/object_share'
5
6
 
6
7
  module Contrast
7
8
  module Components
@@ -15,7 +16,7 @@ module Contrast
15
16
  include Contrast::Components::ComponentBase
16
17
  include Contrast::Components::Interface
17
18
 
18
- access_component :agent, :config
19
+ access_component :agent, :analysis, :config, :logging
19
20
 
20
21
  DEFAULT_APP_NAME = 'rails'
21
22
  DEFAULT_APP_PATH = '/'
@@ -28,58 +29,57 @@ module Contrast
28
29
 
29
30
  def server_type
30
31
  @_server_type ||= begin
31
- tmp = CONFIG.root.server.type
32
- tmp = Contrast::Agent.framework_manager.server_type unless Contrast::Utils::StringUtils.present?(tmp)
33
- tmp
34
- end
32
+ tmp = CONFIG.root.server.type
33
+ tmp = Contrast::Agent.framework_manager.server_type unless Contrast::Utils::StringUtils.present?(tmp)
34
+ tmp
35
+ end
35
36
  end
36
37
 
37
38
  def name
38
39
  @_name ||= begin
39
- tmp = CONFIG.root.application.name
40
- tmp = Contrast::Agent.framework_manager.app_name unless Contrast::Utils::StringUtils.present?(tmp)
41
- tmp = File.basename(Dir.pwd) unless Contrast::Utils::StringUtils.present?(tmp)
42
- Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_APP_NAME)
43
- rescue StandardError
44
- DEFAULT_APP_NAME
45
- end
40
+ tmp = CONFIG.root.application.name
41
+ tmp = Contrast::Agent.framework_manager.app_name unless Contrast::Utils::StringUtils.present?(tmp)
42
+ tmp = File.basename(Dir.pwd) unless Contrast::Utils::StringUtils.present?(tmp)
43
+ Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_APP_NAME)
44
+ rescue StandardError
45
+ DEFAULT_APP_NAME
46
+ end
46
47
  end
47
48
 
48
49
  def path
49
50
  @_path ||= begin
50
- tmp = CONFIG.root.application.path
51
- Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_APP_PATH)
52
- rescue StandardError
53
- DEFAULT_APP_PATH
54
- end
51
+ tmp = CONFIG.root.application.path
52
+ Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_APP_PATH)
53
+ rescue StandardError
54
+ DEFAULT_APP_PATH
55
+ end
55
56
  end
56
57
 
57
58
  def server_name
58
59
  @_server_name ||= begin
59
- tmp = CONFIG.root.server.name
60
- tmp = Socket.gethostname unless Contrast::Utils::StringUtils.present?(tmp)
61
- tmp = Contrast::Utils::StringUtils.force_utf8(tmp)
62
- Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_SERVER_NAME)
63
- rescue StandardError
64
- DEFAULT_SERVER_NAME
65
- end
60
+ tmp = CONFIG.root.server.name
61
+ tmp = Socket.gethostname unless Contrast::Utils::StringUtils.present?(tmp)
62
+ tmp = Contrast::Utils::StringUtils.force_utf8(tmp)
63
+ Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_SERVER_NAME)
64
+ rescue StandardError
65
+ DEFAULT_SERVER_NAME
66
+ end
66
67
  end
67
68
 
68
69
  def server_path
69
70
  @_server_path ||= begin
70
- tmp = CONFIG.root.server.path
71
- tmp = Dir.pwd unless Contrast::Utils::StringUtils.present?(tmp)
72
- Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_SERVER_PATH)
73
- rescue StandardError
74
- DEFAULT_SERVER_PATH
75
- end
71
+ tmp = CONFIG.root.server.path
72
+ tmp = Dir.pwd unless Contrast::Utils::StringUtils.present?(tmp)
73
+ Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_SERVER_PATH)
74
+ rescue StandardError
75
+ DEFAULT_SERVER_PATH
76
+ end
76
77
  end
77
78
 
78
79
  def build_app_startup_message
79
80
  msg = Contrast::Api::Dtm::ApplicationCreate.new
80
81
 
81
82
  msg.group = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.group
82
- msg.tags = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.tags
83
83
  msg.app_version = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.version.to_s
84
84
  msg.code = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.code
85
85
  msg.metadata = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.metadata
@@ -92,13 +92,24 @@ module Contrast
92
92
 
93
93
  def build_agent_startup_message
94
94
  msg = Contrast::Api::Dtm::AgentStartup.new
95
- msg.server_name = Contrast::Utils::StringUtils.protobuf_format server_name
96
- msg.server_path = Contrast::Utils::StringUtils.protobuf_format server_path
97
- msg.server_type = Contrast::Utils::StringUtils.protobuf_format server_type
98
- msg.server_version = Contrast::Agent::VERSION
99
- msg.version = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server.version
100
- msg.environment = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server.environment
101
- msg.tags = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server.tags
95
+ msg.server_name = Contrast::Utils::StringUtils.protobuf_format server_name
96
+ msg.server_path = Contrast::Utils::StringUtils.protobuf_format server_path
97
+ msg.server_type = Contrast::Utils::StringUtils.protobuf_format server_type
98
+ msg.server_version = Contrast::Agent::VERSION
99
+ msg.version = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server.version
100
+ msg.environment = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server.environment
101
+ msg.server_tags = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server.tags
102
+ msg.application_tags = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.tags
103
+ msg.library_tags = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.inventory.tags
104
+ msg.finding_tags = Contrast::Utils::StringUtils.protobuf_format ASSESS.tags
105
+ logger.info('Application context',
106
+ server_name: msg.server_name,
107
+ server_path: msg.server_path,
108
+ server_type: msg.server_type,
109
+ application_name: name,
110
+ application_path: path,
111
+ application_language: Contrast::Utils::ObjectShare::RUBY)
112
+
102
113
  msg
103
114
  end
104
115