contrast-agent 6.13.0 → 6.15.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/lib/contrast/agent/{assess.rb → assess/assess.rb} +1 -1
  3. data/lib/contrast/agent/{module_data.rb → assess/module_data.rb} +0 -0
  4. data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +3 -0
  5. data/lib/contrast/agent/assess/policy/policy_node.rb +3 -2
  6. data/lib/contrast/agent/assess/policy/propagation_method.rb +2 -2
  7. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +0 -1
  8. data/lib/contrast/agent/assess/policy/source_method.rb +1 -1
  9. data/lib/contrast/agent/assess/policy/trigger_method.rb +36 -1
  10. data/lib/contrast/agent/assess/policy/trigger_validation/redos_validator.rb +1 -1
  11. data/lib/contrast/agent/{excluder.rb → excluder/excluder.rb} +0 -0
  12. data/lib/contrast/agent/{exclusion_matcher.rb → excluder/exclusion_matcher.rb} +0 -0
  13. data/lib/contrast/agent/{at_exit_hook.rb → hooks/at_exit_hook.rb} +0 -0
  14. data/lib/contrast/agent/{tracepoint_hook.rb → hooks/tracepoint_hook.rb} +0 -0
  15. data/lib/contrast/agent/inventory/database_config.rb +1 -0
  16. data/lib/contrast/agent/{inventory.rb → inventory/inventory.rb} +0 -0
  17. data/lib/contrast/agent/{middleware.rb → middleware/middleware.rb} +3 -3
  18. data/lib/contrast/agent/{static_analysis.rb → middleware/static_analysis.rb} +0 -0
  19. data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +5 -5
  20. data/lib/contrast/agent/protect/input_analyzer/worth_watching_analyzer.rb +1 -1
  21. data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +1 -1
  22. data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +1 -1
  23. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +1 -1
  24. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +1 -1
  25. data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +1 -1
  26. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +1 -1
  27. data/lib/contrast/agent/protect/rule/base.rb +121 -134
  28. data/lib/contrast/agent/protect/rule/{bot_blocker.rb → bot_blocker/bot_blocker.rb} +2 -2
  29. data/lib/contrast/agent/protect/rule/{cmd_injection.rb → cmdi/cmd_injection.rb} +1 -1
  30. data/lib/contrast/agent/protect/rule/cmdi/cmdi_backdoors.rb +3 -3
  31. data/lib/contrast/agent/protect/rule/cmdi/cmdi_base_rule.rb +1 -1
  32. data/lib/contrast/agent/protect/rule/cmdi/cmdi_chained_command.rb +2 -2
  33. data/lib/contrast/agent/protect/rule/cmdi/cmdi_dangerous_path.rb +2 -2
  34. data/lib/contrast/agent/protect/rule/cmdi/cmdi_input_classification.rb +1 -1
  35. data/lib/contrast/agent/protect/rule/{deserialization.rb → deserialization/deserialization.rb} +2 -2
  36. data/lib/contrast/agent/protect/rule/{no_sqli.rb → no_sqli/no_sqli.rb} +3 -3
  37. data/lib/contrast/agent/protect/rule/no_sqli/no_sqli_input_classification.rb +1 -1
  38. data/lib/contrast/agent/protect/rule/{path_traversal.rb → path_traversal/path_traversal.rb} +2 -2
  39. data/lib/contrast/agent/protect/rule/path_traversal/path_traversal_semantic_security_bypass.rb +3 -3
  40. data/lib/contrast/agent/protect/rule/{sql_sample_builder.rb → sqli/sql_sample_builder.rb} +0 -1
  41. data/lib/contrast/agent/protect/rule/{sqli.rb → sqli/sqli.rb} +2 -2
  42. data/lib/contrast/agent/protect/rule/sqli/sqli_base_rule.rb +1 -1
  43. data/lib/contrast/agent/protect/rule/{unsafe_file_upload.rb → unsafe_file_upload/unsafe_file_upload.rb} +2 -2
  44. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_input_classification.rb +1 -1
  45. data/lib/contrast/agent/protect/rule/utils/builders.rb +111 -0
  46. data/lib/contrast/agent/protect/rule/utils/filters.rb +110 -0
  47. data/lib/contrast/agent/protect/rule/{xss.rb → xss/xss.rb} +2 -2
  48. data/lib/contrast/agent/protect/rule/{xxe.rb → xxe/xxe.rb} +2 -2
  49. data/lib/contrast/agent/protect/rule.rb +8 -9
  50. data/lib/contrast/agent/{disable_reaction.rb → reactions/disable_reaction.rb} +0 -0
  51. data/lib/contrast/agent/reporting/reporter.rb +1 -1
  52. data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample.rb +3 -3
  53. data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +1 -1
  54. data/lib/contrast/agent/reporting/reporting_workers/application_server_worker.rb +1 -1
  55. data/lib/contrast/agent/reporting/reporting_workers/reporter_heartbeat.rb +1 -1
  56. data/lib/contrast/agent/reporting/reporting_workers/server_settings_worker.rb +1 -1
  57. data/lib/contrast/agent/{request.rb → request/request.rb} +0 -0
  58. data/lib/contrast/agent/{request_context.rb → request/request_context.rb} +3 -3
  59. data/lib/contrast/agent/{request_context_extend.rb → request/request_context_extend.rb} +0 -0
  60. data/lib/contrast/agent/{request_handler.rb → request/request_handler.rb} +0 -0
  61. data/lib/contrast/agent/{response.rb → response/response.rb} +0 -0
  62. data/lib/contrast/agent/{scope.rb → scope/scope.rb} +0 -0
  63. data/lib/contrast/agent/telemetry/base.rb +2 -2
  64. data/lib/contrast/agent/{telemetry.rb → telemetry/telemetry.rb} +0 -0
  65. data/lib/contrast/agent/{thread.rb → thread/thread.rb} +0 -0
  66. data/lib/contrast/agent/{thread_watcher.rb → thread/thread_watcher.rb} +0 -0
  67. data/lib/contrast/agent/{worker_thread.rb → thread/worker_thread.rb} +0 -0
  68. data/lib/contrast/agent/version.rb +1 -1
  69. data/lib/contrast/agent.rb +11 -11
  70. data/lib/contrast/components/agent.rb +1 -1
  71. data/lib/contrast/components/assess.rb +1 -0
  72. data/lib/contrast/{agent → components}/rule_set.rb +0 -0
  73. data/lib/contrast/components/scope.rb +1 -1
  74. data/lib/contrast/components/settings.rb +1 -1
  75. data/lib/contrast/config/validate.rb +140 -0
  76. data/lib/contrast/config/yaml_file.rb +129 -0
  77. data/lib/contrast/extension/assess/exec_trigger.rb +1 -1
  78. data/lib/contrast/extension/assess/string.rb +4 -3
  79. data/lib/contrast/tasks/config.rb +7 -118
  80. data/lib/contrast/utils/middleware_utils.rb +4 -0
  81. data/lib/contrast.rb +1 -1
  82. data/ruby-agent.gemspec +6 -3
  83. metadata +56 -60
  84. data/lib/contrast/agent/protect/rule/base_service.rb +0 -175
@@ -0,0 +1,140 @@
1
+ # Copyright (c) 2023 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
+ # frozen_string_literal: true
3
+
4
+ require 'yaml'
5
+ require 'contrast/configuration'
6
+ require 'contrast/agent/reporting/reporter'
7
+ require 'base64'
8
+
9
+ module Contrast
10
+ module Config
11
+ # Helper module with methods to validate the existing yaml file.
12
+ module Validate
13
+ # rubocop:disable Rails/Output
14
+ SKIP_LOG = %w[service_key api_key].cs__freeze
15
+ REQUIRED = %i[url api_key service_key user_name].cs__freeze
16
+ PASS = " \u{2705} "
17
+ FAIL = " \u{274C} "
18
+ REQUIRED_HEADERS = %i[server_type server_name server_path app_language app_name].cs__freeze
19
+
20
+ def validate_file
21
+ puts("\u{1F9EA} Validating Agent Configuration...\n")
22
+ Contrast::Config.validate_config
23
+ puts('done...')
24
+ puts("Validating Contrast Reporter Headers...\n")
25
+ reporter = Contrast::Config.validate_headers
26
+ puts('done...')
27
+ puts("Testing Reporter Client Connection...\n")
28
+ Contrast::Config.test_connection(reporter) if reporter
29
+ puts('Validation complete')
30
+ end
31
+
32
+ def validate_config
33
+ config = Contrast::Configuration.new
34
+ abort("Unable to Build Config #{ FAIL }") unless config
35
+ missing = []
36
+
37
+ api_hash = config.api.to_contrast_hash
38
+
39
+ api_hash.each_key do |key|
40
+ value = mask_keys(api_hash, key)
41
+ if value.is_a?(Contrast::Config::ApiProxyConfiguration)
42
+ Contrast::Config.validate_proxy(value)
43
+ elsif value.is_a?(Contrast::Config::CertificationConfiguration)
44
+ Contrast::Config.validate_cert(value)
45
+ next
46
+ elsif value.is_a?(Contrast::Config::RequestAuditConfiguration)
47
+ Contrast::Config.validate_audit(value)
48
+ next
49
+ elsif value.nil? && REQUIRED.include?(key.to_sym)
50
+ missing << key
51
+ end
52
+ end
53
+ return if missing.empty?
54
+
55
+ abort("Validation failed: Missing required API configuration values: #{ missing.join(', ') } #{ FAIL }")
56
+ end
57
+
58
+ def validate_proxy config
59
+ puts(" Proxy Enabled: #{ config.enable }")
60
+ return unless config.enable
61
+
62
+ mark = config.url.nil? ? FAIL : PASS
63
+ puts(" Proxy URL: #{ config.url } #{ mark }")
64
+ abort('Proxy Enabled but no Proxy URL given') unless config.url
65
+ end
66
+
67
+ def validate_cert config
68
+ puts(" Certification Enabled: #{ config.enable }")
69
+ return unless config.enable
70
+
71
+ mark = config.ca_file.nil? ? FAIL : PASS
72
+ puts(" CA File: #{ config.ca_file } #{ mark }")
73
+ abort('CA file path not provided') unless config.ca_file
74
+ mark = config.cert_file.nil? ? FAIL : PASS
75
+ puts(" Cert File: #{ config.cert_file } #{ mark }")
76
+ abort('Cert file path not provided') unless config.cert_file
77
+ mark = config.key_file.nil? ? FAIL : PASS
78
+ puts(" Key File: #{ config.key_file } #{ mark }")
79
+ abort('Key file path not provided') unless config.key_file
80
+ end
81
+
82
+ def validate_audit config
83
+ puts(" Request Audit Enabled: #{ config.enable }")
84
+ return unless config.enable
85
+
86
+ config.cs__class::CONFIG_VALUES.each do |value_name|
87
+ puts(" #{ value_name }::#{ config.send(value_name.to_sym) }")
88
+ end
89
+ end
90
+
91
+ def init_reporter
92
+ Contrast::Agent::Reporter.new
93
+ end
94
+
95
+ def validate_headers
96
+ missing = []
97
+ reporter = init_reporter
98
+ reporter_headers = reporter.client.headers.to_contrast_hash
99
+ REQUIRED_HEADERS.each do |key|
100
+ value = decode_header(reporter_headers, key)
101
+ missing << key if value.nil?
102
+ end
103
+ unless missing.empty?
104
+ abort("Validation failed: Missing required header values: #{ missing.join(', ') } #{ FAIL }")
105
+ end
106
+ reporter
107
+ end
108
+
109
+ def test_connection reporter
110
+ puts(" Connection failed #{ FAIL }") unless reporter
111
+ connection = reporter.connection
112
+ abort("Failed to Initialize Connection please check error logs for details #{ FAIL } ") unless connection
113
+ abort('Failed to Start Client please check error logs for details') unless reporter.client.startup!(connection)
114
+ last_response = reporter.client.response_handler.last_response_code
115
+ if last_response.include?('40')
116
+ puts(" Last response code: #{ last_response } #{ FAIL }")
117
+ abort("Failed to Initialize Connection please check error logs for details #{ FAIL } ")
118
+ elsif connection
119
+ puts(" Last response code: #{ last_response } #{ PASS }")
120
+ puts(" Connection successful #{ PASS }") if connection
121
+ end
122
+ end
123
+
124
+ def mask_keys hash, key
125
+ value = hash[key]
126
+ redacted_value = Contrast::Configuration::REDACTED if SKIP_LOG.include?(key.to_s)
127
+ puts(" #{ key }::#{ redacted_value || value }") unless value.is_a?(Contrast::Config::BaseConfiguration)
128
+ value
129
+ end
130
+
131
+ def decode_header hash, key
132
+ value = hash[key]
133
+ decoded_header = Base64.strict_decode64(value)
134
+ puts(" #{ key }::#{ key == :app_language ? value : decoded_header }")
135
+ value
136
+ end
137
+ # rubocop:enable Rails/Output
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,129 @@
1
+ # Copyright (c) 2023 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
+ # frozen_string_literal: true
3
+
4
+ require 'fileutils'
5
+ require 'yaml'
6
+
7
+ module Contrast
8
+ module Config
9
+ # Helper module with methods to find active configuration file used by the agent or create it.\
10
+ # This file is used before the agent start so methods added here must not be dependent on Agent
11
+ # instrumentation.
12
+ module YamlFile
13
+ CONFIG_FILE_NAME = 'contrast_security'
14
+ EXT = { yml: 'yml', yaml: 'yaml' }.freeze # rubocop:disable Security/Object/Freeze
15
+
16
+ POSSIBLE_TARGET_PATHS = %w[
17
+ ./
18
+ ./config/
19
+ /etc/contrast/ruby/
20
+ /etc/contrast/
21
+ /etc/
22
+ ].freeze # rubocop:disable Security/Object/Freeze
23
+
24
+ HEADER = "# +-------------------------------------------------------------------------+\n" \
25
+ "# This Contrast Security configuration is Auto-generated by rake task.\n" \
26
+ "# To List all available rake task use 'rake -T'. \n" \
27
+ "#\n" \
28
+ "# Please enter valid api information, for the Ruby Agent to be able to\n" \
29
+ "# connect to Contrast UI. You can validate your config file by running: \n" \
30
+ "# 'bundle exec rake contrast:config:validate' \n" \
31
+ "#\n" \
32
+ "# To find your organization keys please follow this documentation:\n" \
33
+ "# https://docs.contrastsecurity.com/en/find-the-agent-keys.html\n" \
34
+ "# +-------------------------------------------------------------------------+\n"
35
+
36
+ FOOTER = "\n# For more information visit the full Ruby agent configuration guide:\n" \
37
+ '# https://docs.contrastsecurity.com/en/ruby-configuration.html'
38
+
39
+ COMMENT = "#agent:\n" \
40
+ "# logger:\n" \
41
+ "# level: WARN\n" \
42
+ "# path: contrast_agent.log\n" \
43
+ "#server:\n" \
44
+ "# name: Server name\n" \
45
+ "#application:\n" \
46
+ "# name: Application name\n" \
47
+ "# code: Application name\n" \
48
+ "# group: Application group\n" \
49
+ "# session_metadata: Application metadata used for creation of Session ID\n" \
50
+ "# version: Application version\n"
51
+
52
+ DEFAULT_CONFIG = {
53
+ 'api' => {
54
+ 'url' => 'https://app.contrastsecurity.com',
55
+ 'api_key' => 'contrast_user',
56
+ 'service_key' => 'demo',
57
+ 'user_name' => 'demo'
58
+ }
59
+ }.freeze # rubocop:disable Security/Object/Freeze
60
+
61
+ class << self
62
+ # Checks all accessible by the agent path for active configuration created.
63
+ #
64
+ # @return [Boolean]
65
+ def created?
66
+ return true if File.exist?(Contrast::Config::YamlFile.target_path)
67
+ return true unless find!.empty?
68
+
69
+ false
70
+ end
71
+
72
+ # Finds active configuration used.
73
+ #
74
+ # @return [String] path of the config file.
75
+ def find!
76
+ found = ''
77
+ paths = POSSIBLE_TARGET_PATHS.dup
78
+ paths << ENV['CONTRAST_CONFIG_PATH'] if ENV['CONTRAST_CONFIG_PATH']
79
+ paths.each do |path|
80
+ EXT.each_value do |extension|
81
+ effective_config = "#{ path }#{ file_name }.#{ extension }"
82
+ found = effective_config if File.exist?(effective_config)
83
+ end
84
+ end
85
+ found
86
+ end
87
+
88
+ # Create new config file to the default destination.
89
+ #
90
+ def create
91
+ # rubocop:disable Rails/Output
92
+ puts("\u{1F48E} Generating: Contrast Configuration file.")
93
+ if Contrast::Config::YamlFile.created?
94
+ puts("\u{2705} Configuration file already exists: #{ Contrast::Config::YamlFile.find! }")
95
+ else
96
+ File.open(Contrast::Config::YamlFile.target_path, 'w') do |file|
97
+ file.write(HEADER)
98
+ file.write(YAML.dump(DEFAULT_CONFIG).gsub('---', ' '))
99
+ file.write(COMMENT)
100
+ file.write(FOOTER)
101
+ file.close
102
+ end
103
+
104
+ puts("\u{2728} Created! path #{ Contrast::Config::YamlFile.target_path }\n")
105
+ puts("\nOpen the file and enter your Contrast Security api keys or set them via environment variables.\n")
106
+ puts('Visit our documentation for more details: ' \
107
+ 'https://docs.contrastsecurity.com/en/ruby-configuration.html')
108
+ end
109
+ rescue StandardError => e
110
+ puts("\u{2757} WARNING configuration could not be created due to error: '#{ e }'. " \
111
+ "Try created in manually by running 'bundle exec rake contrast:config:create'.")
112
+ # rubocop:enable Rails/Output
113
+ end
114
+
115
+ def target_path
116
+ File.join(execution_directory, "#{ file_name }.#{ EXT[:yml] }")
117
+ end
118
+
119
+ def execution_directory
120
+ Dir.pwd
121
+ end
122
+
123
+ def file_name
124
+ ENV['CONTRAST_YAML_FILE_TEST_CREATE_CONFIG_FILE_NAME_VALUE'] || CONFIG_FILE_NAME
125
+ end
126
+ end
127
+ end
128
+ end
129
+ end
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2023 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/agent/at_exit_hook'
4
+ require 'contrast/agent/hooks/at_exit_hook'
5
5
 
6
6
  module Contrast
7
7
  module Extension
@@ -14,9 +14,6 @@ module Contrast
14
14
  # Contrast::Agent::Assess::Policy::Propagator molds without cluttering up the
15
15
  # String Class or exposing our methods there.
16
16
  class StringPropagator
17
- extend Contrast::Components::Logger::InstanceMethods
18
- extend Contrast::Components::Scope::InstanceMethods
19
-
20
17
  NODE_HASH = {
21
18
  'class_name' => 'String',
22
19
  'instance_method' => true,
@@ -31,6 +28,8 @@ module Contrast
31
28
  INTERPOLATION_NODE = Contrast::Agent::Assess::Policy::PropagationNode.new(NODE_HASH)
32
29
 
33
30
  class << self
31
+ include Contrast::Components::Logger::InstanceMethods
32
+ include Contrast::Components::Scope::InstanceMethods
34
33
  # We call this method from C, and the Scope check is happening there. If we are in
35
34
  # Contrast Scope the method won't be invoked.
36
35
  #
@@ -76,6 +75,8 @@ module Contrast
76
75
  return unless (dynamic_props = Contrast::Agent::Assess::Tracker.properties(source)&.properties)
77
76
 
78
77
  Contrast::Agent::Assess::Tracker.properties(target)&.add_properties(dynamic_props)
78
+ rescue StandardError => e
79
+ logger.error('Unable to copy Dynamic track interpolation', e)
79
80
  end
80
81
  end
81
82
  end
@@ -1,47 +1,22 @@
1
1
  # Copyright (c) 2023 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- require 'yaml'
5
- require 'contrast/configuration'
6
- require 'contrast/agent/reporting/reporter'
4
+ require 'contrast/config/yaml_file'
5
+ require 'contrast/config/validate'
7
6
 
8
7
  module Contrast
9
8
  # A Rake task to generate a contrast_security.yaml file with some basic settings
10
9
  module Config
11
10
  extend Rake::DSL
12
- DEFAULT_CONFIG = {
13
- 'api' => {
14
- 'url' => 'Enter your Contrast URL ex: https://app.contrastsecurity.com/Contrast',
15
- 'api_key' => 'Enter your Contrast api key',
16
- 'service_key' => 'Enter your Contrast service key',
17
- 'user_name' => 'Enter your Contrast user name'
18
- },
19
- 'agent' => {
20
- 'logger' => {
21
- 'level' => 'ERROR',
22
- 'path' => 'contrast_agent.log'
23
- }
24
- }
25
- }.cs__freeze
26
-
27
- SKIP_LOG = %w[service_key api_key].cs__freeze
28
- REQUIRED = %i[url api_key service_key user_name].cs__freeze
11
+ # The file create methods are required in the gemspec. Some of the Agent functions are not
12
+ # available there. To be safe the validate mechanics are extracted in different module.
13
+ extend Contrast::Config::Validate
29
14
 
30
15
  namespace :contrast do
31
16
  namespace :config do
32
17
  desc 'Create a contrast_security.yaml in the applications root directory'
33
18
  task :create do
34
- execution_directory = Dir.pwd
35
- target_path = File.join(execution_directory, 'contrast_security.yaml')
36
- if File.exist?(target_path)
37
- puts 'WARNING: contrast_security.yaml already exists'
38
- else
39
- File.write(target_path, YAML.dump(DEFAULT_CONFIG))
40
-
41
- puts "Created contrast_security.yaml at #{ target_path }"
42
- puts 'Open the file and enter your Contrast Security api keys or set them via environment variables'
43
- puts 'Visit our documentation site for more details: https://docs.contrastsecurity.com/installation-rubyconfig.html'
44
- end
19
+ Contrast::Config::YamlFile.create
45
20
  end
46
21
  end
47
22
  end
@@ -50,94 +25,8 @@ module Contrast
50
25
  namespace :config do
51
26
  desc 'Validate the provided Contrast configuration and confirm connectivity'
52
27
  task validate: :environment do
53
- puts 'Validating Agent Configuration...'
54
- Contrast::Config.validate_config
55
- puts '...done!'
56
- puts 'Validating Contrast Reporter Headers...'
57
- reporter = Contrast::Config.validate_headers
58
- puts '...done!'
59
- puts 'Testing Reporter Client Connection...'
60
- Contrast::Config.test_connection(reporter) if reporter
61
- puts '...done!'
62
- end
63
- end
64
-
65
- def self.validate_config
66
- config = Contrast::Configuration.new
67
- abort('Unable to Build Config') unless config
68
- missing = []
69
-
70
- api_hash = config.api.to_contrast_hash
71
-
72
- api_hash.each_key do |key|
73
- value = mask_keys(api_hash, key)
74
- if value.is_a?(Contrast::Config::ApiProxyConfiguration)
75
- Contrast::Config.validate_proxy(value)
76
- elsif value.is_a?(Contrast::Config::CertificationConfiguration)
77
- Contrast::Config.validate_cert(value)
78
- next
79
- elsif value.is_a?(Contrast::Config::RequestAuditConfiguration)
80
- Contrast::Config.validate_audit(value)
81
- next
82
- elsif value.nil? && REQUIRED.includes?(key.to_sym)
83
- missing << key
84
- end
85
- end
86
- abort("Missing required API configuration values: #{ missing.join(', ') }") unless missing.empty?
87
- end
88
-
89
- def self.validate_proxy config
90
- puts("Proxy Enabled: #{ config.enable }")
91
- return unless config.enable
92
-
93
- puts("Proxy URL: #{ config.url }")
94
- abort('Proxy Enabled but no Proxy URL given') unless config.url
95
- end
96
-
97
- def self.validate_cert config
98
- puts("Certification Enabled: #{ config.enable }")
99
- return unless config.enable
100
-
101
- puts("CA File: #{ config.ca_file }")
102
- abort('CA file path not provided') unless config.ca_file
103
- puts("Cert File: #{ config.cert_file }")
104
- abort('Cert file path not provided') unless config.cert_file
105
- puts("Key File: #{ config.key_file }")
106
- abort('Key file path not provided') unless config.key_file
107
- end
108
-
109
- def self.validate_audit config
110
- puts("Request Audit Enabled: #{ config.enable }")
111
- return unless config.enable
112
-
113
- config.each do |k, v|
114
- puts("#{ k }::#{ v }")
115
- end
116
- end
117
-
118
- def self.validate_headers
119
- missing = []
120
- reporter = Contrast::Agent::Reporter.new
121
- reporter_headers = reporter.client.headers.to_contrast_hash
122
- reporter_headers.each_key do |key|
123
- value = mask_keys(reporter_headers, key)
124
- missing << key if value.nil?
28
+ validate_file
125
29
  end
126
- abort("Missing required header values: #{ missing.join(', ') }") unless missing.empty?
127
- reporter
128
- end
129
-
130
- def self.test_connection reporter
131
- connection = reporter.connection
132
- abort('Failed to Initialize Connection please check error logs for details') unless connection
133
- abort('Failed to Start Client please check error logs for details') unless reporter.client.startup!(connection)
134
- end
135
-
136
- def self.mask_keys hash, key
137
- value = hash[key]
138
- redacted_value = Contrast::Configuration::REDACTED if SKIP_LOG.include?(key.to_s)
139
- puts("#{ key }::#{ redacted_value || value }") unless value.is_a?(Contrast::Config::BaseConfiguration)
140
- value
141
30
  end
142
31
  end
143
32
  end
@@ -1,6 +1,8 @@
1
1
  # Copyright (c) 2023 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/config/yaml_file'
5
+
4
6
  module Contrast
5
7
  module Utils
6
8
  # helper methods for Contrast::Agent::Middleware
@@ -16,6 +18,8 @@ module Contrast
16
18
  "April #{ LANGUAGE_DEPRECATION_YEAR }. Please contact Customer Support prior if you require continued support."
17
19
 
18
20
  def setup_agent
21
+ # Generate new config file if one is not already created:
22
+ Contrast::Config::YamlFile.create unless Contrast::Config::YamlFile.created?
19
23
  ::Contrast::SETTINGS.reset_state
20
24
 
21
25
  inform_deprecations
data/lib/contrast.rb CHANGED
@@ -62,7 +62,7 @@ require 'contrast/components/scope'
62
62
  require 'contrast/components/settings'
63
63
  require 'contrast/utils/routes_sent'
64
64
  require 'contrast/agent/telemetry/hash'
65
- require 'contrast/agent/telemetry'
65
+ require 'contrast/agent/telemetry/telemetry'
66
66
  require 'contrast/agent/telemetry/exception/event'
67
67
  require 'contrast/agent_lib/interface'
68
68
 
data/ruby-agent.gemspec CHANGED
@@ -2,6 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require_relative './lib/contrast/agent/version'
5
+ require_relative './lib/contrast/config/yaml_file'
5
6
 
6
7
  lib = File.expand_path('lib', __dir__)
7
8
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
@@ -119,10 +120,12 @@ end
119
120
  # dependencies.csv in this directory to indicate that and create a
120
121
  # corresponding update to the fake gem server data in TeamServer.
121
122
  def self.add_dependencies spec
123
+ spec.add_dependency 'ffi', '~> 1.0'
122
124
  spec.add_dependency 'ougai', '>= 1.8', '< 3.0.0'
123
125
  spec.add_dependency 'rack', '~> 2.0'
124
- spec.add_dependency 'contrast-agent-lib', '~> 0.1.0', '>= 0.1.3'
125
- spec.add_dependency 'ffi', '~> 1.0'
126
+
127
+ # bind this directly as we've had issues w/ build changes on bug release
128
+ spec.add_dependency 'contrast-agent-lib', '1.1.0'
126
129
  end
127
130
 
128
131
  # Enumerate the files required to build the Agent.
@@ -185,7 +188,7 @@ Gem::Specification.new do |spec|
185
188
  spec.extensions = Dir['ext/cs__common/extconf.rb', 'ext/**/extconf.rb']
186
189
  spec.require_paths = ['lib']
187
190
 
188
- unless File.exist?(File.join(Dir.pwd, 'contrast_security.yaml'))
191
+ unless Contrast::Config::YamlFile.created?
189
192
  spec.post_install_message = 'To generate the required contrast_security.yaml file you can run: '\
190
193
  'bundle exec rake contrast:config:create'
191
194
  end