contrast-agent 6.15.3 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +1 -1
  3. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.h +1 -1
  4. data/ext/cs__assess_module/cs__assess_module.c +0 -19
  5. data/ext/cs__assess_test/cs__assess_tests.c +1 -1
  6. data/ext/cs__common/cs__common.c +17 -18
  7. data/ext/cs__common/cs__common.h +7 -11
  8. data/ext/cs__contrast_patch/cs__contrast_patch.c +16 -24
  9. data/ext/extconf_common.rb +79 -0
  10. data/lib/contrast/agent/assess/policy/policy.rb +1 -1
  11. data/lib/contrast/agent/assess/policy/source_method.rb +1 -0
  12. data/lib/contrast/agent/deadzone/policy/policy.rb +1 -1
  13. data/lib/contrast/agent/patching/policy/policy.rb +2 -2
  14. data/lib/contrast/agent/protect/input_analyzer/worth_watching_analyzer.rb +3 -0
  15. data/lib/contrast/agent/protect/rule/no_sqli/no_sqli.rb +1 -1
  16. data/lib/contrast/agent/reporting/reporter.rb +19 -4
  17. data/lib/contrast/agent/reporting/reporting_events/agent_effective_config.rb +32 -0
  18. data/lib/contrast/agent/reporting/reporting_utilities/endpoints.rb +7 -0
  19. data/lib/contrast/agent/reporting/reporting_utilities/headers.rb +3 -1
  20. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +11 -7
  21. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +15 -7
  22. data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +4 -2
  23. data/lib/contrast/agent/reporting/reporting_workers/application_server_worker.rb +3 -0
  24. data/lib/contrast/agent/reporting/reporting_workers/reporter_heartbeat.rb +3 -0
  25. data/lib/contrast/agent/reporting/reporting_workers/server_settings_worker.rb +3 -0
  26. data/lib/contrast/agent/telemetry/base.rb +37 -12
  27. data/lib/contrast/agent/telemetry/client.rb +1 -3
  28. data/lib/contrast/agent/telemetry/telemetry.rb +0 -7
  29. data/lib/contrast/agent/thread/thread_watcher.rb +2 -2
  30. data/lib/contrast/agent/version.rb +1 -1
  31. data/lib/contrast/components/agent.rb +1 -1
  32. data/lib/contrast/components/api.rb +3 -3
  33. data/lib/contrast/components/app_context.rb +1 -1
  34. data/lib/contrast/components/assess.rb +1 -1
  35. data/lib/contrast/components/assess_rules.rb +2 -2
  36. data/lib/contrast/components/base.rb +3 -3
  37. data/lib/contrast/components/config/sources.rb +12 -9
  38. data/lib/contrast/components/config.rb +2 -2
  39. data/lib/contrast/components/protect.rb +2 -2
  40. data/lib/contrast/components/sampling.rb +7 -5
  41. data/lib/contrast/components/settings.rb +1 -1
  42. data/lib/contrast/config/certification_configuration.rb +1 -1
  43. data/lib/contrast/config/configuration_files.rb +47 -0
  44. data/lib/contrast/config/diagnostics/command_line.rb +24 -0
  45. data/lib/contrast/config/{config.rb → diagnostics/config.rb} +21 -6
  46. data/lib/contrast/config/diagnostics/contrast_ui.rb +24 -0
  47. data/lib/contrast/config/diagnostics/effective_config.rb +28 -0
  48. data/lib/contrast/config/diagnostics/effective_config_value.rb +14 -0
  49. data/lib/contrast/config/diagnostics/environment_variables.rb +51 -0
  50. data/lib/contrast/config/{diagnostics.rb → diagnostics/monitor.rb} +10 -10
  51. data/lib/contrast/config/diagnostics/source_config_value.rb +51 -0
  52. data/lib/contrast/config/diagnostics/tools.rb +188 -0
  53. data/lib/contrast/config/diagnostics/user_configuration_file.rb +44 -0
  54. data/lib/contrast/config/request_audit_configuration.rb +1 -1
  55. data/lib/contrast/config/server_configuration.rb +1 -1
  56. data/lib/contrast/configuration.rb +90 -57
  57. data/lib/contrast/utils/hash_utils.rb +43 -0
  58. data/lib/contrast/utils/json.rb +46 -0
  59. data/lib/contrast/utils/middleware_utils.rb +4 -4
  60. data/lib/contrast/utils/net_http_base.rb +75 -26
  61. data/lib/contrast/utils/object_share.rb +3 -3
  62. data/lib/contrast.rb +0 -16
  63. data/ruby-agent.gemspec +4 -8
  64. metadata +40 -25
  65. data/lib/contrast/config/diagnostics_tools.rb +0 -99
  66. data/lib/contrast/config/effective_config.rb +0 -131
  67. data/lib/contrast/config/effective_config_value.rb +0 -32
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.15.3
4
+ version: 7.1.0
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: 2023-02-23 00:00:00.000000000 Z
16
+ date: 2023-04-13 00:00:00.000000000 Z
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
19
19
  name: bundler
@@ -277,6 +277,9 @@ dependencies:
277
277
  name: rails
278
278
  requirement: !ruby/object:Gem::Requirement
279
279
  requirements:
280
+ - - ">="
281
+ - !ruby/object:Gem::Version
282
+ version: '6'
280
283
  - - "~>"
281
284
  - !ruby/object:Gem::Version
282
285
  version: '7'
@@ -284,6 +287,9 @@ dependencies:
284
287
  prerelease: false
285
288
  version_requirements: !ruby/object:Gem::Requirement
286
289
  requirements:
290
+ - - ">="
291
+ - !ruby/object:Gem::Version
292
+ version: '6'
287
293
  - - "~>"
288
294
  - !ruby/object:Gem::Version
289
295
  version: '7'
@@ -305,16 +311,16 @@ dependencies:
305
311
  name: async
306
312
  requirement: !ruby/object:Gem::Requirement
307
313
  requirements:
308
- - - "~>"
314
+ - - ">="
309
315
  - !ruby/object:Gem::Version
310
- version: 1.30.3
316
+ version: '0'
311
317
  type: :development
312
318
  prerelease: false
313
319
  version_requirements: !ruby/object:Gem::Requirement
314
320
  requirements:
315
- - - "~>"
321
+ - - ">="
316
322
  - !ruby/object:Gem::Version
317
- version: 1.30.3
323
+ version: '0'
318
324
  - !ruby/object:Gem::Dependency
319
325
  name: execjs
320
326
  requirement: !ruby/object:Gem::Requirement
@@ -531,14 +537,14 @@ dependencies:
531
537
  requirements:
532
538
  - - '='
533
539
  - !ruby/object:Gem::Version
534
- version: '5.0'
540
+ version: '6.0'
535
541
  type: :development
536
542
  prerelease: false
537
543
  version_requirements: !ruby/object:Gem::Requirement
538
544
  requirements:
539
545
  - - '='
540
546
  - !ruby/object:Gem::Version
541
- version: '5.0'
547
+ version: '6.0'
542
548
  - !ruby/object:Gem::Dependency
543
549
  name: tzinfo-data
544
550
  requirement: !ruby/object:Gem::Requirement
@@ -678,22 +684,22 @@ email:
678
684
  executables: []
679
685
  extensions:
680
686
  - ext/cs__common/extconf.rb
681
- - ext/cs__assess_marshal_module/extconf.rb
682
- - ext/cs__assess_yield_track/extconf.rb
683
- - ext/cs__scope/extconf.rb
684
- - ext/cs__assess_kernel/extconf.rb
685
687
  - ext/cs__assess_array/extconf.rb
686
- - ext/cs__os_information/extconf.rb
687
- - ext/cs__assess_string/extconf.rb
688
+ - ext/cs__assess_basic_object/extconf.rb
689
+ - ext/cs__assess_fiber_track/extconf.rb
688
690
  - ext/cs__assess_hash/extconf.rb
689
- - ext/cs__assess_regexp/extconf.rb
691
+ - ext/cs__assess_kernel/extconf.rb
692
+ - ext/cs__assess_marshal_module/extconf.rb
690
693
  - ext/cs__assess_module/extconf.rb
694
+ - ext/cs__assess_regexp/extconf.rb
695
+ - ext/cs__assess_string/extconf.rb
691
696
  - ext/cs__assess_string_interpolation/extconf.rb
692
- - ext/cs__tests/extconf.rb
693
697
  - ext/cs__assess_test/extconf.rb
694
- - ext/cs__assess_fiber_track/extconf.rb
695
- - ext/cs__assess_basic_object/extconf.rb
698
+ - ext/cs__assess_yield_track/extconf.rb
696
699
  - ext/cs__contrast_patch/extconf.rb
700
+ - ext/cs__os_information/extconf.rb
701
+ - ext/cs__scope/extconf.rb
702
+ - ext/cs__tests/extconf.rb
697
703
  extra_rdoc_files: []
698
704
  files:
699
705
  - ".clang-format"
@@ -1073,6 +1079,7 @@ files:
1073
1079
  - lib/contrast/agent/reporting/masker/masker_utils.rb
1074
1080
  - lib/contrast/agent/reporting/report.rb
1075
1081
  - lib/contrast/agent/reporting/reporter.rb
1082
+ - lib/contrast/agent/reporting/reporting_events/agent_effective_config.rb
1076
1083
  - lib/contrast/agent/reporting/reporting_events/agent_startup.rb
1077
1084
  - lib/contrast/agent/reporting/reporting_events/application_activity.rb
1078
1085
  - lib/contrast/agent/reporting/reporting_events/application_defend_activity.rb
@@ -1218,11 +1225,17 @@ files:
1218
1225
  - lib/contrast/config/api_proxy_configuration.rb
1219
1226
  - lib/contrast/config/base_configuration.rb
1220
1227
  - lib/contrast/config/certification_configuration.rb
1221
- - lib/contrast/config/config.rb
1222
- - lib/contrast/config/diagnostics.rb
1223
- - lib/contrast/config/diagnostics_tools.rb
1224
- - lib/contrast/config/effective_config.rb
1225
- - lib/contrast/config/effective_config_value.rb
1228
+ - lib/contrast/config/configuration_files.rb
1229
+ - lib/contrast/config/diagnostics/command_line.rb
1230
+ - lib/contrast/config/diagnostics/config.rb
1231
+ - lib/contrast/config/diagnostics/contrast_ui.rb
1232
+ - lib/contrast/config/diagnostics/effective_config.rb
1233
+ - lib/contrast/config/diagnostics/effective_config_value.rb
1234
+ - lib/contrast/config/diagnostics/environment_variables.rb
1235
+ - lib/contrast/config/diagnostics/monitor.rb
1236
+ - lib/contrast/config/diagnostics/source_config_value.rb
1237
+ - lib/contrast/config/diagnostics/tools.rb
1238
+ - lib/contrast/config/diagnostics/user_configuration_file.rb
1226
1239
  - lib/contrast/config/env_variables.rb
1227
1240
  - lib/contrast/config/exception_configuration.rb
1228
1241
  - lib/contrast/config/protect_rule_configuration.rb
@@ -1291,12 +1304,14 @@ files:
1291
1304
  - lib/contrast/utils/findings.rb
1292
1305
  - lib/contrast/utils/hash_digest.rb
1293
1306
  - lib/contrast/utils/hash_digest_extend.rb
1307
+ - lib/contrast/utils/hash_utils.rb
1294
1308
  - lib/contrast/utils/head_dump_utils_extend.rb
1295
1309
  - lib/contrast/utils/heap_dump_util.rb
1296
1310
  - lib/contrast/utils/input_classification_base.rb
1297
1311
  - lib/contrast/utils/invalid_configuration_util.rb
1298
1312
  - lib/contrast/utils/io_util.rb
1299
1313
  - lib/contrast/utils/job_servers_running.rb
1314
+ - lib/contrast/utils/json.rb
1300
1315
  - lib/contrast/utils/log_utils.rb
1301
1316
  - lib/contrast/utils/lru_cache.rb
1302
1317
  - lib/contrast/utils/metrics_hash.rb
@@ -1342,7 +1357,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
1342
1357
  requirements:
1343
1358
  - - ">="
1344
1359
  - !ruby/object:Gem::Version
1345
- version: 2.7.0
1360
+ version: 3.0.0
1346
1361
  - - "<"
1347
1362
  - !ruby/object:Gem::Version
1348
1363
  version: 3.3.0
@@ -1352,7 +1367,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1352
1367
  - !ruby/object:Gem::Version
1353
1368
  version: '0'
1354
1369
  requirements: []
1355
- rubygems_version: 3.1.6
1370
+ rubygems_version: 3.2.33
1356
1371
  signing_key:
1357
1372
  specification_version: 4
1358
1373
  summary: Contrast Security's agent for rack-based applications.
@@ -1,99 +0,0 @@
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 'contrast/utils/object_share'
5
- require 'contrast/config/effective_config_value'
6
-
7
- module Contrast
8
- module Agent
9
- module DiagnosticsConfig
10
- # Diagnostics tools to be included in config components.
11
- module DiagnosticsTools
12
- CHECK = 'd'
13
-
14
- # Converts current configuration for array of values to effective config values class and appends them to
15
- # EffectiveConfig class. Must be used inside Config Components only.
16
- #
17
- # @param effective_config [Contrast::Agent::DiagnosticsConfig::EffectiveConfig]
18
- # @param config_values [Array<String>] array of the names of values.
19
- # @param canonical_prefix [String] starting of the path to config => api.proxy...
20
- # @param name_prefix [String] the name of the config prefix => contrast.api_key, contrast.url
21
- def add_effective_config_values effective_config, config_values, canonical_prefix, name_prefix
22
- return if config_values.to_s.empty?
23
-
24
- config_values.each do |config|
25
- Contrast::Agent::DiagnosticsConfig::EffectiveConfigValue.new.tap do |value|
26
- next if (config_val = send(config.to_sym)).to_s.empty?
27
-
28
- config_name = assign_name(config)
29
- value.canonical_name = "#{ canonical_prefix }.#{ config_name }"
30
- value.name = "#{ name_prefix }.#{ config_name }"
31
- value.value = config_val
32
- value.source = Contrast::CONFIG.sources.get(value.canonical_name)
33
- if value.source == Contrast::Components::Config::Sources::YAML
34
- value.filename = Contrast::CONFIG.config_file_path
35
- end
36
- effective_config.values << value
37
- rescue StandardError => e
38
- log_error(e)
39
- next
40
- end
41
- end
42
- end
43
-
44
- # Converts current configuration for single value to effective config values class and appends them to
45
- # EffectiveConfig class. Must be used inside Config Components only.
46
- #
47
- # @param effective_config [Contrast::Agent::DiagnosticsConfig::EffectiveConfig]
48
- # @param config_name [String] name of the config.
49
- # @param config_value [String, Boolean] value of the config.
50
- # @param canonical_prefix [String] starting of the path to config => api.proxy...
51
- # @param name_prefix [String] the name of the config prefix => contrast.api_key, contrast.url
52
- def add_single_effective_value effective_config, config_name, config_value, canonical_prefix, name_prefix
53
- Contrast::Agent::DiagnosticsConfig::EffectiveConfigValue.new.tap do |value|
54
- break if config_value.to_s.empty?
55
-
56
- value.value = config_value
57
- value.canonical_name = "#{ canonical_prefix }.#{ config_name }"
58
- value.name = "#{ name_prefix }.#{ config_name }"
59
- value.source = Contrast::CONFIG.sources.get(value.canonical_name)
60
- if value.source == Contrast::Components::Config::Sources::YAML
61
- value.filename = Contrast::CONFIG.config_file_path
62
- end
63
- effective_config.values << value
64
- rescue StandardError => e
65
- log_error(e)
66
- next
67
- end
68
- end
69
-
70
- private
71
-
72
- # Assigns a proper name for the config removing '?' out of method names.
73
- #
74
- # @param config [String] name of the configuration
75
- # @return [String]
76
- def assign_name config
77
- return Contrast::Utils::ObjectShare::EMPTY_STRING unless config
78
-
79
- name = config.dup
80
- if name.end_with?(Contrast::Utils::ObjectShare::QUESTION_MARK)
81
- # check and remove '?' : start_bundled_service? => start_bundled_service
82
- name.delete!(Contrast::Utils::ObjectShare::QUESTION_MARK)
83
- name.chop! if name.end_with?(CHECK)
84
- name
85
- end
86
- name
87
- end
88
-
89
- # Logs any caught error.
90
- #
91
- # @param error [StandardError]
92
- def log_error error
93
- Contrast::CONFIG.proto_logger.warn('Could not write effective config to file: ',
94
- error: error, backtrace: error.backtrace)
95
- end
96
- end
97
- end
98
- end
99
- end
@@ -1,131 +0,0 @@
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 'contrast/config/effective_config_value'
5
- require 'contrast/config/diagnostics_tools'
6
- require 'contrast/utils/object_share'
7
-
8
- module Contrast
9
- module Agent
10
- module DiagnosticsConfig
11
- # The current effective config received from all authorized configuration channels.
12
- class EffectiveConfig
13
- NON_COMMON_ENV = %w[CONTRAST_CONFIG_PATH CONTRAST_AGENT_TELEMETRY_OPTOUT].cs__freeze
14
-
15
- # Value of effective agent configurations
16
- #
17
- # @return [Array]
18
- attr_reader :values
19
-
20
- def initialize
21
- @values = []
22
- end
23
-
24
- def to_controlled_hash
25
- {
26
- effective_config: { values: @values&.map(&:to_controlled_hash) },
27
- user_configuration_file: yaml_config_settings,
28
- environment_variable: environment_settings(ENV).map(&:to_controlled_hash),
29
- command_line: command_line_settings.map(&:to_controlled_hash),
30
- contrast_ui: contrast_ui_settings.map(&:to_controlled_hash)
31
- }
32
- end
33
-
34
- private
35
-
36
- def yaml_config_settings
37
- {
38
- path: Contrast::CONFIG.config_file_path,
39
- values: value_to_s(Contrast::CONFIG.sources.for(Contrast::Components::Config::Sources::YAML))
40
- }
41
- end
42
-
43
- def command_line_settings
44
- cli = flatten_settings(Contrast::CONFIG.sources.for(Contrast::Components::Config::Sources::CLI))
45
- flat_settings(cli)
46
- end
47
-
48
- def contrast_ui_settings
49
- ui = flatten_settings(Contrast::CONFIG.sources.for(Contrast::Components::Config::Sources::CONTRASTUI))
50
- flat_settings(ui)
51
- end
52
-
53
- # @param flats [Array] of flatten configs produced by #flatten_settings
54
- # @return [Array]
55
- def flat_settings flats
56
- ui_settings = []
57
- flats.each do |entry|
58
- entry.each do |key, value|
59
- efc_value = Contrast::Agent::DiagnosticsConfig::EffectiveConfigValue.new.tap do |effective_value|
60
- effective_value.canonical_name = Contrast::Utils::ObjectShare::CONTRAST_DOT + key
61
- effective_value.name = key
62
- effective_value.value = value_to_s(value)
63
- end
64
- ui_settings << efc_value if efc_value
65
- end
66
- end
67
- ui_settings
68
- end
69
-
70
- def flatten_settings data, path = []
71
- data.each_with_object([]) do |(k, v), entries|
72
- if v.cs__is_a?(Hash)
73
- entries.concat(flatten_settings(v, path.dup.append(k.to_sym)))
74
- else
75
- entries << { "#{ path.join('.') }.#{ k }" => Contrast::CONFIG.config.loaded_config.dig(*path, k).to_s }
76
- end
77
- end.flatten # rubocop:disable Style/MethodCalledOnDoEndBlock
78
- end
79
-
80
- # This method will fill the canonical name for each env var and will check for any uncommon ones.
81
- #
82
- # @param env [Hash]
83
- # @return [Array] array of all the values needed to be written.
84
- def environment_settings env
85
- env_hash = env.select do |e|
86
- e.to_s.start_with?(Contrast::Components::Config::CONTRAST_ENV_MARKER) || NON_COMMON_ENV.include?(e.to_s)
87
- end
88
- environment_settings = []
89
- env_hash.each do |key, value|
90
- efc_value = Contrast::Agent::DiagnosticsConfig::EffectiveConfigValue.new.tap do |effective_value|
91
- next unless value
92
-
93
- effective_value.canonical_name = if NON_COMMON_ENV.include?(key)
94
- key.gsub(Contrast::Utils::ObjectShare::UNDERSCORE,
95
- Contrast::Utils::ObjectShare::PERIOD).downcase
96
- else
97
- key.gsub(Contrast::Utils::ObjectShare::DOUBLE_UNDERSCORE,
98
- Contrast::Utils::ObjectShare::PERIOD).downcase
99
- end
100
- if effective_value.canonical_name
101
- effective_value.name =
102
- effective_value.canonical_name.gsub(Contrast::Utils::ObjectShare::CONTRAST_DOT,
103
- Contrast::Utils::ObjectShare::EMPTY_STRING)
104
- end
105
- effective_value.value = value_to_s(value)
106
- end
107
- environment_settings << efc_value if efc_value
108
- end
109
- environment_settings
110
- end
111
-
112
- # Recursively converts each value to string.
113
- #
114
- # @param value [Hash]
115
- def value_to_s value
116
- return value if value.cs__is_a?(String)
117
-
118
- value.each_with_object({}) do |(k, v), m| # rubocop:disable Style/HashTransformValues
119
- m[k] = if v.cs__is_a?(Hash)
120
- value_to_s(v)
121
- elsif v.cs__is_a?(Array)
122
- v.map(&:to_s)
123
- else
124
- v.to_s
125
- end
126
- end
127
- end
128
- end
129
- end
130
- end
131
- end
@@ -1,32 +0,0 @@
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
- module Contrast
5
- module Agent
6
- module DiagnosticsConfig
7
- # All In effect config values stored in a easy to write representation.
8
- class EffectiveConfigValue
9
- # @return [String] Name of the config starting form root of yaml config.
10
- attr_accessor :canonical_name
11
- # @return [String] Name of the config.
12
- attr_accessor :name
13
- # @return [String] Value set for the config.
14
- attr_accessor :value
15
- # @return [String] The source for the entry in the config.
16
- attr_accessor :source
17
- # @return [String,nil] The filename for the source of the config, if the source was "yaml".
18
- attr_accessor :filename
19
-
20
- def to_controlled_hash
21
- {
22
- canonical_name: canonical_name,
23
- name: name, # rubocop:disable Security/Module/Name
24
- value: value&.cs__is_a?(Array) ? value.map(&:to_s) : value.to_s,
25
- source: source,
26
- filename: filename
27
- }.compact
28
- end
29
- end
30
- end
31
- end
32
- end