contrast-agent 6.6.2 → 6.6.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f00aee3e36cdb303ca9b209824fbb92386e0ca0043c0f24377f79168dca8d252
4
- data.tar.gz: 7fc3d7571246ff92a10da151ce4b723768e3f7214b5a1e57d5bb1d6a66e86e2b
3
+ metadata.gz: 38657595e182ad9ef1a26180b273061522dcea43e441e1750d9883d2d1d2d9f6
4
+ data.tar.gz: 37fe627c2fec00f17c6a2cd6b42aa96149bc4b01871fddd6bb929c5a2baabb63
5
5
  SHA512:
6
- metadata.gz: 9fc9e69602a2706cb41bf8d13e07693afb61ad85ad03ff43182f3c79c5f9dff1c0b8ed3e0cb690d15cf8e43830920516604e9b497945963897f0ee1b82e11f9b
7
- data.tar.gz: dfd4e5146f9ac498b83d76b13a9d6ed17a5de0e659ed301acbf6a873e18d5ff75ea8aa8fa7c3789433e100903a9f6bfb4b87c9d283107c5bd04015f862e88644
6
+ metadata.gz: 1a2a85843ec7ba80d84a84f21defd2333a1b1130165113777c324176597231ca17b6c861f1f44ff6024f71e01e7d3508f0d57e767381e3d7580e82c7e10bee4a
7
+ data.tar.gz: b7b98e93f5b8e3bfd826f730e3981bb6006aa69a71dbd24ecec6eeef373b0b147ce542f0e0416f42d9da33dbbe4a76945bb1341bde91ea9b7134a4ddee80b2fb
@@ -31,7 +31,7 @@ module Contrast
31
31
  # Contrast::Api::Dtm::ArchitectureComponent, but have different names for their fields.
32
32
  #
33
33
  # @param activity_or_update [Contrast::Api::Dtm::Activity, Contrast::Agent::Reporting::ApplicationUpdate]
34
- # @param hash_or_str [Hash, String] the database connection information
34
+ # @param hash_or_str [Hash, String, #configuration_hash] the database connection information
35
35
  def append_db_config activity_or_update, hash_or_str = active_record_config
36
36
  arr = build_from_db_config(hash_or_str)
37
37
  return unless arr&.any?
@@ -82,6 +82,11 @@ module Contrast
82
82
  def build_from_db_config hash_or_str
83
83
  return unless hash_or_str
84
84
 
85
+ # we need to handle types of HashConfig, which != Hash
86
+ # for example ActiveRecord::DatabaseConfigurations::HashConfig is type of active_record config
87
+ # but the method is not handling it properly
88
+ # so we need to handle it here and extract the hash
89
+ hash_or_str = hash_or_str.configuration_hash if hash_or_str.cs__respond_to?(:configuration_hash)
85
90
  if hash_or_str.is_a?(Hash)
86
91
  build_from_db_hash(hash_or_str)
87
92
  else
@@ -13,9 +13,8 @@ module Contrast
13
13
  # in which database operations occur. It is responsible for deciding if
14
14
  # the given invocation is worth reporting or not.
15
15
  module DataStores
16
+ extend Contrast::Components::Logger::InstanceMethods
16
17
  class << self
17
- extend Contrast::Components::Logger::InstanceMethods
18
-
19
18
  # The key used in policy.json to indicate the database type to
20
19
  # report.
21
20
  DATA_STORE_MARKER = 'data_store'
@@ -27,8 +27,8 @@ module Contrast
27
27
 
28
28
  def initialize
29
29
  @app_language = Contrast::Utils::ObjectShare::RUBY
30
- @app_name = ::Contrast::APP_CONTEXT.app_name
31
- @app_version = ::Contrast::APP_CONTEXT.app_version
30
+ @app_name = ::Contrast::APP_CONTEXT.name # rubocop:disable Security/Module/Name
31
+ @app_version = ::Contrast::APP_CONTEXT.version
32
32
  @routes = []
33
33
  end
34
34
 
@@ -153,7 +153,7 @@ module Contrast
153
153
  def app_name
154
154
  return @_app_name unless @_app_name.nil?
155
155
 
156
- @_app_name = ::Contrast::APP_CONTEXT.app_name
156
+ @_app_name = ::Contrast::APP_CONTEXT.name # rubocop:disable Security/Module/Name
157
157
  end
158
158
 
159
159
  # @return [String,nil]
@@ -18,12 +18,12 @@ module Contrast
18
18
  CONTENT_TYPE = 'application/json'
19
19
 
20
20
  def initialize
21
- @app_name = Base64.strict_encode64(Contrast::APP_CONTEXT.app_name)
21
+ @app_name = Base64.strict_encode64(Contrast::APP_CONTEXT.name) # rubocop:disable Security/Module/Name
22
22
  @api_key = Contrast::API.api_key
23
23
  @agent_version = [RUBY, Contrast::Agent::VERSION].join(SPACE)
24
24
  @app_language = RUBY
25
25
  @app_path = Base64.strict_encode64(Contrast::APP_CONTEXT.path)
26
- @app_version = Contrast::APP_CONTEXT.app_version
26
+ @app_version = Contrast::APP_CONTEXT.version
27
27
  @authorization = Base64.strict_encode64("#{ Contrast::API.user_name }:#{ Contrast::API.service_key }")
28
28
  @server_name = Base64.strict_encode64(Contrast::APP_CONTEXT.server_name)
29
29
  @server_path = Base64.strict_encode64(Contrast::APP_CONTEXT.server_path)
@@ -107,7 +107,7 @@ module Contrast
107
107
  suspend_reporting(message, ready_after, error_message) if mode == @_mode.resending
108
108
  return unless mode == @_mode.disabled
109
109
 
110
- stop_reporting(message, application: Contrast::APP_CONTEXT.app_name, error_message: error_message)
110
+ stop_reporting(message, application: Contrast::APP_CONTEXT.name, error_message: error_message) # rubocop:disable Security/Module/Name
111
111
  rescue StandardError => e
112
112
  logger.debug('Could not handle Response error information', error: e)
113
113
  end
@@ -3,6 +3,6 @@
3
3
 
4
4
  module Contrast
5
5
  module Agent
6
- VERSION = '6.6.2'
6
+ VERSION = '6.6.3'
7
7
  end
8
8
  end
@@ -52,7 +52,7 @@ module Contrast
52
52
 
53
53
  def build event
54
54
  msg = new
55
- msg.app_name = ::Contrast::APP_CONTEXT.app_name
55
+ msg.app_name = ::Contrast::APP_CONTEXT.name # rubocop:disable Security/Module/Name
56
56
  msg.app_path = ::Contrast::APP_CONTEXT.path
57
57
  msg.app_language = Contrast::Utils::ObjectShare::RUBY
58
58
  msg.client_id = ::Contrast::APP_CONTEXT.client_id
@@ -6,6 +6,7 @@ require 'contrast/api/decorators/agent_startup'
6
6
  require 'contrast/api/decorators/application_startup'
7
7
  require 'contrast/utils/object_share'
8
8
  require 'contrast/components/app_context_extend'
9
+ require 'contrast/config/base_configuration'
9
10
 
10
11
  module Contrast
11
12
  module Components
@@ -18,15 +19,66 @@ module Contrast
18
19
  class Interface
19
20
  include Contrast::Components::AppContextExtend
20
21
  include Contrast::Components::ComponentBase
21
- include Contrast::Components::Logger::InstanceMethods
22
+ include Contrast::Config::BaseConfiguration
22
23
 
23
24
  DEFAULT_APP_NAME = 'rails'
24
25
  DEFAULT_APP_PATH = '/'
25
26
  DEFAULT_SERVER_NAME = 'localhost'
26
27
  DEFAULT_SERVER_PATH = '/'
27
28
 
28
- def initialize
29
+ # @return [String]
30
+ attr_reader :version
31
+ # @return [String]
32
+ attr_reader :language
33
+ # @return [String]
34
+ attr_reader :group
35
+ # @return [String]
36
+ attr_reader :tags
37
+ # @return [String]
38
+ attr_reader :code
39
+ # @return [String]
40
+ attr_reader :metadata
41
+
42
+ def initialize hsh = {}
29
43
  original_pid
44
+ return unless hsh
45
+
46
+ @_name = hsh[:name]
47
+ @version = hsh[:version]
48
+ @language = hsh[:language]
49
+ @_path = hsh[:path]
50
+ @group = hsh[:group]
51
+ @tags = hsh[:tags]
52
+ @code = hsh[:code]
53
+ @metadata = hsh[:metadata]
54
+ @_session_id = hsh[:session_id]
55
+ @_session_metadata = hsh[:session_metadata]
56
+ end
57
+
58
+ # @return [String, Contrast::Utils::ObjectShare::EMPTY_STRING]
59
+ def session_id
60
+ @_session_id ||= Contrast::Utils::ObjectShare::EMPTY_STRING
61
+ end
62
+
63
+ # Set session_id
64
+ #
65
+ # @param id [String]
66
+ # @return [String]
67
+ def session_id= id
68
+ @_session_id = id
69
+ end
70
+
71
+ # @return [String, Contrast::Utils::ObjectShare::EMPTY_STRING]
72
+ def session_metadata
73
+ @_session_metadata ||= Contrast::Utils::ObjectShare::EMPTY_STRING
74
+ end
75
+
76
+ # Set session_metadata
77
+ #
78
+ # @param meta [String]
79
+ # @return [String]
80
+ def session_metadata= meta
81
+ @_session_metadata = meta
30
82
  end
31
83
 
32
84
  def server_type
@@ -37,9 +89,8 @@ module Contrast
37
89
  end
38
90
  end
39
91
 
40
- def app_name
41
- @_app_name ||= begin
42
- tmp = ::Contrast::CONFIG.root.application.name # rubocop:disable Security/Module/Name
92
+ def name
93
+ @_name ||= begin
43
94
  tmp = Contrast::Agent.framework_manager.app_name unless Contrast::Utils::StringUtils.present?(tmp)
44
95
  tmp = File.basename(Dir.pwd) unless Contrast::Utils::StringUtils.present?(tmp)
45
96
  Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_APP_NAME)
@@ -48,13 +99,16 @@ module Contrast
48
99
  end
49
100
  end
50
101
 
51
- def app_version
52
- @_app_version ||= Contrast::CONFIG.root.application.version
102
+ # Set application name
103
+ #
104
+ # @param app_name [String] application name
105
+ # @return [String]
106
+ def name= app_name
107
+ @_name = app_name
53
108
  end
54
109
 
55
110
  def path
56
111
  @_path ||= begin
57
- tmp = ::Contrast::CONFIG.root.application.path
58
112
  tmp = Contrast::Agent.framework_manager.application_root unless Contrast::Utils::StringUtils.present?(tmp)
59
113
  Contrast::Utils::StringUtils.truncate(tmp, DEFAULT_APP_PATH)
60
114
  rescue StandardError
@@ -18,13 +18,13 @@ module Contrast
18
18
 
19
19
  def build_agent_startup_message
20
20
  msg = Contrast::Api::Dtm::AgentStartup.build(server_name, server_path, server_type)
21
- logger.info('Application context',
22
- server_name: msg.server_name,
23
- server_path: msg.server_path,
24
- server_type: msg.server_type,
25
- application_name: app_name,
26
- application_path: path,
27
- application_language: Contrast::Utils::ObjectShare::RUBY)
21
+ Contrast::CONFIG.proto_logger.info('Application context',
22
+ server_name: msg.server_name,
23
+ server_path: msg.server_path,
24
+ server_type: msg.server_type,
25
+ application_name: name, # rubocop:disable Security/Module/Name
26
+ application_path: path,
27
+ application_language: Contrast::Utils::ObjectShare::RUBY)
28
28
 
29
29
  msg
30
30
  end
@@ -42,7 +42,7 @@ module Contrast
42
42
  end
43
43
 
44
44
  def client_id
45
- @_client_id ||= [app_name, pgid].join('-')
45
+ @_client_id ||= [name, pgid].join('-') # rubocop:disable Security/Module/Name
46
46
  end
47
47
 
48
48
  def app_and_server_information
@@ -4,6 +4,8 @@
4
4
  require 'contrast/components/agent'
5
5
  require 'contrast/components/inventory'
6
6
  require 'contrast/components/protect'
7
+ require 'contrast/components/app_context'
8
+
7
9
  module Contrast
8
10
  module Config
9
11
  # The base of the Common Configuration settings.
@@ -14,7 +16,7 @@ module Contrast
14
16
  attr_writer :api
15
17
  # @return [Contrast::Components::Agent::Interface]
16
18
  attr_writer :agent
17
- # @return [Contrast::Config::ApplicationConfiguration]
19
+ # @return [Contrast::Components::AppContext::Interface]
18
20
  attr_writer :application
19
21
  # @return [Contrast::Config::ServerConfiguration]
20
22
  attr_writer :server
@@ -36,7 +38,7 @@ module Contrast
36
38
  @api = Contrast::Components::Api::Interface.new(hsh[:api])
37
39
  @enable = hsh[:enable]
38
40
  @agent = Contrast::Components::Agent::Interface.new(hsh[:agent])
39
- @application = Contrast::Config::ApplicationConfiguration.new(hsh[:application])
41
+ @application = Contrast::Components::AppContext::Interface.new(hsh[:application])
40
42
  @server = Contrast::Config::ServerConfiguration.new(hsh[:server])
41
43
  @assess = Contrast::Config::AssessConfiguration.new(hsh[:assess])
42
44
  @inventory = Contrast::Components::Inventory::Interface.new(hsh[:inventory])
@@ -54,9 +56,9 @@ module Contrast
54
56
  @agent ||= Contrast::Components::Agent::Interface.new
55
57
  end
56
58
 
57
- # @return [Contrast::Config::ApplicationConfiguration]
59
+ # @return [Contrast::Components::AppContext::Interface]
58
60
  def application
59
- @application ||= Contrast::Config::ApplicationConfiguration.new
61
+ @application ||= Contrast::Components::AppContext::Interface.new
60
62
  end
61
63
 
62
64
  # @return [Contrast::Config::ServerConfiguration]
@@ -18,7 +18,6 @@ require 'contrast/config/protect_rule_configuration'
18
18
  require 'contrast/config/protect_rules_configuration'
19
19
 
20
20
  require 'contrast/config/ruby_configuration'
21
- require 'contrast/config/application_configuration'
22
21
  require 'contrast/config/server_configuration'
23
22
  require 'contrast/config/assess_configuration'
24
23
  require 'contrast/config/root_configuration'
@@ -182,7 +182,7 @@ module Contrast
182
182
  else
183
183
  DEFAULT_METADATA
184
184
  end
185
- app_name = ::Contrast::APP_CONTEXT.app_name
185
+ app_name = ::Contrast::APP_CONTEXT.name # rubocop:disable Security/Module/Name
186
186
  attach_request_and_sender_info(message, sender_info)
187
187
  message << "request=#{ context.request.url } "
188
188
  message << "requestMethod=#{ request_method } "
@@ -1,15 +1,11 @@
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/components/logger'
5
-
6
4
  module Contrast
7
5
  module Utils
8
6
  # Utilities for encoding and normalizing strings
9
- class StringUtils
7
+ module StringUtils
10
8
  class << self
11
- include Contrast::Components::Logger::InstanceMethods
12
-
13
9
  UTF8 = 'utf-8'
14
10
  HTTP_PREFIX = 'HTTP_'
15
11
 
@@ -61,7 +57,7 @@ module Contrast
61
57
  # We were unable to switch the String to a UTF-8 format.
62
58
  # Return non-nil so as not to throw an exception later when trying
63
59
  # to do regexp or other compares on the String
64
- logger.trace('Unable to cast String to UTF-8 format', e, value: str)
60
+ Contrast::CONFIG.proto_logger.trace('Unable to cast String to UTF-8 format', e, value: str)
65
61
 
66
62
  Contrast::Utils::ObjectShare::EMPTY_STRING
67
63
  end
data/lib/contrast.rb CHANGED
@@ -81,7 +81,7 @@ module Contrast
81
81
  AGENT = CONFIG.root.agent
82
82
  LOGGER = AGENT.logger
83
83
  CONTRAST_SERVICE = Contrast::Components::ContrastService::Interface.new
84
- APP_CONTEXT = Contrast::Components::AppContext::Interface.new
84
+ APP_CONTEXT = CONFIG.root.application
85
85
  end
86
86
 
87
87
  module Contrast
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contrast-agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.6.2
4
+ version: 6.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - galen.palmer@contrastsecurity.com
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: exe
15
15
  cert_chain: []
16
- date: 2022-07-15 00:00:00.000000000 Z
16
+ date: 2022-07-19 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: bundler
@@ -665,22 +665,22 @@ executables:
665
665
  - contrast_service
666
666
  extensions:
667
667
  - ext/cs__common/extconf.rb
668
- - ext/cs__assess_fiber_track/extconf.rb
669
- - ext/cs__assess_string/extconf.rb
668
+ - ext/cs__tests/extconf.rb
670
669
  - ext/cs__assess_module/extconf.rb
671
- - ext/cs__assess_test/extconf.rb
672
- - ext/cs__assess_kernel/extconf.rb
673
- - ext/cs__assess_yield_track/extconf.rb
670
+ - ext/cs__assess_array/extconf.rb
674
671
  - ext/cs__assess_hash/extconf.rb
672
+ - ext/cs__assess_basic_object/extconf.rb
673
+ - ext/cs__assess_regexp/extconf.rb
675
674
  - ext/cs__os_information/extconf.rb
675
+ - ext/cs__assess_test/extconf.rb
676
+ - ext/cs__assess_string/extconf.rb
676
677
  - ext/cs__contrast_patch/extconf.rb
677
- - ext/cs__assess_marshal_module/extconf.rb
678
- - ext/cs__assess_regexp/extconf.rb
679
- - ext/cs__assess_array/extconf.rb
680
- - ext/cs__scope/extconf.rb
681
- - ext/cs__assess_basic_object/extconf.rb
682
- - ext/cs__tests/extconf.rb
683
678
  - ext/cs__assess_string_interpolation/extconf.rb
679
+ - ext/cs__scope/extconf.rb
680
+ - ext/cs__assess_marshal_module/extconf.rb
681
+ - ext/cs__assess_fiber_track/extconf.rb
682
+ - ext/cs__assess_yield_track/extconf.rb
683
+ - ext/cs__assess_kernel/extconf.rb
684
684
  extra_rdoc_files: []
685
685
  files:
686
686
  - ".clang-format"
@@ -1193,7 +1193,6 @@ files:
1193
1193
  - lib/contrast/components/settings.rb
1194
1194
  - lib/contrast/config.rb
1195
1195
  - lib/contrast/config/api_proxy_configuration.rb
1196
- - lib/contrast/config/application_configuration.rb
1197
1196
  - lib/contrast/config/assess_configuration.rb
1198
1197
  - lib/contrast/config/assess_rules_configuration.rb
1199
1198
  - lib/contrast/config/base_configuration.rb
@@ -1,57 +0,0 @@
1
- # Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
- # frozen_string_literal: true
3
-
4
- require 'contrast/utils/object_share'
5
-
6
- module Contrast
7
- module Config
8
- # Common Configuration settings. Those in this section pertain to the
9
- # application identification functionality of the Agent.
10
- class ApplicationConfiguration
11
- include Contrast::Config::BaseConfiguration
12
-
13
- # @return [String]
14
- attr_accessor :name
15
- # @return [String]
16
- attr_accessor :version
17
- # @return [String]
18
- attr_accessor :language
19
- # @return [String]
20
- attr_accessor :path
21
- # @return [String]
22
- attr_accessor :group
23
- # @return [String]
24
- attr_accessor :tags
25
- # @return [String]
26
- attr_accessor :code
27
- # @return [String]
28
- attr_accessor :metadata
29
- attr_writer :session_id, :session_metadata
30
-
31
- def initialize hsh = {}
32
- return unless hsh
33
-
34
- @name = hsh[:name]
35
- @version = hsh[:version]
36
- @language = hsh[:language]
37
- @path = hsh[:path]
38
- @group = hsh[:group]
39
- @tags = hsh[:tags]
40
- @code = hsh[:code]
41
- @metadata = hsh[:metadata]
42
- @session_id = hsh[:session_id]
43
- @session_metadata = hsh[:session_metadata]
44
- end
45
-
46
- # @return [String, Contrast::Utils::ObjectShare::EMPTY_STRING]
47
- def session_id
48
- @session_id ||= Contrast::Utils::ObjectShare::EMPTY_STRING
49
- end
50
-
51
- # @return [String, Contrast::Utils::ObjectShare::EMPTY_STRING]
52
- def session_metadata
53
- @session_metadata ||= Contrast::Utils::ObjectShare::EMPTY_STRING
54
- end
55
- end
56
- end
57
- end