contrast-agent 4.6.0 → 4.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -1
  3. data/.gitmodules +1 -1
  4. data/.simplecov +1 -0
  5. data/Rakefile +1 -2
  6. data/ext/build_funchook.rb +3 -3
  7. data/ext/extconf_common.rb +1 -5
  8. data/lib/contrast.rb +24 -14
  9. data/lib/contrast/agent/assess.rb +1 -1
  10. data/lib/contrast/agent/assess/contrast_event.rb +1 -4
  11. data/lib/contrast/agent/assess/contrast_object.rb +2 -2
  12. data/lib/contrast/agent/assess/events/event_factory.rb +2 -1
  13. data/lib/contrast/agent/assess/finalizers/hash.rb +2 -4
  14. data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +6 -3
  15. data/lib/contrast/agent/assess/policy/patcher.rb +16 -21
  16. data/lib/contrast/agent/assess/policy/policy.rb +1 -1
  17. data/lib/contrast/agent/assess/policy/policy_node.rb +25 -33
  18. data/lib/contrast/agent/assess/policy/policy_scanner.rb +3 -5
  19. data/lib/contrast/agent/assess/policy/preshift.rb +7 -5
  20. data/lib/contrast/agent/assess/policy/propagation_method.rb +10 -19
  21. data/lib/contrast/agent/assess/policy/propagation_node.rb +19 -8
  22. data/lib/contrast/agent/assess/policy/propagator.rb +1 -0
  23. data/lib/contrast/agent/assess/policy/propagator/center.rb +2 -1
  24. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +3 -6
  25. data/lib/contrast/agent/assess/policy/propagator/insert.rb +3 -1
  26. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +2 -1
  27. data/lib/contrast/agent/assess/policy/propagator/rack_protection.rb +73 -0
  28. data/lib/contrast/agent/assess/policy/propagator/select.rb +2 -12
  29. data/lib/contrast/agent/assess/policy/propagator/split.rb +12 -13
  30. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +3 -10
  31. data/lib/contrast/agent/assess/policy/propagator/trim.rb +3 -15
  32. data/lib/contrast/agent/assess/policy/rewriter_patch.rb +13 -10
  33. data/lib/contrast/agent/assess/policy/source_method.rb +12 -12
  34. data/lib/contrast/agent/assess/policy/source_validation/source_validation.rb +1 -3
  35. data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +5 -1
  36. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +0 -3
  37. data/lib/contrast/agent/assess/policy/trigger_method.rb +8 -18
  38. data/lib/contrast/agent/assess/policy/trigger_node.rb +3 -2
  39. data/lib/contrast/agent/assess/policy/trigger_validation/redos_validator.rb +4 -3
  40. data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +1 -2
  41. data/lib/contrast/agent/assess/policy/trigger_validation/xss_validator.rb +1 -8
  42. data/lib/contrast/agent/assess/property/evented.rb +8 -5
  43. data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +11 -5
  44. data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +4 -1
  45. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +7 -9
  46. data/lib/contrast/agent/at_exit_hook.rb +3 -3
  47. data/lib/contrast/agent/class_reopener.rb +9 -6
  48. data/lib/contrast/agent/disable_reaction.rb +4 -7
  49. data/lib/contrast/agent/exclusion_matcher.rb +7 -14
  50. data/lib/contrast/agent/inventory/dependencies.rb +2 -0
  51. data/lib/contrast/agent/inventory/dependency_analysis.rb +2 -6
  52. data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +3 -5
  53. data/lib/contrast/agent/inventory/policy/datastores.rb +3 -4
  54. data/lib/contrast/agent/inventory/policy/policy.rb +1 -1
  55. data/lib/contrast/agent/middleware.rb +17 -18
  56. data/lib/contrast/agent/module_data.rb +3 -3
  57. data/lib/contrast/agent/patching/policy/after_load_patch.rb +3 -3
  58. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +9 -9
  59. data/lib/contrast/agent/patching/policy/method_policy.rb +6 -2
  60. data/lib/contrast/agent/patching/policy/module_policy.rb +14 -7
  61. data/lib/contrast/agent/patching/policy/patch.rb +20 -25
  62. data/lib/contrast/agent/patching/policy/patch_status.rb +6 -7
  63. data/lib/contrast/agent/patching/policy/patcher.rb +21 -18
  64. data/lib/contrast/agent/patching/policy/policy.rb +2 -4
  65. data/lib/contrast/agent/patching/policy/policy_node.rb +16 -7
  66. data/lib/contrast/agent/patching/policy/trigger_node.rb +21 -8
  67. data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +1 -1
  68. data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +1 -1
  69. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +1 -1
  70. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +2 -3
  71. data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +1 -1
  72. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +5 -9
  73. data/lib/contrast/agent/protect/policy/policy.rb +1 -1
  74. data/lib/contrast/agent/protect/policy/rule_applicator.rb +7 -9
  75. data/lib/contrast/agent/protect/rule/base.rb +20 -23
  76. data/lib/contrast/agent/protect/rule/base_service.rb +9 -5
  77. data/lib/contrast/agent/protect/rule/cmd_injection.rb +18 -23
  78. data/lib/contrast/agent/protect/rule/deserialization.rb +6 -13
  79. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +3 -14
  80. data/lib/contrast/agent/protect/rule/no_sqli.rb +6 -2
  81. data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +1 -3
  82. data/lib/contrast/agent/protect/rule/path_traversal.rb +6 -10
  83. data/lib/contrast/agent/protect/rule/sqli.rb +1 -1
  84. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +1 -1
  85. data/lib/contrast/agent/protect/rule/xss.rb +1 -1
  86. data/lib/contrast/agent/protect/rule/xxe.rb +5 -12
  87. data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +1 -2
  88. data/lib/contrast/agent/reaction_processor.rb +13 -13
  89. data/lib/contrast/agent/request.rb +27 -26
  90. data/lib/contrast/agent/request_context.rb +17 -22
  91. data/lib/contrast/agent/request_handler.rb +5 -3
  92. data/lib/contrast/agent/response.rb +2 -3
  93. data/lib/contrast/agent/rewriter.rb +9 -6
  94. data/lib/contrast/agent/rule_set.rb +5 -4
  95. data/lib/contrast/agent/service_heartbeat.rb +4 -6
  96. data/lib/contrast/agent/static_analysis.rb +6 -5
  97. data/lib/contrast/agent/thread.rb +2 -4
  98. data/lib/contrast/agent/thread_watcher.rb +3 -4
  99. data/lib/contrast/agent/tracepoint_hook.rb +5 -5
  100. data/lib/contrast/agent/version.rb +1 -1
  101. data/lib/contrast/api/communication/messaging_queue.rb +4 -5
  102. data/lib/contrast/api/communication/response_processor.rb +11 -13
  103. data/lib/contrast/api/communication/service_lifecycle.rb +9 -6
  104. data/lib/contrast/api/communication/socket_client.rb +22 -31
  105. data/lib/contrast/api/communication/speedracer.rb +8 -13
  106. data/lib/contrast/api/decorators/address.rb +2 -3
  107. data/lib/contrast/api/decorators/agent_startup.rb +7 -9
  108. data/lib/contrast/api/decorators/application_startup.rb +12 -10
  109. data/lib/contrast/api/decorators/application_update.rb +0 -4
  110. data/lib/contrast/api/decorators/http_request.rb +3 -7
  111. data/lib/contrast/api/decorators/instrumentation_mode.rb +3 -5
  112. data/lib/contrast/api/decorators/library.rb +8 -6
  113. data/lib/contrast/api/decorators/message.rb +9 -9
  114. data/lib/contrast/api/decorators/trace_event.rb +3 -1
  115. data/lib/contrast/api/decorators/trace_event_object.rb +3 -6
  116. data/lib/contrast/api/decorators/trace_taint_range_tags.rb +1 -6
  117. data/lib/contrast/components/agent.rb +17 -17
  118. data/lib/contrast/components/app_context.rb +11 -15
  119. data/lib/contrast/components/assess.rb +16 -16
  120. data/lib/contrast/components/base.rb +40 -0
  121. data/lib/contrast/components/config.rb +2 -3
  122. data/lib/contrast/components/contrast_service.rb +12 -18
  123. data/lib/contrast/components/heap_dump.rb +5 -4
  124. data/lib/contrast/components/inventory.rb +2 -7
  125. data/lib/contrast/components/logger.rb +1 -2
  126. data/lib/contrast/components/protect.rb +10 -13
  127. data/lib/contrast/components/sampling.rb +13 -7
  128. data/lib/contrast/components/scope.rb +0 -4
  129. data/lib/contrast/components/settings.rb +5 -7
  130. data/lib/contrast/config/assess_rules_configuration.rb +1 -3
  131. data/lib/contrast/config/base_configuration.rb +4 -5
  132. data/lib/contrast/config/exception_configuration.rb +1 -5
  133. data/lib/contrast/config/heap_dump_configuration.rb +12 -6
  134. data/lib/contrast/config/logger_configuration.rb +1 -5
  135. data/lib/contrast/configuration.rb +6 -18
  136. data/lib/contrast/extension/assess/array.rb +3 -10
  137. data/lib/contrast/extension/assess/erb.rb +1 -7
  138. data/lib/contrast/extension/assess/eval_trigger.rb +4 -9
  139. data/lib/contrast/extension/assess/exec_trigger.rb +3 -9
  140. data/lib/contrast/extension/assess/fiber.rb +8 -17
  141. data/lib/contrast/extension/assess/hash.rb +3 -3
  142. data/lib/contrast/extension/assess/kernel.rb +4 -13
  143. data/lib/contrast/extension/assess/marshal.rb +6 -10
  144. data/lib/contrast/extension/assess/regexp.rb +6 -10
  145. data/lib/contrast/extension/assess/string.rb +8 -6
  146. data/lib/contrast/extension/kernel.rb +2 -2
  147. data/lib/contrast/extension/protect/kernel.rb +0 -5
  148. data/lib/contrast/framework/manager.rb +3 -5
  149. data/lib/contrast/framework/rack/patch/session_cookie.rb +11 -24
  150. data/lib/contrast/framework/rack/patch/support.rb +6 -4
  151. data/lib/contrast/framework/rails/patch/assess_configuration.rb +12 -9
  152. data/lib/contrast/framework/rails/patch/support.rb +41 -35
  153. data/lib/contrast/framework/rails/railtie.rb +34 -0
  154. data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +4 -1
  155. data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +2 -0
  156. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +5 -4
  157. data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +2 -0
  158. data/lib/contrast/framework/rails/support.rb +2 -2
  159. data/lib/contrast/framework/sinatra/support.rb +3 -1
  160. data/lib/contrast/funchook/funchook.rb +5 -8
  161. data/lib/contrast/logger/application.rb +13 -15
  162. data/lib/contrast/logger/format.rb +2 -5
  163. data/lib/contrast/logger/log.rb +26 -9
  164. data/lib/contrast/logger/request.rb +1 -6
  165. data/lib/contrast/security_exception.rb +1 -1
  166. data/lib/contrast/tasks/config.rb +0 -1
  167. data/lib/contrast/tasks/service.rb +6 -7
  168. data/lib/contrast/utils/assess/sampling_util.rb +2 -3
  169. data/lib/contrast/utils/assess/tracking_util.rb +3 -6
  170. data/lib/contrast/utils/class_util.rb +0 -8
  171. data/lib/contrast/utils/hash_digest.rb +2 -5
  172. data/lib/contrast/utils/heap_dump_util.rb +5 -3
  173. data/lib/contrast/utils/invalid_configuration_util.rb +4 -3
  174. data/lib/contrast/utils/inventory_util.rb +2 -3
  175. data/lib/contrast/utils/io_util.rb +3 -5
  176. data/lib/contrast/utils/job_servers_running.rb +13 -7
  177. data/lib/contrast/utils/os.rb +4 -4
  178. data/lib/contrast/utils/ruby_ast_rewriter.rb +2 -1
  179. data/lib/contrast/utils/string_utils.rb +2 -3
  180. data/lib/contrast/utils/tag_util.rb +25 -19
  181. data/resources/assess/policy.json +55 -0
  182. data/ruby-agent.gemspec +17 -16
  183. data/service_executables/VERSION +1 -1
  184. data/service_executables/linux/contrast-service +0 -0
  185. data/service_executables/mac/contrast-service +0 -0
  186. data/sonar-project.properties +9 -0
  187. metadata +61 -46
  188. data/lib/contrast/agent/railtie.rb +0 -31
  189. data/lib/contrast/components/interface.rb +0 -195
  190. data/lib/contrast/delegators/input_analysis.rb +0 -12
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f9748bb3a9e7e6ce4722edc88dbb3bd8d3a59b11dd691f47ac29b3ee9e6a00ba
4
- data.tar.gz: d5b5ff651f2914bff6da5cbd2fdcdc28a2dd1a2ea8ad4eced6c416cbab72b632
3
+ metadata.gz: 27e411d1ab6398ca59e77859552c6956b0590dc94973512d0bd6e8e63ffa7f74
4
+ data.tar.gz: 79fee8e128ace994b8aa791d6e945edada8bd69ff099494272af60fba437937c
5
5
  SHA512:
6
- metadata.gz: 6e03ec0934d333e79f957515dfdc851861d395e9c768d09ffdfbf56b6e818d27361cffb2f010985f6da2182b1a4b070ef2291b86ccd9280fb117c4125611ae8f
7
- data.tar.gz: bb60224de8c19b547f311aca8d78a2b99593e329696ab6acbaf59336316109be5e9419d02e6e4cd06d0714627c0942fea6d1c0872a6c69faff531838e1dbc359
6
+ metadata.gz: 6029048d3bc67b6c4f0e5408d37c2b9a8362bd5b8bf5d5e5858f93a26f499e4454896613dc71003e123cd1ca9473d558ec11cc9d7fbebe648b192d9040a44d8e
7
+ data.tar.gz: e1e697c39c4611f3fadccc82c189e700facd5f399214f96b6bc053bd702ccd05b10aa37a302231e39f82611b13ae40adbf45c2ca0e2ef7fb10eef790310a1836
data/.gitignore CHANGED
@@ -1,8 +1,8 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
3
  /_yardoc/
4
- /Gemfile.lock
5
4
  /coverage/
5
+ /Gemfile.lock
6
6
  /data/*
7
7
  /doc/
8
8
  /log/
@@ -18,6 +18,11 @@
18
18
  /ext/**/*.so
19
19
  /ext/**/*.bundle
20
20
 
21
+ bin
22
+ ruby-spec
23
+ mspec
24
+ service_executables
25
+
21
26
  # Funchook artifacts
22
27
  /ext/**/funchook.h
23
28
  /ext/**/libfunchook.dylib
data/.gitmodules CHANGED
@@ -1,6 +1,6 @@
1
1
  [submodule "agent-service-api"]
2
2
  path = agent-service-api
3
- url = git@bitbucket.org:contrastsecurity/agent-service-api
3
+ url = git@github.com:Contrast-Security-Inc/agent-service-api.git
4
4
  [submodule "funchook"]
5
5
  path = funchook
6
6
  url = https://github.com/kubo/funchook.git
data/.simplecov CHANGED
@@ -4,4 +4,5 @@
4
4
  SimpleCov.minimum_coverage line: 94.75
5
5
  SimpleCov.start do
6
6
  add_filter '/spec/'
7
+ enable_coverage :branch
7
8
  end
data/Rakefile CHANGED
@@ -23,8 +23,7 @@ task :contrast_pb_compile do
23
23
  # do some stuff before compile
24
24
 
25
25
  # Invoke the protobuf compile task with your sensible defaults
26
- ::Rake::Task['protobuf:compile'].invoke('lib',
27
- './agent-service-api/protobuf ./agent-service-api/protobuf/dtm.proto',
26
+ ::Rake::Task['protobuf:compile'].invoke('lib', './agent-service-api/protobuf ./agent-service-api/protobuf/dtm.proto',
28
27
  'lib/contrast/api',
29
28
  nil)
30
29
 
@@ -10,7 +10,8 @@ unless find_header('funchook.h', ext_path)
10
10
  COMMANDS = ['./autogen.sh', './configure', 'make clean', 'make'].freeze
11
11
  bundler_install_target_paths = []
12
12
 
13
- possible_gem_paths = Gem.path # .path and .paths diverge in their return type - .path returns strings, .paths returns PathSupports
13
+ # .path and .paths diverge in their return type - .path returns strings, .paths returns PathSupports
14
+ possible_gem_paths = Gem.path
14
15
  possible_gem_paths.each do |base_path|
15
16
  contrast_gem_dir_search = File.join(base_path, 'extensions', '**', '*', 'contrast-agent-*')
16
17
  extension_paths = Dir[contrast_gem_dir_search]
@@ -31,8 +32,7 @@ unless find_header('funchook.h', ext_path)
31
32
  end
32
33
 
33
34
  SOURCE_PATHS = [
34
- File.join('include', 'funchook.h'),
35
- File.join('src', 'libfunchook.dylib'),
35
+ File.join('include', 'funchook.h'), File.join('src', 'libfunchook.dylib'),
36
36
  File.join('src', 'libfunchook.so')
37
37
  ].freeze
38
38
 
@@ -4,12 +4,8 @@
4
4
  require 'mkmf'
5
5
  require_relative '../lib/contrast/agent/version'
6
6
 
7
- def name
8
- $TO_MAKE
9
- end
10
-
11
7
  def make!
12
- create_makefile "#{ name }/#{ name }"
8
+ create_makefile "#{ $TO_MAKE }/#{ $TO_MAKE }"
13
9
  end
14
10
 
15
11
  def ext_path
data/lib/contrast.rb CHANGED
@@ -4,10 +4,6 @@
4
4
  # Used to prevent deprecation warnings from flooding stdout
5
5
  ENV['PB_IGNORE_DEPRECATIONS'] = 'true'
6
6
 
7
- # Top-level namespace for Contrast Security agent
8
- module Contrast
9
- end
10
-
11
7
  # Some developers override various methods on Object, which can often involve
12
8
  # changing expected method parity/behavior which in turn prevents us from being
13
9
  # able to reliably use affected methods.
@@ -38,22 +34,36 @@ if RUBY_VERSION >= '3.0.0'
38
34
  end
39
35
  end
40
36
 
41
- # component interface for class creation
42
- # config gets built as a consequence of this require
43
- require 'contrast/components/interface'
37
+ require 'contrast/components/agent'
38
+ require 'contrast/components/app_context'
39
+ require 'contrast/components/assess'
40
+ require 'contrast/components/config'
41
+ require 'contrast/components/contrast_service'
42
+ require 'contrast/components/inventory'
43
+ require 'contrast/components/logger'
44
+ require 'contrast/components/protect'
45
+ require 'contrast/components/sampling'
46
+ require 'contrast/components/scope'
47
+ require 'contrast/components/settings'
48
+
49
+ module Contrast
50
+ SCOPE = Contrast::Components::Scope::Interface.new
51
+ CONFIG = Contrast::Components::Config::Interface.new
52
+ SETTINGS = Contrast::Components::Settings::Interface.new
53
+ ASSESS = Contrast::Components::Assess::Interface.new
54
+ PROTECT = Contrast::Components::Protect::Interface.new
55
+ INVENTORY = Contrast::Components::Inventory::Interface.new
56
+ LOGGER = Contrast::Components::Logger::Interface.new
57
+ AGENT = Contrast::Components::Agent::Interface.new
58
+ CONTRAST_SERVICE = Contrast::Components::ContrastService::Interface.new
59
+ APP_CONTEXT = Contrast::Components::AppContext::Interface.new
60
+ end
44
61
 
45
62
  # This needs to be required very early, after component interfaces, and before instrumentation attempts
46
63
  require 'contrast/funchook/funchook'
47
64
 
48
- # shared configuration support
49
- require 'contrast/config'
50
- require 'contrast/configuration'
51
-
52
65
  require 'contrast/agent/version'
53
66
 
54
- # errors and exceptions
55
- require 'contrast/security_exception'
56
-
57
67
  # shared utils
58
68
  require 'contrast/utils/timer'
59
69
  require 'contrast/utils/preflight_util'
@@ -10,7 +10,7 @@ module Contrast
10
10
  module Assess
11
11
  require 'contrast/agent/assess/tracker'
12
12
  require 'contrast/agent/module_data'
13
- require 'contrast/agent/rewriter'
13
+ require 'contrast/agent/rewriter' if RUBY_VERSION < '2.6.0' # TODO: RUBY-714 remove guard w/ EOL of 2.5
14
14
  require 'contrast/agent/assess/policy/preshift'
15
15
 
16
16
  # Dynamic Sources
@@ -8,7 +8,6 @@ require 'contrast/utils/object_share'
8
8
  require 'contrast/utils/stack_trace_utils'
9
9
  require 'contrast/utils/string_utils'
10
10
  require 'contrast/utils/timer'
11
- require 'contrast/components/interface'
12
11
  require 'contrast/agent/assess/contrast_object'
13
12
 
14
13
  module Contrast
@@ -29,8 +28,6 @@ module Contrast
29
28
  # @attr_reader args [Array<Contrast::Agent::Assess::ContrastObject>] the safe representation of the Arguments
30
29
  # with which the method was invoked
31
30
  class ContrastEvent
32
- include Contrast::Components::Interface
33
- access_component :analysis
34
31
 
35
32
  attr_reader :event_id, :policy_node, :stack_trace, :time, :thread, :object, :ret, :args, :tags
36
33
 
@@ -164,7 +161,7 @@ module Contrast
164
161
  def capture_stacktrace!
165
162
  # If we're configured to not capture the stacktrace, usually for performance reasons, then don't and return an
166
163
  # empty array instead
167
- unless ASSESS.capture_stacktrace?(policy_node)
164
+ unless ::Contrast::ASSESS.capture_stacktrace?(policy_node)
168
165
  @stack_trace = Contrast::Utils::ObjectShare::EMPTY_ARRAY
169
166
  return
170
167
  end
@@ -34,14 +34,14 @@ module Contrast
34
34
  def initialize object
35
35
  if object
36
36
  @object = Contrast::Utils::ClassUtil.to_contrast_string(object)
37
- @object_type = object.cs__class.name
37
+ @object_type = object.cs__class.cs__name
38
38
  # TODO: RUBY-1084 determine if we need to copy these tags to
39
39
  # restore immutability. For instance, if these tags were on a
40
40
  # String that was then #reverse!'d, would our tags be wrong?
41
41
  @tags = Contrast::Agent::Assess::Tracker.properties(object)&.tags
42
42
  else
43
43
  @object = Contrast::Utils::ObjectShare::NIL_STRING
44
- @object_type = nil.cs__class.name
44
+ @object_type = nil.cs__class.cs__name
45
45
  end
46
46
  end
47
47
 
@@ -13,7 +13,8 @@ module Contrast
13
13
  def self.build policy_node, tagged, object, ret, args, source_type = nil, source_name = nil
14
14
  case policy_node
15
15
  when Contrast::Agent::Assess::Policy::SourceNode
16
- Contrast::Agent::Assess::Events::SourceEvent.new(policy_node, tagged, object, ret, args, source_type, source_name)
16
+ Contrast::Agent::Assess::Events::SourceEvent.new(policy_node, tagged, object, ret, args, source_type,
17
+ source_name)
17
18
  when Contrast::Agent::Assess::Policy::PolicyNode
18
19
  Contrast::Agent::Assess::ContrastEvent.new(policy_node, tagged, object, ret, args)
19
20
  end
@@ -10,13 +10,11 @@ module Contrast
10
10
  # An extension of Hash that doesn't impact GC of the object being stored by storing its ID as a Key to lookup
11
11
  # and registering a finalizer on the object to remove its entry from the Hash immediately after it's GC'd.
12
12
  class Hash < Hash
13
- include Contrast::Components::Interface
14
- access_component :agent, :analysis
15
13
 
16
14
  FROZEN_FINALIZED_IDS = Set.new
17
15
 
18
16
  def []= key, obj
19
- return unless AGENT.enabled? && ASSESS.enabled?
17
+ return unless ::Contrast::AGENT.enabled? && ::Contrast::ASSESS.enabled?
20
18
 
21
19
  # We can't finalize frozen things, so only act on those that went through .pre_freeze
22
20
  if key.cs__frozen?
@@ -79,7 +77,7 @@ module Contrast
79
77
  #
80
78
  # @param key [Object] the Object on which we need to pre-define finalizers
81
79
  def pre_freeze key
82
- return unless AGENT.enabled? && ASSESS.enabled?
80
+ return unless ::Contrast::AGENT.enabled? && ::Contrast::ASSESS.enabled?
83
81
  return if key.cs__frozen?
84
82
  return if FROZEN_FINALIZED_IDS.include?(key.__id__)
85
83
 
@@ -37,7 +37,8 @@ module Contrast
37
37
  # Move on if we already know about this Dynamic Source
38
38
  next if Contrast::Agent::Assess::Policy::Policy.instance.find_source_node(class_name, method_name, true)
39
39
 
40
- dynamic_source_node = create_source_node(class_name, method_name, Set.new(properties.tag_keys), current_request)
40
+ dynamic_source_node = create_source_node(class_name, method_name, Set.new(properties.tag_keys),
41
+ current_request)
41
42
  Contrast::Agent::Assess::Policy::Policy.instance.add_node(dynamic_source_node, :dynamic_source)
42
43
  method_policy = build_source_policy(method_name, dynamic_source_node)
43
44
  Contrast::Agent::Patching::Policy::Patcher.patch_method(klass, instance_methods, method_policy)
@@ -130,8 +131,10 @@ module Contrast
130
131
  def append_properties! dynamic_source, request, source_node, field
131
132
  dynamic_source.properties[READ_TABLE] = Contrast::Utils::StringUtils.force_utf8(source_node.class_name)
132
133
  dynamic_source.properties[READ_COLUMN] = Contrast::Utils::StringUtils.force_utf8(field)
133
- dynamic_source.properties[WRITE_QUERY_TIME] = Contrast::Utils::StringUtils.force_utf8(Contrast::Utils::Timer.now_ms)
134
- dynamic_source.properties[WRITE_QUERY_URL] = Contrast::Utils::StringUtils.force_utf8(request&.normalized_uri)
134
+ dynamic_source.properties[WRITE_QUERY_TIME] =
135
+ Contrast::Utils::StringUtils.force_utf8(Contrast::Utils::Timer.now_ms)
136
+ dynamic_source.properties[WRITE_QUERY_URL] =
137
+ Contrast::Utils::StringUtils.force_utf8(request&.normalized_uri)
135
138
  end
136
139
 
137
140
  def append_events! dynamic_source, event
@@ -5,7 +5,8 @@ require 'contrast/agent/assess/policy/policy'
5
5
  require 'contrast/agent/patching/policy/patcher'
6
6
  require 'contrast/agent/patching/policy/method_policy'
7
7
  require 'contrast/agent/patching/policy/module_policy'
8
- require 'contrast/components/interface'
8
+ require 'contrast/components/logger'
9
+ require 'contrast/components/scope'
9
10
 
10
11
  module Contrast
11
12
  module Agent
@@ -16,8 +17,9 @@ module Contrast
16
17
  # provides a map for which methods our renamed functions need to call
17
18
  # and how.
18
19
  module Patcher
19
- include Contrast::Components::Interface
20
- access_component :logging, :analysis, :agent, :scope
20
+ extend Contrast::Components::Logger::InstanceMethods
21
+ extend Contrast::Components::Scope::InstanceMethods
22
+
21
23
 
22
24
  class << self
23
25
  def policy
@@ -34,24 +36,18 @@ module Contrast
34
36
  # called. This hook is provided so that patches to those methods can
35
37
  # pass us execution flow once a new method has been made available.
36
38
  def patch_assess_on_eval mod
37
- return unless ASSESS.enabled?
39
+ return unless ::Contrast::ASSESS.enabled?
38
40
  return if in_contrast_scope?
39
41
 
40
42
  patcher.patch_specific_module(mod)
41
43
  rescue StandardError => e
42
- logger.warn(
43
- 'Unable to patch assess during eval',
44
- e,
45
- module: mod.cs__name)
44
+ logger.warn('Unable to patch assess during eval', e, module: mod.cs__name)
46
45
  end
47
46
 
48
47
  # Exposed so that methods can be dynamically patched on creation at
49
48
  # runtime, like those generated by
50
49
  # ActiveRecord::AttributeMethods::Read::ClassMethods#define_method_attribute
51
- CLASS_TYPES = [
52
- Contrast::Utils::ObjectShare::CLASS,
53
- Contrast::Utils::ObjectShare::MODULE
54
- ].cs__freeze
50
+ CLASS_TYPES = [Contrast::Utils::ObjectShare::CLASS, Contrast::Utils::ObjectShare::MODULE].cs__freeze
55
51
  def patch_assess_method mod, method_name
56
52
  # Module.define_method is called a lot in Class and Module. We
57
53
  # currently do not expect these define_methods to result in methods
@@ -62,7 +58,8 @@ module Contrast
62
58
  return if CLASS_TYPES.include?(class_name)
63
59
  return unless ASSESS.enabled?
64
60
 
65
- source_nodes = Contrast::Agent::Patching::Policy::ModulePolicy.nodes_for_module(policy.sources, class_name)
61
+ source_nodes = Contrast::Agent::Patching::Policy::ModulePolicy.nodes_for_module(policy.sources,
62
+ class_name)
66
63
  return if source_nodes.empty?
67
64
 
68
65
  method_array = []
@@ -70,17 +67,15 @@ module Contrast
70
67
  source_nodes.each do |source_node|
71
68
  next unless source_node.method_name.to_s == method_name
72
69
 
73
- method_policy = Contrast::Agent::Patching::Policy::MethodPolicy.new(source_node: source_node,
74
- method_name: source_node.method_name,
75
- method_visibility: source_node.method_visibility,
76
- instance_method: true)
70
+ method_policy =
71
+ Contrast::Agent::Patching::Policy::MethodPolicy.new(source_node: source_node,
72
+ method_name: source_node.method_name,
73
+ method_visibility: source_node.method_visibility,
74
+ instance_method: true)
77
75
  patcher.patch_method(mod, method_array, method_policy)
78
76
  end
79
77
  rescue StandardError => e
80
- logger.warn(
81
- 'Unable to patch assess during define_method_attribute',
82
- e,
83
- module: mod.cs__name)
78
+ logger.warn('Unable to patch assess during define_method_attribute', e, module: mod.cs__name)
84
79
  end
85
80
  end
86
81
  end
@@ -26,7 +26,7 @@ module Contrast
26
26
  # Indicates is this feature has been disabled by the configuration,
27
27
  # read at startup, and therefore can never be enabled.
28
28
  def disabled_globally?
29
- ASSESS.forcibly_disabled?
29
+ ::Contrast::ASSESS.forcibly_disabled?
30
30
  end
31
31
 
32
32
  def node_type
@@ -35,16 +35,6 @@ module Contrast
35
35
  :TYPE_METHOD
36
36
  end
37
37
 
38
- def target
39
- @_target ||= begin
40
- if targets&.any?
41
- targets[0]
42
- elsif sources&.any?
43
- sources[0]
44
- end
45
- end
46
- end
47
-
48
38
  def target_string= value
49
39
  @target_string = value
50
40
  @targets = convert_policy_markers(value)
@@ -85,8 +75,7 @@ module Contrast
85
75
  next if Contrast::Api::Decorators::TraceTaintRangeTags::VALID_TAGS.include?(tag) ||
86
76
  Contrast::Api::Decorators::TraceTaintRangeTags::VALID_SOURCE_TAGS.include?(tag)
87
77
 
88
- raise(ArgumentError,
89
- "#{ node_class } #{ id } had an invalid tag. #{ tag } is not a known value.")
78
+ raise(ArgumentError, "#{ node_class } #{ id } had an invalid tag. #{ tag } is not a known value.")
90
79
  end
91
80
  end
92
81
 
@@ -100,27 +89,26 @@ module Contrast
100
89
  # Trigger (trigger nodes) don't have targets (they are the target)
101
90
  # Everything else (propagation nodes) are Source2Target
102
91
  def build_action
103
- @event_action ||= begin
104
- case node_class
105
- when Contrast::Agent::Assess::Policy::SourceNode::SOURCE
106
- :CREATION
107
- when Contrast::Agent::Assess::Policy::TriggerNode::TRIGGER
108
- :TRIGGER
109
- else
110
- if source_string.nil?
111
- :CREATION
112
- elsif target_string.nil?
113
- :TRIGGER
114
- else
115
- # TeamServer can't handle the multi-source or multi-target
116
- # values. Give it some help by changing them to 'A'
117
- source = source_string.include?(Contrast::Utils::ObjectShare::COMMA) ? ALL_TYPE : source_string
118
- target = target_string.include?(Contrast::Utils::ObjectShare::COMMA) ? ALL_TYPE : target_string
119
- str = source[0] + TO_MARKER + target[0]
120
- str.to_sym
121
- end
122
- end
123
- end
92
+ @event_action ||= case node_class
93
+ when Contrast::Agent::Assess::Policy::SourceNode::SOURCE
94
+ :CREATION
95
+ when Contrast::Agent::Assess::Policy::TriggerNode::TRIGGER
96
+ :TRIGGER
97
+ else
98
+ if source_string.nil?
99
+ :CREATION
100
+ elsif target_string.nil?
101
+ :TRIGGER
102
+ else
103
+ # TeamServer can't handle the multi-source or multi-target values. Give it some help
104
+ # by changing them to 'A'
105
+ source = all_type?(source_string) ? ALL_TYPE : source_string
106
+ target = all_type?(target_string) ? ALL_TYPE : target_string
107
+ str = source[0] + TO_MARKER + target[0]
108
+ str.to_sym
109
+ end
110
+ end
111
+
124
112
  @event_action
125
113
  end
126
114
 
@@ -158,6 +146,10 @@ module Contrast
158
146
  end
159
147
  converted
160
148
  end
149
+
150
+ def all_type? marker
151
+ marker.include?(Contrast::Utils::ObjectShare::COMMA)
152
+ end
161
153
  end
162
154
  end
163
155
  end