contrast-agent 3.11.0 → 3.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.flayignore +1 -0
- data/ext/cs__assess_active_record_named/cs__active_record_named.c +7 -2
- data/ext/cs__assess_active_record_named/cs__active_record_named.h +1 -0
- data/ext/cs__assess_array/cs__assess_array.c +2 -1
- data/ext/cs__assess_array/cs__assess_array.h +1 -0
- data/ext/cs__assess_basic_object/cs__assess_basic_object.c +3 -7
- data/ext/cs__assess_basic_object/cs__assess_basic_object.h +2 -1
- data/ext/cs__assess_kernel/cs__assess_kernel.c +1 -1
- data/ext/cs__assess_module/cs__assess_module.c +5 -7
- data/ext/cs__assess_module/cs__assess_module.h +3 -0
- data/ext/cs__common/cs__common.c +1 -1
- data/ext/cs__protect_kernel/cs__protect_kernel.c +4 -2
- data/ext/cs__protect_kernel/cs__protect_kernel.h +1 -0
- data/funchook/autom4te.cache/output.0 +13 -1
- data/funchook/autom4te.cache/requests +49 -48
- data/funchook/autom4te.cache/traces.0 +3 -0
- data/funchook/config.log +217 -378
- data/funchook/config.status +24 -23
- data/funchook/configure +13 -1
- data/funchook/src/Makefile +7 -7
- data/funchook/src/config.h +2 -2
- data/funchook/src/decoder.o +0 -0
- data/funchook/src/distorm.o +0 -0
- data/funchook/src/funchook.o +0 -0
- data/funchook/src/funchook_io.o +0 -0
- data/funchook/src/funchook_syscall.o +0 -0
- data/funchook/src/funchook_unix.o +0 -0
- data/funchook/src/funchook_x86.o +0 -0
- data/funchook/src/instructions.o +0 -0
- data/funchook/src/insts.o +0 -0
- data/funchook/src/libfunchook.so +0 -0
- data/funchook/src/mnemonics.o +0 -0
- data/funchook/src/operands.o +0 -0
- data/funchook/src/os_func.o +0 -0
- data/funchook/src/os_func_unix.o +0 -0
- data/funchook/src/prefix.o +0 -0
- data/funchook/src/printf_base.o +0 -0
- data/funchook/src/textdefs.o +0 -0
- data/funchook/src/wstring.o +0 -0
- data/funchook/test/Makefile +2 -2
- data/funchook/test/funchook_test +0 -0
- data/funchook/test/libfunchook_test.so +0 -0
- data/funchook/test/test_main.o +0 -0
- data/funchook/test/x86_64_test.o +0 -0
- data/lib/contrast.rb +0 -1
- data/lib/contrast/agent.rb +19 -22
- data/lib/contrast/agent/assess.rb +0 -9
- data/lib/contrast/agent/assess/policy/patcher.rb +1 -0
- data/lib/contrast/agent/assess/policy/policy_node.rb +1 -1
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagation_method.rb +3 -0
- data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/database_write.rb +1 -3
- data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +90 -0
- data/lib/contrast/agent/assess/policy/trigger/xpath.rb +57 -0
- data/lib/contrast/agent/assess/policy/trigger_method.rb +3 -7
- data/lib/contrast/agent/assess/policy/trigger_node.rb +4 -1
- data/lib/contrast/agent/assess/rule/base.rb +0 -15
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +22 -5
- data/lib/contrast/agent/assess/rule/redos.rb +0 -1
- data/lib/contrast/agent/at_exit_hook.rb +2 -2
- data/lib/contrast/agent/class_reopener.rb +9 -4
- data/lib/contrast/agent/exclusion_matcher.rb +0 -1
- data/lib/contrast/agent/inventory/policy/datastores.rb +54 -0
- data/lib/contrast/agent/inventory/policy/policy.rb +1 -1
- data/lib/contrast/agent/middleware.rb +38 -34
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +11 -2
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +51 -56
- data/lib/contrast/agent/patching/policy/patch.rb +2 -1
- data/lib/contrast/agent/patching/policy/patcher.rb +10 -12
- data/lib/contrast/agent/patching/policy/policy_node.rb +1 -1
- data/lib/contrast/agent/patching/policy/trigger_node.rb +1 -1
- data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +63 -0
- data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +52 -0
- data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +68 -0
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +117 -0
- data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +54 -0
- data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +129 -0
- data/lib/contrast/agent/protect/policy/policy.rb +6 -6
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +51 -0
- data/lib/contrast/agent/protect/rule.rb +0 -5
- data/lib/contrast/agent/protect/rule/base.rb +6 -5
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +3 -3
- data/lib/contrast/agent/protect/rule/path_traversal.rb +2 -7
- data/lib/contrast/agent/protect/rule/sqli.rb +4 -4
- data/lib/contrast/agent/railtie.rb +1 -0
- data/lib/contrast/agent/request.rb +2 -6
- data/lib/contrast/agent/request_context.rb +5 -6
- data/lib/contrast/agent/request_handler.rb +2 -2
- data/lib/contrast/agent/response.rb +0 -69
- data/lib/contrast/agent/service_heartbeat.rb +2 -2
- data/lib/contrast/agent/socket_client.rb +8 -8
- data/lib/contrast/agent/static_analysis.rb +2 -3
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/api/decorators/application_settings.rb +1 -1
- data/lib/contrast/api/speedracer.rb +1 -1
- data/lib/contrast/components/agent.rb +17 -12
- data/lib/contrast/components/app_context.rb +33 -1
- data/lib/contrast/components/assess.rb +25 -15
- data/lib/contrast/components/contrast_service.rb +23 -67
- data/lib/contrast/components/interface.rb +4 -12
- data/lib/contrast/components/inventory.rb +5 -1
- data/lib/contrast/components/logger.rb +2 -2
- data/lib/contrast/components/protect.rb +40 -4
- data/lib/contrast/components/scope.rb +2 -52
- data/lib/contrast/components/settings.rb +24 -18
- data/lib/contrast/config/protect_rules_configuration.rb +0 -1
- data/lib/contrast/{extensions/ruby_core → extension}/assess.rb +12 -14
- data/lib/contrast/extension/assess/array.rb +77 -0
- data/lib/contrast/{extensions/ruby_core → extension}/assess/assess_extension.rb +2 -2
- data/lib/contrast/{extensions/ruby_core → extension}/assess/erb.rb +0 -0
- data/lib/contrast/extension/assess/eval_trigger.rb +78 -0
- data/lib/contrast/{extensions/ruby_core → extension}/assess/exec_trigger.rb +1 -1
- data/lib/contrast/{extensions/ruby_core → extension}/assess/fiber.rb +6 -5
- data/lib/contrast/{extensions/ruby_core → extension}/assess/hash.rb +2 -2
- data/lib/contrast/extension/assess/kernel.rb +110 -0
- data/lib/contrast/{extensions/ruby_core → extension}/assess/regexp.rb +4 -4
- data/lib/contrast/{extensions/ruby_core → extension}/assess/string.rb +5 -5
- data/lib/contrast/{extensions/ruby_core → extension}/delegator.rb +0 -0
- data/lib/contrast/{extensions/ruby_core → extension}/inventory.rb +2 -2
- data/lib/contrast/extension/kernel.rb +54 -0
- data/lib/contrast/{extensions/ruby_core → extension}/module.rb +0 -0
- data/lib/contrast/{extensions/ruby_core → extension}/protect.rb +2 -2
- data/lib/contrast/extension/protect/kernel.rb +44 -0
- data/lib/contrast/{extensions/ruby_core → extension}/protect/psych.rb +1 -1
- data/lib/contrast/{extensions/ruby_core → extension}/thread.rb +0 -0
- data/lib/contrast/framework/base_support.rb +22 -0
- data/lib/contrast/framework/manager.rb +33 -8
- data/lib/contrast/framework/rack/patch/session_cookie.rb +126 -0
- data/lib/contrast/framework/rack/patch/support.rb +24 -0
- data/lib/contrast/framework/rack/support.rb +22 -0
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +43 -0
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +103 -0
- data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +31 -0
- data/lib/contrast/framework/rails/patch/support.rb +67 -0
- data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +34 -0
- data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +39 -0
- data/lib/contrast/framework/rails/rewrite/active_record_named.rb +73 -0
- data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +33 -0
- data/lib/contrast/framework/rails/support.rb +115 -0
- data/lib/contrast/framework/sinatra/application_helper.rb +51 -0
- data/lib/contrast/framework/sinatra/patch/base.rb +83 -0
- data/lib/contrast/framework/sinatra/patch/support.rb +27 -0
- data/lib/contrast/framework/sinatra/support.rb +109 -0
- data/lib/contrast/logger/application.rb +80 -0
- data/lib/contrast/{agent/logger.rb → logger/log.rb} +23 -54
- data/lib/contrast/logger/time.rb +50 -0
- data/lib/contrast/tasks/config.rb +54 -0
- data/lib/contrast/tasks/service.rb +1 -5
- data/lib/contrast/utils/class_util.rb +1 -1
- data/lib/contrast/utils/gemfile_reader.rb +2 -2
- data/lib/contrast/utils/hash_digest.rb +2 -7
- data/lib/contrast/utils/invalid_configuration_util.rb +3 -3
- data/lib/contrast/utils/job_servers_running.rb +4 -2
- data/lib/contrast/utils/object_share.rb +0 -1
- data/lib/contrast/utils/service_response_util.rb +14 -12
- data/lib/contrast/utils/service_sender_util.rb +78 -21
- data/resources/assess/policy.json +9 -50
- data/resources/inventory/policy.json +2 -2
- data/resources/protect/policy.json +6 -6
- data/ruby-agent.gemspec +5 -1
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +69 -83
- data/funchook/src/libfunchook.dylib +0 -0
- data/funchook/test/libfunchook_test.so.dSYM/Contents/Info.plist +0 -20
- data/funchook/test/libfunchook_test.so.dSYM/Contents/Resources/DWARF/libfunchook_test.so +0 -0
- data/lib/contrast/agent/assess/rule/csrf.rb +0 -66
- data/lib/contrast/agent/assess/rule/csrf/csrf_action.rb +0 -28
- data/lib/contrast/agent/assess/rule/csrf/csrf_applicator.rb +0 -53
- data/lib/contrast/agent/assess/rule/csrf/csrf_watcher.rb +0 -136
- data/lib/contrast/agent/assess/rule/response_scanning_rule.rb +0 -47
- data/lib/contrast/agent/assess/rule/response_watcher.rb +0 -36
- data/lib/contrast/agent/assess/rule/watcher.rb +0 -36
- data/lib/contrast/agent/feature_state.rb +0 -346
- data/lib/contrast/agent/protect/rule/csrf.rb +0 -119
- data/lib/contrast/agent/protect/rule/csrf/csrf_evaluator.rb +0 -100
- data/lib/contrast/agent/protect/rule/csrf/csrf_token_injector.rb +0 -85
- data/lib/contrast/agent/settings_state.rb +0 -88
- data/lib/contrast/api/decorators/exclusion.rb +0 -20
- data/lib/contrast/extensions/framework/rack/cookie.rb +0 -24
- data/lib/contrast/extensions/framework/rack/request.rb +0 -24
- data/lib/contrast/extensions/framework/rack/response.rb +0 -23
- data/lib/contrast/extensions/framework/rails/action_controller_inheritance.rb +0 -39
- data/lib/contrast/extensions/framework/rails/action_controller_railties_helper_inherited.rb +0 -20
- data/lib/contrast/extensions/framework/rails/active_record.rb +0 -26
- data/lib/contrast/extensions/framework/rails/active_record_named.rb +0 -58
- data/lib/contrast/extensions/framework/rails/active_record_time_zone_inherited.rb +0 -21
- data/lib/contrast/extensions/framework/rails/buffer.rb +0 -28
- data/lib/contrast/extensions/framework/rails/configuration.rb +0 -27
- data/lib/contrast/extensions/framework/sinatra/base.rb +0 -59
- data/lib/contrast/extensions/ruby_core/assess/array.rb +0 -59
- data/lib/contrast/extensions/ruby_core/assess/basic_object.rb +0 -15
- data/lib/contrast/extensions/ruby_core/assess/kernel.rb +0 -96
- data/lib/contrast/extensions/ruby_core/assess/module.rb +0 -14
- data/lib/contrast/extensions/ruby_core/assess/tilt_template_trigger.rb +0 -78
- data/lib/contrast/extensions/ruby_core/assess/xpath_library_trigger.rb +0 -40
- data/lib/contrast/extensions/ruby_core/eval_trigger.rb +0 -51
- data/lib/contrast/extensions/ruby_core/inventory/datastores.rb +0 -37
- data/lib/contrast/extensions/ruby_core/protect/applies_command_injection_rule.rb +0 -61
- data/lib/contrast/extensions/ruby_core/protect/applies_deserialization_rule.rb +0 -50
- data/lib/contrast/extensions/ruby_core/protect/applies_no_sqli_rule.rb +0 -66
- data/lib/contrast/extensions/ruby_core/protect/applies_path_traversal_rule.rb +0 -115
- data/lib/contrast/extensions/ruby_core/protect/applies_sqli_rule.rb +0 -53
- data/lib/contrast/extensions/ruby_core/protect/applies_xxe_rule.rb +0 -127
- data/lib/contrast/extensions/ruby_core/protect/kernel.rb +0 -30
- data/lib/contrast/extensions/ruby_core/protect/rule_applicator.rb +0 -50
- data/lib/contrast/framework/rails_support.rb +0 -104
- data/lib/contrast/framework/sinatra_application_helper.rb +0 -49
- data/lib/contrast/framework/sinatra_support.rb +0 -104
- data/lib/contrast/utils/data_store_util.rb +0 -23
- data/lib/contrast/utils/rack_assess_session_cookie.rb +0 -104
- data/lib/contrast/utils/rails_assess_configuration.rb +0 -95
- data/lib/contrast/utils/random_util.rb +0 -22
- data/resources/csrf/inject.js +0 -44
@@ -0,0 +1,54 @@
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
cs__scoped_require 'yaml'
|
5
|
+
|
6
|
+
module Contrast
|
7
|
+
# A Rake task to generate a contrast_security.yaml file with some basic settings
|
8
|
+
module Config
|
9
|
+
extend Rake::DSL
|
10
|
+
include Contrast::Components::Interface
|
11
|
+
DEFAULT_CONFIG = {
|
12
|
+
'api' => {
|
13
|
+
'url' => 'Enter your Contrast URL ex: https://app.contrastsecurity.com/Contrast',
|
14
|
+
'api_key' => 'Enter your Contrast api key',
|
15
|
+
'service_key' => 'Enter your Contrast service key',
|
16
|
+
'user_name' => 'Enter your Contrast user name'
|
17
|
+
},
|
18
|
+
'agent' => {
|
19
|
+
'service' => {
|
20
|
+
'logger' => {
|
21
|
+
'path' => 'contrast_service.log',
|
22
|
+
'level' => 'ERROR' # DEBUG | INFO | WARN | ERROR
|
23
|
+
},
|
24
|
+
'socket' => '/tmp/contrast_service.sock'
|
25
|
+
},
|
26
|
+
'logger' => {
|
27
|
+
'level' => 'ERROR',
|
28
|
+
'path' => 'contrast_agent.log'
|
29
|
+
}
|
30
|
+
}
|
31
|
+
}.cs__freeze
|
32
|
+
|
33
|
+
namespace :contrast do
|
34
|
+
namespace :config do
|
35
|
+
desc 'Create a contrast_security.yaml in the applications root directory'
|
36
|
+
task :create do
|
37
|
+
execution_directory = Dir.pwd
|
38
|
+
target_path = File.join(execution_directory, 'contrast_security.yaml')
|
39
|
+
if File.exist?(target_path)
|
40
|
+
puts 'WARNING: contrast_security.yaml already exists'
|
41
|
+
else
|
42
|
+
File.open(target_path, 'w') do |f|
|
43
|
+
f.write(YAML.dump(DEFAULT_CONFIG))
|
44
|
+
end
|
45
|
+
|
46
|
+
puts "Created contrast_security.yaml at #{ target_path }"
|
47
|
+
puts 'Open the file and enter your Contrast Security api keys or set them via environment variables'
|
48
|
+
puts 'Visit our documentation site for more details: https://docs.contrastsecurity.com/installation-rubyconfig.html'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -43,8 +43,6 @@ module Contrast
|
|
43
43
|
task :start do
|
44
44
|
if Contrast::Utils::OS.running?
|
45
45
|
puts 'Contrast Service already running. No need to start'
|
46
|
-
elsif !CONTRAST_SERVICE.enabled?
|
47
|
-
puts 'Contrast Service disabled by configuration. Not starting.'
|
48
46
|
else
|
49
47
|
start_service
|
50
48
|
end
|
@@ -58,10 +56,8 @@ module Contrast
|
|
58
56
|
task :status do
|
59
57
|
if Contrast::Utils::OS.running?
|
60
58
|
puts 'online'
|
61
|
-
elsif CONTRAST_SERVICE.enabled?
|
62
|
-
puts 'offline'
|
63
59
|
else
|
64
|
-
puts '
|
60
|
+
puts 'offline'
|
65
61
|
end
|
66
62
|
end
|
67
63
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
cs__scoped_require 'contrast/
|
4
|
+
cs__scoped_require 'contrast/extension/module'
|
5
5
|
cs__scoped_require 'contrast/utils/object_share'
|
6
6
|
|
7
7
|
module Contrast
|
@@ -92,11 +92,11 @@ module Contrast
|
|
92
92
|
usage = Contrast::Api::Dtm::LibraryUsageUpdate.new
|
93
93
|
usage.hash_code = Contrast::Utils::StringUtils.force_utf8(digest)
|
94
94
|
activity.library_usages[usage.hash_code] = usage if activity
|
95
|
-
# TODO:
|
95
|
+
# TODO: RUBY-882 once TS switches to take filenames, remove the count setter and
|
96
96
|
# send the class names in usage.class_names
|
97
97
|
usage.count = files.size
|
98
98
|
end
|
99
|
-
# TODO:
|
99
|
+
# TODO: RUBY-882 once TS switches to take filenames, clear this and remove the
|
100
100
|
# @updated variable
|
101
101
|
|
102
102
|
# @spec_to_files.clear
|
@@ -69,6 +69,8 @@ module Contrast
|
|
69
69
|
hash.finish
|
70
70
|
end
|
71
71
|
|
72
|
+
private
|
73
|
+
|
72
74
|
def generate_crypto_hash finding, algorithm
|
73
75
|
hash = new
|
74
76
|
hash.update(finding.rule_id)
|
@@ -85,13 +87,6 @@ module Contrast
|
|
85
87
|
hash.finish
|
86
88
|
end
|
87
89
|
|
88
|
-
def generate_response_hash finding
|
89
|
-
hash = new
|
90
|
-
hash.update(finding.rule_id)
|
91
|
-
hash.update_on_request
|
92
|
-
hash.finish
|
93
|
-
end
|
94
|
-
|
95
90
|
def generate_trigger_hash finding
|
96
91
|
hash = new
|
97
92
|
hash.update(finding.rule_id)
|
@@ -9,7 +9,7 @@ module Contrast
|
|
9
9
|
# customer applications, as determined by Configuration Rules at runtime.
|
10
10
|
module InvalidConfigurationUtil
|
11
11
|
include Contrast::Components::Interface
|
12
|
-
access_component :
|
12
|
+
access_component :analysis, :app_context, :logging
|
13
13
|
|
14
14
|
CS__PATH = 'path'
|
15
15
|
CS__SESSION_ID = 'sessionId'
|
@@ -45,9 +45,9 @@ module Contrast
|
|
45
45
|
activity.findings << finding
|
46
46
|
|
47
47
|
# If assess is enabled, we can just send the activity
|
48
|
-
if
|
48
|
+
if APP_CONTEXT.ready?
|
49
49
|
build_tags(activity)
|
50
|
-
|
50
|
+
Contrast::Utils::ServiceSenderUtil.push_to_ready_queue activity
|
51
51
|
# Otherwise, if the Agent isn't ready, we have to queue the messages
|
52
52
|
# until we know the starting state.
|
53
53
|
else
|
@@ -7,13 +7,15 @@ module Contrast
|
|
7
7
|
# the application are running
|
8
8
|
module JobServersRunning
|
9
9
|
include Contrast::Components::Interface
|
10
|
-
access_component :logging
|
10
|
+
access_component :app_context, :logging
|
11
11
|
|
12
12
|
class << self
|
13
13
|
def job_servers_running?
|
14
14
|
sidekiq_running? || rake_running?
|
15
15
|
end
|
16
16
|
|
17
|
+
private
|
18
|
+
|
17
19
|
def sidekiq_running?
|
18
20
|
return unless defined?(Sidekiq) && Sidekiq.cs__respond_to?(:server?) && Sidekiq.server?
|
19
21
|
|
@@ -26,7 +28,7 @@ module Contrast
|
|
26
28
|
Rake.cs__respond_to?(:application) &&
|
27
29
|
Rake.application.cs__respond_to?(:top_level_tasks)
|
28
30
|
|
29
|
-
disabled_rake_tasks =
|
31
|
+
disabled_rake_tasks = APP_CONTEXT.disabled_agent_rake_tasks
|
30
32
|
has_disabled_task = Rake.application.top_level_tasks.any? { |top_level_task| disabled_rake_tasks.include?(top_level_task) }
|
31
33
|
return false unless has_disabled_task
|
32
34
|
|
@@ -1,7 +1,8 @@
|
|
1
1
|
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
cs__scoped_require 'contrast/
|
4
|
+
cs__scoped_require 'contrast/logger/log'
|
5
|
+
cs__scoped_require 'contrast/agent/reaction_processor'
|
5
6
|
cs__scoped_require 'contrast/components/interface'
|
6
7
|
cs__scoped_require 'contrast/utils/assess/sampling_util'
|
7
8
|
|
@@ -11,13 +12,16 @@ module Contrast
|
|
11
12
|
# processes Server and Application settings and updates the Settings component.
|
12
13
|
module ServiceResponseUtil
|
13
14
|
include Contrast::Components::Interface
|
14
|
-
access_component :
|
15
|
+
access_component :agent, :analysis, :logging, :settings
|
15
16
|
|
16
17
|
class << self
|
17
|
-
#
|
18
|
+
# Return true if the agent has processed a response from the service
|
19
|
+
def update_received?
|
20
|
+
@_last_update.nil?
|
21
|
+
end
|
22
|
+
|
18
23
|
def process_response response
|
19
|
-
|
20
|
-
fs.last_update = response&.sent_ms
|
24
|
+
@_last_update = response&.sent_ms
|
21
25
|
|
22
26
|
server_features = process_server_response(response)
|
23
27
|
app_settings = process_application_response(response)
|
@@ -25,17 +29,13 @@ module Contrast
|
|
25
29
|
# ReactionProcessor is a design pattern from TeamServer.
|
26
30
|
# Right now, there's one potential reaction, which is disabling the agent
|
27
31
|
Contrast::Agent::ReactionProcessor.process(response&.application_settings)
|
28
|
-
# Determine new accumulator state
|
29
|
-
if (new_accum = response&.accumulator_settings)
|
30
|
-
SETTINGS.accumulator_settings.replace(new_accum)
|
31
|
-
end
|
32
32
|
|
33
|
-
Contrast::
|
33
|
+
Contrast::Logger::Log.instance.update(server_features&.log_file, server_features&.log_level)
|
34
34
|
update_features(server_features, app_settings)
|
35
35
|
logger.trace(
|
36
36
|
'Agent settings updated in response to Service',
|
37
|
-
protect_on:
|
38
|
-
assess_on:
|
37
|
+
protect_on: PROTECT.enabled?,
|
38
|
+
assess_on: ASSESS.enabled?)
|
39
39
|
end
|
40
40
|
|
41
41
|
private
|
@@ -68,10 +68,12 @@ module Contrast
|
|
68
68
|
# I don't think it should go into contrast_service because that only handles connection specific data
|
69
69
|
def update_features server_features, app_settings
|
70
70
|
return unless !!(server_features || app_settings)
|
71
|
+
return unless AGENT.enabled?
|
71
72
|
|
72
73
|
logger.trace_with_time('Rebuilding rule modes') do
|
73
74
|
SETTINGS.build_protect_rules if PROTECT.enabled?
|
74
75
|
SETTINGS.build_assess_rules if ASSESS.enabled?
|
76
|
+
AGENT.reset_ruleset
|
75
77
|
|
76
78
|
logger.info('Current rule settings:')
|
77
79
|
PROTECT.rules.each { |k, v| logger.info('Protect Rule mode set', rule: k, mode: v.mode) }
|
@@ -13,11 +13,9 @@ module Contrast
|
|
13
13
|
# to SpeedRacer.
|
14
14
|
module ServiceSenderUtil
|
15
15
|
include Contrast::Components::Interface
|
16
|
-
access_component :
|
16
|
+
access_component :analysis, :app_context, :logging, :settings
|
17
17
|
|
18
18
|
class << self
|
19
|
-
attr_reader :assess_messages, :ready_messages_queue
|
20
|
-
|
21
19
|
# Push the given DTM into a queue to be sent to the Service.
|
22
20
|
#
|
23
21
|
# @param event [Contrast::Api::Dtm] One of the DTMs valid for the event field of
|
@@ -25,30 +23,42 @@ module Contrast
|
|
25
23
|
def push_to_ready_queue event
|
26
24
|
return unless event
|
27
25
|
|
28
|
-
|
29
|
-
# the queue on first message sent
|
30
|
-
@ready_messages_queue ||= Queue.new
|
26
|
+
prep_queue
|
31
27
|
ready_messages_queue.push event
|
32
28
|
logger.debug('Enqueued event',
|
33
29
|
event_id: event.__id__,
|
34
|
-
event_type: event.cs__class.name
|
30
|
+
event_type: event.cs__class.name,
|
31
|
+
queue: ready_messages_queue.__id__,
|
32
|
+
length: ready_messages_queue.length)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Bypass the queue and send the message directly to SpeedRacer. This is the only way
|
36
|
+
# to receive the response object back from SpeedRacer. An invoking method that needs
|
37
|
+
# to process the response object with custom logic should use this method.
|
38
|
+
#
|
39
|
+
# @param event [Contrast::Api::Dtm] One of the DTMs valid for the event
|
40
|
+
# field of Contrast::Api::Dtm::Message
|
41
|
+
# @return [Array<Contrast::Api::Dtm::AttackResult>] the response from SpeedRacer
|
42
|
+
def send_event_immediately event
|
43
|
+
client.send_to_speedracer(event) if event
|
35
44
|
end
|
36
45
|
|
37
46
|
def sending_thread
|
38
|
-
|
39
|
-
@ready_messages_queue ||= Queue.new
|
40
|
-
@assess_messages ||= []
|
47
|
+
return @_sender_thread if @_sender_thread
|
41
48
|
|
49
|
+
# in case we got here before a message attempted to be sent, let's make sure these are initialized
|
42
50
|
@_sender_thread ||= Contrast::Agent::Thread.new do
|
43
51
|
loop do
|
44
|
-
check_assess_queue
|
52
|
+
check_assess_queue
|
45
53
|
# if ready messages queue is empty, calling thread is suspended until a message is pushed onto queue
|
46
54
|
event = ready_messages_queue.pop
|
47
55
|
begin
|
48
56
|
logger.debug('Dequeued event',
|
49
57
|
event_id: event.__id__,
|
50
|
-
event_type: event.cs__class.name
|
51
|
-
|
58
|
+
event_type: event.cs__class.name,
|
59
|
+
queue: ready_messages_queue.__id__,
|
60
|
+
length: ready_messages_queue.length)
|
61
|
+
response = client.send_to_speedracer(event)
|
52
62
|
Contrast::Utils::ServiceResponseUtil.process_response(response) if response
|
53
63
|
rescue StandardError => e
|
54
64
|
logger.error('Could not send message to service from service sender thread.', e)
|
@@ -64,17 +74,64 @@ module Contrast
|
|
64
74
|
end
|
65
75
|
|
66
76
|
def add_to_assess_messages msg
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
77
|
+
assess_messages! << msg
|
78
|
+
end
|
79
|
+
|
80
|
+
# Return true if the agent has connected with the service
|
81
|
+
def connection_established?
|
82
|
+
client.connection_established?
|
72
83
|
end
|
73
84
|
|
74
85
|
private
|
75
86
|
|
87
|
+
# TODO: RUBY-920
|
88
|
+
# If we've been forked, then we need to make sure the sender is set and
|
89
|
+
# alive. This is a temporary workaround to address issues in Passenger
|
90
|
+
# around forking and will be addressed next sprint.
|
91
|
+
def prep_queue
|
92
|
+
return if @_sender_thread&.alive?
|
93
|
+
|
94
|
+
@_sender_thread = nil
|
95
|
+
start
|
96
|
+
end
|
97
|
+
|
98
|
+
def ready_messages_queue
|
99
|
+
@_ready_messages_queue ||= begin
|
100
|
+
tmp = Queue.new
|
101
|
+
logger.debug('Creating new ready_messages_queue.',
|
102
|
+
queue: tmp.__id__,
|
103
|
+
length: tmp.length)
|
104
|
+
tmp
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def assess_messages!
|
109
|
+
unless @_assess_messages
|
110
|
+
logger.debug('Creating new assess messages queue by force.')
|
111
|
+
@_assess_messages = nil
|
112
|
+
end
|
113
|
+
assess_messages
|
114
|
+
end
|
115
|
+
|
116
|
+
# This list holds messages containing assess findings. We may not
|
117
|
+
# know if the agent is running in assess, so until we do then we
|
118
|
+
# must keep the messages stored here. Once we do know, we'll set this
|
119
|
+
# to `false` and rely on the standard ready_messages_queue
|
120
|
+
def assess_messages
|
121
|
+
if @_assess_messages.nil?
|
122
|
+
logger.debug('Creating new assess messages queue.')
|
123
|
+
@_assess_messages = []
|
124
|
+
end
|
125
|
+
@_assess_messages
|
126
|
+
end
|
127
|
+
|
128
|
+
def client
|
129
|
+
@_client ||= Contrast::Agent::SocketClient.new
|
130
|
+
end
|
131
|
+
|
76
132
|
def check_assess_queue
|
77
|
-
return unless
|
133
|
+
return unless assess_messages
|
134
|
+
return unless APP_CONTEXT.ready?
|
78
135
|
|
79
136
|
if ASSESS.enabled?
|
80
137
|
assess_messages.each do |msg|
|
@@ -82,7 +139,7 @@ module Contrast
|
|
82
139
|
ready_messages_queue.push msg # this message is ready to be sent to SR
|
83
140
|
end
|
84
141
|
end
|
85
|
-
@
|
142
|
+
@_assess_messages = false # clear out queue, we no longer need it
|
86
143
|
end
|
87
144
|
|
88
145
|
# When we queued up findings, we didn't have access to a configuration
|
@@ -101,7 +158,7 @@ module Contrast
|
|
101
158
|
end
|
102
159
|
|
103
160
|
msg.findings.each do |finding|
|
104
|
-
finding.session_id =
|
161
|
+
finding.session_id = SETTINGS.session_id
|
105
162
|
end
|
106
163
|
end
|
107
164
|
end
|
@@ -975,49 +975,8 @@
|
|
975
975
|
"method_visibility": "private",
|
976
976
|
"method_name": "sprintf",
|
977
977
|
"action": "CUSTOM",
|
978
|
-
"patch_class": "KernelPropagator",
|
978
|
+
"patch_class": "Contrast::Extension::Assess::KernelPropagator",
|
979
979
|
"patch_method": "sprintf_tagger"
|
980
|
-
}, {
|
981
|
-
"class_name":"SQLite3::Statement",
|
982
|
-
"instance_method": true,
|
983
|
-
"method_visibility": "private",
|
984
|
-
"method_name":"initialize",
|
985
|
-
"action": "CUSTOM",
|
986
|
-
"patch_class": "Contrast::Agent::Assess::Rule::Csrf::CsrfApplicator",
|
987
|
-
"patch_method": "csrf_tagger",
|
988
|
-
"source": "P1"
|
989
|
-
}, {
|
990
|
-
"class_name":"PG::Connection",
|
991
|
-
"instance_method": true,
|
992
|
-
"method_visibility": "public",
|
993
|
-
"method_name":"sync_exec",
|
994
|
-
"action": "CUSTOM",
|
995
|
-
"patch_class": "Contrast::Agent::Assess::Rule::Csrf::CsrfApplicator",
|
996
|
-
"patch_method": "csrf_tagger"
|
997
|
-
}, {
|
998
|
-
"class_name":"PG::Connection",
|
999
|
-
"instance_method": true,
|
1000
|
-
"method_visibility": "public",
|
1001
|
-
"method_name":"sync_exec_params",
|
1002
|
-
"action": "CUSTOM",
|
1003
|
-
"patch_class": "Contrast::Agent::Assess::Rule::Csrf::CsrfApplicator",
|
1004
|
-
"patch_method": "csrf_tagger"
|
1005
|
-
}, {
|
1006
|
-
"class_name":"PG::Connection",
|
1007
|
-
"instance_method": true,
|
1008
|
-
"method_visibility": "public",
|
1009
|
-
"method_name":"async_exec",
|
1010
|
-
"action": "CUSTOM",
|
1011
|
-
"patch_class": "Contrast::Agent::Assess::Rule::Csrf::CsrfApplicator",
|
1012
|
-
"patch_method": "csrf_tagger"
|
1013
|
-
}, {
|
1014
|
-
"class_name":"PG::Connection",
|
1015
|
-
"instance_method": true,
|
1016
|
-
"method_visibility": "public",
|
1017
|
-
"method_name":"async_exec_params",
|
1018
|
-
"action": "CUSTOM",
|
1019
|
-
"patch_class": "Contrast::Agent::Assess::Rule::Csrf::CsrfApplicator",
|
1020
|
-
"patch_method": "csrf_tagger"
|
1021
980
|
}, {
|
1022
981
|
"class_name":"ActiveRecord::ConnectionAdapters::Quoting",
|
1023
982
|
"instance_method": true,
|
@@ -1238,9 +1197,9 @@
|
|
1238
1197
|
"method_name": "evaluate",
|
1239
1198
|
"instance_method": true,
|
1240
1199
|
"method_visibility": "public",
|
1241
|
-
"source":"O",
|
1242
|
-
"trigger_class": "
|
1243
|
-
"trigger_method": "
|
1200
|
+
"source": "O",
|
1201
|
+
"trigger_class": "Contrast::Agent::Assess::Policy::Trigger::ReflectedXss",
|
1202
|
+
"trigger_method": "xss_tilt_trigger"
|
1244
1203
|
},
|
1245
1204
|
{
|
1246
1205
|
"class_name":"String",
|
@@ -1695,16 +1654,16 @@
|
|
1695
1654
|
"method_visibility": "private",
|
1696
1655
|
"method_name": "initialize",
|
1697
1656
|
"source": "P1",
|
1698
|
-
"trigger_class": "
|
1699
|
-
"trigger_method": "
|
1657
|
+
"trigger_class": "Contrast::Agent::Assess::Policy::Trigger::Xpath",
|
1658
|
+
"trigger_method": "xpath_expression_trigger"
|
1700
1659
|
}, {
|
1701
1660
|
"class_name": "Oga::XML::CharacterNode",
|
1702
1661
|
"instance_method": true,
|
1703
|
-
"method_visibility": "
|
1662
|
+
"method_visibility": "private",
|
1704
1663
|
"method_name": "initialize",
|
1705
1664
|
"source": "P0",
|
1706
|
-
"trigger_class": "
|
1707
|
-
"trigger_method": "
|
1665
|
+
"trigger_class": "Contrast::Agent::Assess::Policy::Trigger::Xpath",
|
1666
|
+
"trigger_method": "xpath_oga_trigger"
|
1708
1667
|
}, {
|
1709
1668
|
"class_name": "XPather",
|
1710
1669
|
"instance_method": true,
|