contrast-agent 3.11.0 → 3.13.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.dockerignore +0 -1
- data/.flayignore +1 -0
- data/.gitignore +1 -1
- data/.simplecov +1 -1
- data/Rakefile +31 -0
- data/ext/build_funchook.rb +0 -2
- 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_fiber_track/cs__assess_fiber_track.c +2 -8
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.h +0 -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__assess_string_interpolation26/cs__assess_string_interpolation26.c +1 -6
- data/ext/cs__assess_yield_track/cs__assess_yield_track.c +1 -5
- data/ext/cs__assess_yield_track/cs__assess_yield_track.h +0 -1
- data/ext/cs__common/cs__common.c +25 -1
- data/ext/cs__common/cs__common.h +3 -0
- data/ext/cs__common/extconf.rb +0 -14
- data/ext/cs__protect_kernel/cs__protect_kernel.c +4 -2
- data/ext/cs__protect_kernel/cs__protect_kernel.h +1 -0
- data/ext/extconf_common.rb +0 -28
- data/lib/contrast.rb +3 -2
- data/lib/contrast/agent.rb +33 -24
- data/lib/contrast/agent/assess.rb +0 -9
- data/lib/contrast/agent/assess/contrast_event.rb +28 -167
- data/lib/contrast/agent/assess/events/source_event.rb +3 -7
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +1 -1
- data/lib/contrast/agent/assess/policy/patcher.rb +1 -0
- data/lib/contrast/agent/assess/policy/policy_node.rb +5 -99
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagation_method.rb +4 -2
- data/lib/contrast/agent/assess/policy/propagation_node.rb +5 -1
- data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
- 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/propagator/insert.rb +1 -4
- data/lib/contrast/agent/assess/policy/propagator/match_data.rb +9 -1
- data/lib/contrast/agent/assess/policy/propagator/remove.rb +6 -11
- data/lib/contrast/agent/assess/policy/propagator/select.rb +4 -4
- data/lib/contrast/agent/assess/policy/propagator/split.rb +2 -2
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +4 -4
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +6 -10
- data/lib/contrast/agent/assess/policy/source_method.rb +1 -2
- 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 +2 -14
- data/lib/contrast/agent/assess/policy/trigger_node.rb +20 -5
- data/lib/contrast/agent/assess/properties.rb +4 -382
- data/lib/contrast/agent/assess/property/evented.rb +78 -0
- data/lib/contrast/agent/assess/property/tagged.rb +339 -0
- data/lib/contrast/agent/assess/rule/base.rb +0 -15
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +5 -6
- data/lib/contrast/agent/assess/rule/redos.rb +0 -1
- data/lib/contrast/agent/assess/tag.rb +27 -12
- data/lib/contrast/agent/at_exit_hook.rb +4 -2
- data/lib/contrast/agent/class_reopener.rb +9 -4
- data/lib/contrast/agent/exclusion_matcher.rb +2 -3
- data/lib/contrast/agent/inventory/policy/datastores.rb +53 -0
- data/lib/contrast/agent/inventory/policy/policy.rb +1 -1
- data/lib/contrast/agent/middleware.rb +36 -44
- 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 +3 -2
- data/lib/contrast/agent/patching/policy/patcher.rb +10 -12
- data/lib/contrast/agent/patching/policy/policy.rb +3 -3
- data/lib/contrast/agent/patching/policy/policy_node.rb +3 -3
- 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 +25 -36
- data/lib/contrast/agent/protect/rule/base_service.rb +1 -1
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +3 -3
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +2 -7
- 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/protect/rule/xxe.rb +1 -0
- data/lib/contrast/agent/railtie.rb +1 -0
- data/lib/contrast/agent/reaction_processor.rb +3 -3
- data/lib/contrast/agent/request.rb +91 -334
- data/lib/contrast/agent/request_context.rb +17 -18
- data/lib/contrast/agent/request_handler.rb +2 -2
- data/lib/contrast/agent/response.rb +2 -83
- data/lib/contrast/agent/scope.rb +1 -1
- data/lib/contrast/agent/service_heartbeat.rb +8 -10
- data/lib/contrast/agent/static_analysis.rb +2 -3
- data/lib/contrast/agent/thread_watcher.rb +49 -0
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/agent/worker_thread.rb +24 -0
- data/lib/contrast/api.rb +3 -5
- data/lib/contrast/api/communication.rb +20 -0
- data/lib/contrast/api/communication/connection_status.rb +41 -0
- data/lib/contrast/api/communication/messaging_queue.rb +79 -0
- data/lib/contrast/{utils/service_response_util.rb → api/communication/response_processor.rb} +15 -22
- data/lib/contrast/api/communication/service_lifecycle.rb +61 -0
- data/lib/contrast/api/communication/socket.rb +45 -0
- data/lib/contrast/api/communication/socket_client.rb +76 -0
- data/lib/contrast/api/communication/speedracer.rb +111 -0
- data/lib/contrast/api/communication/tcp_socket.rb +31 -0
- data/lib/contrast/api/communication/unix_socket.rb +27 -0
- data/lib/contrast/api/decorators.rb +10 -0
- data/lib/contrast/api/decorators/address.rb +60 -0
- data/lib/contrast/api/decorators/application_settings.rb +7 -3
- data/lib/contrast/api/decorators/application_update.rb +0 -9
- data/lib/contrast/api/decorators/http_request.rb +139 -0
- data/lib/contrast/api/decorators/message.rb +75 -0
- data/lib/contrast/api/decorators/rasp_rule_sample.rb +28 -0
- data/lib/contrast/api/decorators/route_coverage.rb +57 -0
- data/lib/contrast/api/decorators/trace_event.rb +99 -0
- data/lib/contrast/api/decorators/trace_event_object.rb +57 -0
- data/lib/contrast/api/decorators/trace_event_signature.rb +46 -0
- data/lib/contrast/api/decorators/trace_taint_range.rb +51 -0
- data/lib/contrast/api/decorators/trace_taint_range_tags.rb +109 -0
- data/lib/contrast/api/decorators/user_input.rb +40 -0
- data/lib/contrast/components/agent.rb +17 -12
- data/lib/contrast/components/app_context.rb +27 -2
- data/lib/contrast/components/assess.rb +25 -15
- data/lib/contrast/components/config.rb +4 -9
- data/lib/contrast/components/contrast_service.rb +23 -67
- data/lib/contrast/components/interface.rb +5 -13
- 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 +18 -18
- data/lib/contrast/config/protect_rules_configuration.rb +0 -1
- data/lib/contrast/configuration.rb +2 -2
- data/lib/contrast/{extensions/ruby_core → extension}/assess.rb +12 -15
- data/lib/contrast/extension/assess/array.rb +77 -0
- data/lib/contrast/{extensions/ruby_core → extension}/assess/assess_extension.rb +3 -4
- 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 +7 -6
- 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 +6 -6
- data/lib/contrast/{extensions/ruby_core → extension}/delegator.rb +0 -0
- data/lib/contrast/{extensions/ruby_core → extension}/inventory.rb +2 -3
- 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 -23
- data/lib/contrast/framework/manager.rb +31 -15
- 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 +41 -0
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +102 -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 +86 -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 +98 -0
- data/lib/contrast/funchook/funchook.rb +45 -0
- data/lib/contrast/logger/application.rb +80 -0
- data/lib/contrast/logger/format.rb +51 -0
- data/lib/contrast/{agent/logger.rb → logger/log.rb} +39 -63
- 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/assess/tracking_util.rb +45 -20
- data/lib/contrast/utils/class_util.rb +4 -2
- data/lib/contrast/utils/gemfile_reader.rb +2 -2
- data/lib/contrast/utils/hash_digest.rb +13 -9
- data/lib/contrast/utils/invalid_configuration_util.rb +2 -18
- data/lib/contrast/utils/inventory_util.rb +2 -7
- data/lib/contrast/utils/job_servers_running.rb +4 -2
- data/lib/contrast/utils/object_share.rb +0 -2
- data/lib/contrast/utils/os.rb +16 -4
- data/lib/contrast/utils/stack_trace_utils.rb +0 -1
- data/lib/contrast/utils/tag_util.rb +1 -1
- data/lib/contrast/utils/thread_tracker.rb +1 -14
- data/lib/contrast/utils/timer.rb +1 -17
- 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 +9 -5
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +103 -139
- data/funchook/Makefile +0 -29
- data/funchook/autom4te.cache/output.0 +0 -4964
- data/funchook/autom4te.cache/requests +0 -77
- data/funchook/autom4te.cache/traces.0 +0 -361
- data/funchook/config.log +0 -651
- data/funchook/config.status +0 -1015
- data/funchook/configure +0 -4964
- data/funchook/src/Makefile +0 -70
- data/funchook/src/config.h +0 -101
- data/funchook/src/config.h.in +0 -100
- 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.dylib +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 +0 -43
- data/funchook/test/funchook_test +0 -0
- data/funchook/test/libfunchook_test.so +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/funchook/test/test_main.o +0 -0
- data/funchook/test/x86_64_test.o +0 -0
- data/lib/contrast/agent/assess/adjusted_span.rb +0 -27
- 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/agent/socket_client.rb +0 -134
- data/lib/contrast/api/connection_status.rb +0 -49
- data/lib/contrast/api/decorators/exclusion.rb +0 -20
- data/lib/contrast/api/socket.rb +0 -43
- data/lib/contrast/api/speedracer.rb +0 -188
- data/lib/contrast/api/tcp_socket.rb +0 -29
- data/lib/contrast/api/unix_socket.rb +0 -25
- 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/framework/view_technologies_descriptor.rb +0 -21
- data/lib/contrast/internal_exception.rb +0 -8
- data/lib/contrast/utils/cache.rb +0 -58
- 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/lib/contrast/utils/service_sender_util.rb +0 -110
- data/lib/contrast/utils/sinatra_helper.rb +0 -49
- data/resources/csrf/inject.js +0 -44
@@ -5,62 +5,17 @@ cs__scoped_require 'logger'
|
|
5
5
|
cs__scoped_require 'ougai'
|
6
6
|
cs__scoped_require 'singleton'
|
7
7
|
|
8
|
-
cs__scoped_require 'contrast/extensions/ruby_core/module'
|
9
8
|
cs__scoped_require 'contrast/components/interface'
|
9
|
+
cs__scoped_require 'contrast/extension/module'
|
10
|
+
cs__scoped_require 'contrast/logger/application'
|
11
|
+
cs__scoped_require 'contrast/logger/format'
|
12
|
+
cs__scoped_require 'contrast/logger/time'
|
10
13
|
|
11
14
|
module Contrast
|
12
|
-
module
|
13
|
-
# Our decorator for the Ougai logger allowing for timing and with_level
|
14
|
-
# methods.
|
15
|
-
module Logger
|
16
|
-
# Log the message at the given level.
|
17
|
-
#
|
18
|
-
# @param level [String] the name of the method to use. Should be one of
|
19
|
-
# trace, debug, info, warn, error
|
20
|
-
# @param message [String] the message to log
|
21
|
-
def with_level level, message
|
22
|
-
send(level.to_sym, message)
|
23
|
-
end
|
24
|
-
|
25
|
-
# Log, at the debug level, the action with a message including the time
|
26
|
-
# it took for the wrapped function to complete.
|
27
|
-
#
|
28
|
-
# @param msgs [Array<Object>] the arguments to pass to the logger.
|
29
|
-
# msgs[0] will be modified to include the elapsed time.
|
30
|
-
# @param block [Block, Proc] the block to execute
|
31
|
-
def debug_with_time *msgs, &block
|
32
|
-
log_with_time(:debug, *msgs, &block)
|
33
|
-
end
|
34
|
-
|
35
|
-
# Log, at the trace level, the action with a message including the time
|
36
|
-
# it took for the wrapped function to complete.
|
37
|
-
#
|
38
|
-
# @param msgs [Array<Object>] the arguments to pass to the logger.
|
39
|
-
# msgs[0] will be modified to include the elapsed time.
|
40
|
-
# @param block [Block, Proc] the block to execute
|
41
|
-
def trace_with_time *msgs, &block
|
42
|
-
log_with_time(:trace, *msgs, &block)
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def log_with_time level, *msgs
|
48
|
-
a = Contrast::Utils::Timer.now_ms
|
49
|
-
ret = yield if block_given?
|
50
|
-
z = Contrast::Utils::Timer.now_ms
|
51
|
-
msgs[0] = "#{ msgs[0] }: pid=#{ Process.pid }, elapsed=#{ z - a }ms"
|
52
|
-
send(level, *msgs)
|
53
|
-
ret
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
module Contrast
|
60
|
-
module Agent
|
15
|
+
module Logger
|
61
16
|
# This class functions to serve as a wrapper around our logging, as we need
|
62
17
|
# to be able to dynamically update level based on updates to TeamServer.
|
63
|
-
class
|
18
|
+
class Log
|
64
19
|
include Singleton
|
65
20
|
include Contrast::Components::Interface
|
66
21
|
access_component :config
|
@@ -76,8 +31,6 @@ module Contrast
|
|
76
31
|
|
77
32
|
def initialize
|
78
33
|
update
|
79
|
-
rescue StandardError => e
|
80
|
-
logger.error('Unable to initialize regular logger in LoggerManager.', e)
|
81
34
|
end
|
82
35
|
|
83
36
|
# Given new settings from TeamServer, update our logging to use the new
|
@@ -102,10 +55,14 @@ module Contrast
|
|
102
55
|
@previous_level = level_const
|
103
56
|
|
104
57
|
@_logger = build(path: path, level_const: level_const)
|
105
|
-
|
106
|
-
logger.debug('Initialized new contrast agent logger')
|
58
|
+
log_update
|
107
59
|
rescue StandardError => e
|
108
|
-
logger
|
60
|
+
if logger
|
61
|
+
logger.error('Unable to process update to LoggerManager.', e)
|
62
|
+
else
|
63
|
+
puts 'Unable to process update to LoggerManager.'
|
64
|
+
puts e.backtrace.join("\n")
|
65
|
+
end
|
109
66
|
end
|
110
67
|
|
111
68
|
def logger
|
@@ -131,13 +88,19 @@ module Contrast
|
|
131
88
|
else
|
132
89
|
::Ougai::Logger.new(path)
|
133
90
|
end
|
134
|
-
logger
|
91
|
+
add_contrast_loggers(logger)
|
135
92
|
logger.progname = 'Contrast Agent'
|
136
93
|
logger.level = level_const
|
94
|
+
logger.formatter = Contrast::Logger::Format.new
|
137
95
|
logger.formatter.datetime_format = '%Y-%m-%dT%H:%M:%S.%L%z'
|
138
96
|
logger
|
139
97
|
end
|
140
98
|
|
99
|
+
def add_contrast_loggers logger
|
100
|
+
logger.extend(Contrast::Logger::Application)
|
101
|
+
logger.extend(Contrast::Logger::Time)
|
102
|
+
end
|
103
|
+
|
141
104
|
def valid_path path
|
142
105
|
path = path.nil? ? Contrast::Utils::ObjectShare::EMPTY_STRING : path
|
143
106
|
return path if path == STDOUT_STR
|
@@ -146,13 +109,15 @@ module Contrast
|
|
146
109
|
path = DEFAULT_NAME if path.empty?
|
147
110
|
if write_permission?(path)
|
148
111
|
path
|
112
|
+
elsif write_permission?(DEFAULT_NAME)
|
113
|
+
# Log once when the path is invalid. We'll change to this path, so no
|
114
|
+
# need to log again.
|
115
|
+
puts "[!] Unable to write to '#{ path }'. Writing to default log '#{ DEFAULT_NAME }' instead." if previous_path != DEFAULT_NAME
|
116
|
+
DEFAULT_NAME
|
149
117
|
else
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
logger.error('Unable to write to log file. Writing to standard out instead', path: path)
|
154
|
-
end
|
155
|
-
|
118
|
+
# Log once when the path is invalid. We'll change to this path, so no
|
119
|
+
# need to log again.
|
120
|
+
puts "[!] Unable to write to '#{ path }'. Writing to standard out instead." if previous_path != STDOUT_STR
|
156
121
|
STDOUT_STR
|
157
122
|
end
|
158
123
|
end
|
@@ -168,6 +133,17 @@ module Contrast
|
|
168
133
|
rescue StandardError
|
169
134
|
DEFAULT_LEVEL
|
170
135
|
end
|
136
|
+
|
137
|
+
# Log that the Agent log has changed and include some default information
|
138
|
+
# at the start of the log.
|
139
|
+
def log_update
|
140
|
+
logger.debug('Initialized new contrast agent logger')
|
141
|
+
logger.debug_with_time('middleware: log environment') do
|
142
|
+
logger.application_environment
|
143
|
+
logger.application_configuration
|
144
|
+
logger.application_libraries
|
145
|
+
end
|
146
|
+
end
|
171
147
|
end
|
172
148
|
end
|
173
149
|
end
|
@@ -0,0 +1,50 @@
|
|
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
|
+
module Contrast
|
5
|
+
module Logger
|
6
|
+
# Our decorator for the Ougai logger allowing for timing and with_level
|
7
|
+
# methods.
|
8
|
+
module Time
|
9
|
+
# Log the message at the given level.
|
10
|
+
#
|
11
|
+
# @param level [String] the name of the method to use. Should be one of
|
12
|
+
# trace, debug, info, warn, error
|
13
|
+
# @param message [String] the message to log
|
14
|
+
def with_level level, message
|
15
|
+
send(level.to_sym, message)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Log, at the debug level, the action with a message including the time
|
19
|
+
# it took for the wrapped function to complete.
|
20
|
+
#
|
21
|
+
# @param msgs [Array<Object>] the arguments to pass to the logger.
|
22
|
+
# msgs[0] will be modified to include the elapsed time.
|
23
|
+
# @param block [Block, Proc] the block to execute
|
24
|
+
def debug_with_time *msgs, &block
|
25
|
+
log_with_time(:debug, *msgs, &block)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Log, at the trace level, the action with a message including the time
|
29
|
+
# it took for the wrapped function to complete.
|
30
|
+
#
|
31
|
+
# @param msgs [Array<Object>] the arguments to pass to the logger.
|
32
|
+
# msgs[0] will be modified to include the elapsed time.
|
33
|
+
# @param block [Block, Proc] the block to execute
|
34
|
+
def trace_with_time *msgs, &block
|
35
|
+
log_with_time(:trace, *msgs, &block)
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def log_with_time level, *msgs
|
41
|
+
a = Contrast::Utils::Timer.now_ms
|
42
|
+
ret = yield if block_given?
|
43
|
+
z = Contrast::Utils::Timer.now_ms
|
44
|
+
msgs[0] = "#{ msgs[0] }: pid=#{ Process.pid }, elapsed=#{ z - a }ms"
|
45
|
+
send(level, *msgs)
|
46
|
+
ret
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -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
|
@@ -12,30 +12,55 @@ module Contrast
|
|
12
12
|
|
13
13
|
access_component :logging
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
class << self
|
16
|
+
# Public interface to our tracking check, isolating the internals
|
17
|
+
# required for recursion.
|
18
|
+
#
|
19
|
+
# @param obj [Object] the thing to check if tracked
|
20
|
+
# @return [Boolean] if the obj, or something in it if a collection, is
|
21
|
+
# tracked.
|
22
|
+
def tracked? obj
|
23
|
+
_tracked?(obj, 0)
|
24
|
+
end
|
17
25
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
private
|
27
|
+
|
28
|
+
# Sometimes things are nested inside of each other, such as an Array
|
29
|
+
# holding a Hash, holding that Array. In those cases, rather than
|
30
|
+
# entering an infinite loop, we'll break out.
|
31
|
+
# Right now, that level of nesting has been arbitrarily set to 10.
|
32
|
+
#
|
33
|
+
# @param obj [Object] the thing to check if tracked
|
34
|
+
# @param idx [Integer] the number of levels nested we've gone
|
35
|
+
# @return [Boolean] if the obj, or something in it if a collection, is
|
36
|
+
# tracked.
|
37
|
+
def _tracked? obj, idx
|
38
|
+
return false if obj.nil?
|
39
|
+
return false if idx > 10
|
40
|
+
|
41
|
+
idx += 1
|
42
|
+
if Contrast::Utils::DuckUtils.iterable_hash?(obj)
|
43
|
+
obj.each_pair do |k, v|
|
44
|
+
return true if _tracked?(k, idx)
|
45
|
+
return true if _tracked?(v, idx)
|
46
|
+
end
|
47
|
+
false
|
48
|
+
elsif Contrast::Utils::DuckUtils.iterable_enumerable?(obj)
|
49
|
+
obj.any? do |ele|
|
50
|
+
_tracked?(ele, idx) unless obj == ele
|
51
|
+
end
|
52
|
+
elsif Contrast::Utils::DuckUtils.quacks_to?(obj, :cs__tracked?)
|
53
|
+
obj.cs__tracked?
|
54
|
+
else
|
55
|
+
false
|
27
56
|
end
|
28
|
-
|
29
|
-
|
30
|
-
|
57
|
+
rescue StandardError => e
|
58
|
+
# This is used to ask if a ton of objects are tracked. They may not
|
59
|
+
# all be iterable. Bad things could happen in some cases, like when
|
60
|
+
# checking a closed statement for SQL injection trigger events
|
61
|
+
logger.warn('Failed to determine tracking', e, module: obj.cs__class)
|
31
62
|
false
|
32
63
|
end
|
33
|
-
rescue StandardError => e
|
34
|
-
# This is used to ask if a ton of objects are tracked. They may not
|
35
|
-
# all be iterable. Bad things could happen in some cases, like when
|
36
|
-
# checking a closed statement for SQL injection trigger events
|
37
|
-
logger.warn('Failed to determine tracking', e, module: obj.cs__class)
|
38
|
-
false
|
39
64
|
end
|
40
65
|
end
|
41
66
|
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
|
@@ -56,7 +56,9 @@ module Contrast
|
|
56
56
|
# @return [String] the human readable form of the String, as defined by
|
57
57
|
# https://bitbucket.org/contrastsecurity/assess-specifications/src/master/vulnerability/capture-snapshot.md
|
58
58
|
def to_contrast_string object
|
59
|
-
if
|
59
|
+
# Only treat object like a string if it actually is a string
|
60
|
+
# some subclasses of String override string methods we depend on
|
61
|
+
if object.cs__class == String
|
60
62
|
cached = to_cached_string(object)
|
61
63
|
return cached if cached
|
62
64
|
|
@@ -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
|
@@ -32,8 +32,8 @@ module Contrast
|
|
32
32
|
request.parameters.each_key do |name|
|
33
33
|
hash.update(name)
|
34
34
|
end
|
35
|
-
cl = request.
|
36
|
-
hash.
|
35
|
+
cl = request.headers[CONTENT_LENGTH_HEADER]
|
36
|
+
hash.update_on_content_length(cl) if cl
|
37
37
|
hash.finish
|
38
38
|
end
|
39
39
|
|
@@ -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)
|
@@ -126,6 +121,15 @@ module Contrast
|
|
126
121
|
end
|
127
122
|
end
|
128
123
|
|
124
|
+
CHARS = %w[a b c d e f g].cs__freeze
|
125
|
+
# This method converts and integer value for length into a string value
|
126
|
+
# that we can hash on, based on the logarithmic value of the length, and
|
127
|
+
# updates the current hash with that value.
|
128
|
+
# @param chr [Numeric] the length to translate
|
129
|
+
def update_on_content_length chr
|
130
|
+
update(CHARS[Math.log10(chr.to_s.length).to_i] || CHARS[-1])
|
131
|
+
end
|
132
|
+
|
129
133
|
def initialize
|
130
134
|
@crc32 = 0
|
131
135
|
end
|
@@ -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'
|
@@ -44,29 +44,13 @@ module Contrast
|
|
44
44
|
activity = Contrast::Api::Dtm::Activity.new
|
45
45
|
activity.findings << finding
|
46
46
|
|
47
|
-
|
48
|
-
if ASSESS.enabled?
|
49
|
-
build_tags(activity)
|
50
|
-
CONTRAST_SERVICE.queue_message activity
|
51
|
-
# Otherwise, if the Agent isn't ready, we have to queue the messages
|
52
|
-
# until we know the starting state.
|
53
|
-
else
|
54
|
-
Contrast::Utils::ServiceSenderUtil.add_to_assess_messages activity
|
55
|
-
end
|
47
|
+
Contrast::Agent.messaging_queue.send_event_eventually(activity)
|
56
48
|
rescue StandardError => e
|
57
49
|
logger.error('Unable to build a finding', e, rule: rule_id)
|
58
50
|
end
|
59
51
|
|
60
52
|
private
|
61
53
|
|
62
|
-
# This seems silly to pull out, but we can ONLY call this in the case
|
63
|
-
# where we have a configuration. Doing otherwise results in a bad error
|
64
|
-
# case where we try to do other things, like logging, which behave
|
65
|
-
# strangely without a config
|
66
|
-
def build_tags activity
|
67
|
-
activity.finding_tags = Contrast::Utils::StringUtils.force_utf8(ASSESS.tags)
|
68
|
-
end
|
69
|
-
|
70
54
|
def file_snippet file_path, call_location
|
71
55
|
idx = call_location&.lineno
|
72
56
|
if file_path && idx && File.exist?(file_path)
|