contrast-agent 3.9.0 → 3.11.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.simplecov +5 -2
- data/ext/build_funchook.rb +14 -9
- data/ext/cs__assess_active_record_named/cs__active_record_named.c +5 -12
- data/ext/cs__assess_active_record_named/extconf.rb +3 -0
- data/ext/cs__assess_array/cs__assess_array.c +3 -5
- data/ext/cs__assess_array/extconf.rb +3 -0
- data/ext/cs__assess_basic_object/cs__assess_basic_object.c +10 -4
- data/ext/cs__assess_basic_object/extconf.rb +3 -0
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +4 -3
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.h +3 -3
- data/ext/cs__assess_fiber_track/extconf.rb +3 -0
- data/ext/cs__assess_hash/cs__assess_hash.c +40 -17
- data/ext/cs__assess_hash/cs__assess_hash.h +4 -6
- data/ext/cs__assess_hash/extconf.rb +3 -0
- data/ext/cs__assess_kernel/cs__assess_kernel.c +10 -8
- data/ext/cs__assess_kernel/cs__assess_kernel.h +1 -0
- data/ext/cs__assess_kernel/extconf.rb +3 -0
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +3 -6
- data/ext/cs__assess_marshal_module/extconf.rb +3 -0
- data/ext/cs__assess_module/cs__assess_module.c +13 -9
- data/ext/cs__assess_module/extconf.rb +3 -0
- data/ext/cs__assess_regexp/cs__assess_regexp.c +13 -9
- data/ext/cs__assess_regexp/cs__assess_regexp.h +1 -0
- data/ext/cs__assess_regexp/extconf.rb +3 -0
- data/ext/cs__assess_string/cs__assess_string.c +5 -8
- data/ext/cs__assess_string/cs__assess_string.h +2 -1
- data/ext/cs__assess_string/extconf.rb +3 -0
- data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +2 -2
- data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.h +3 -3
- data/ext/cs__assess_string_interpolation26/extconf.rb +3 -0
- data/ext/cs__assess_yield_track/cs__assess_yield_track.h +1 -1
- data/ext/cs__assess_yield_track/extconf.rb +3 -0
- data/ext/cs__common/cs__common.c +79 -0
- data/ext/cs__common/cs__common.h +34 -0
- data/ext/cs__common/extconf.rb +9 -8
- data/ext/cs__contrast_patch/cs__contrast_patch.h +1 -6
- data/ext/cs__contrast_patch/extconf.rb +3 -0
- data/ext/cs__protect_kernel/cs__protect_kernel.c +20 -11
- data/ext/cs__protect_kernel/extconf.rb +3 -0
- data/ext/extconf_common.rb +10 -8
- data/funchook/autom4te.cache/output.0 +1 -13
- data/funchook/autom4te.cache/requests +44 -45
- data/funchook/autom4te.cache/traces.0 +0 -3
- data/funchook/config.log +378 -217
- data/funchook/config.status +23 -24
- data/funchook/configure +1 -13
- 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.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 +2 -2
- 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 +20 -0
- 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.rb +1 -0
- data/lib/contrast/agent.rb +21 -15
- data/lib/contrast/agent/assess.rb +1 -2
- data/lib/contrast/agent/assess/adjusted_span.rb +3 -1
- data/lib/contrast/agent/assess/contrast_event.rb +20 -68
- data/lib/contrast/agent/assess/events/event_factory.rb +25 -0
- data/lib/contrast/agent/assess/events/source_event.rb +83 -0
- data/lib/contrast/agent/assess/insulator.rb +0 -4
- data/lib/contrast/agent/assess/policy/patcher.rb +5 -2
- data/lib/contrast/agent/assess/policy/policy_node.rb +0 -7
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +1 -1
- data/lib/contrast/agent/assess/policy/preshift.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagation_method.rb +65 -33
- data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -1
- data/lib/contrast/agent/assess/policy/propagator.rb +1 -0
- data/lib/contrast/agent/assess/policy/propagator/match_data.rb +80 -0
- data/lib/contrast/agent/assess/policy/propagator/select.rb +35 -22
- data/lib/contrast/agent/assess/policy/propagator/split.rb +26 -6
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +2 -0
- data/lib/contrast/agent/assess/policy/rewriter_patch.rb +40 -27
- data/lib/contrast/agent/assess/policy/source_method.rb +20 -20
- data/lib/contrast/agent/assess/policy/source_node.rb +0 -15
- data/lib/contrast/agent/assess/policy/trigger_method.rb +29 -40
- data/lib/contrast/agent/assess/policy/trigger_node.rb +3 -6
- data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -31
- data/lib/contrast/agent/assess/properties.rb +5 -3
- data/lib/contrast/agent/assess/rule/base.rb +1 -5
- data/lib/contrast/agent/assess/rule/csrf/csrf_applicator.rb +2 -22
- data/lib/contrast/agent/assess/rule/csrf/csrf_watcher.rb +5 -1
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +2 -2
- data/lib/contrast/agent/assess/rule/redos.rb +4 -4
- data/lib/contrast/agent/assess/tag.rb +24 -14
- data/lib/contrast/agent/at_exit_hook.rb +16 -13
- data/lib/contrast/agent/class_reopener.rb +15 -6
- data/lib/contrast/agent/deadzone/policy/policy.rb +2 -2
- data/lib/contrast/agent/disable_reaction.rb +3 -4
- data/lib/contrast/agent/exclusion_matcher.rb +8 -48
- data/lib/contrast/agent/feature_state.rb +45 -78
- data/lib/contrast/agent/logger.rb +173 -0
- data/lib/contrast/agent/middleware.rb +87 -250
- data/lib/contrast/agent/module_data.rb +2 -1
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +2 -1
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +21 -4
- data/lib/contrast/agent/patching/policy/method_policy.rb +3 -3
- data/lib/contrast/agent/patching/policy/module_policy.rb +0 -25
- data/lib/contrast/agent/patching/policy/patch.rb +96 -23
- data/lib/contrast/agent/patching/policy/patcher.rb +19 -19
- data/lib/contrast/agent/patching/policy/policy.rb +7 -7
- data/lib/contrast/agent/patching/policy/policy_node.rb +2 -10
- data/lib/contrast/agent/patching/policy/trigger_node.rb +1 -4
- data/lib/contrast/agent/protect/rule/base.rb +14 -33
- data/lib/contrast/agent/protect/rule/base_service.rb +3 -1
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +10 -13
- data/lib/contrast/agent/protect/rule/csrf.rb +2 -1
- data/lib/contrast/agent/protect/rule/csrf/csrf_evaluator.rb +11 -14
- data/lib/contrast/agent/protect/rule/default_scanner.rb +0 -13
- data/lib/contrast/agent/protect/rule/deserialization.rb +2 -0
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +2 -2
- data/lib/contrast/agent/protect/rule/no_sqli.rb +4 -4
- data/lib/contrast/agent/protect/rule/path_traversal.rb +5 -4
- data/lib/contrast/agent/protect/rule/sqli.rb +1 -0
- data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +2 -0
- data/lib/contrast/agent/protect/rule/xss.rb +2 -0
- data/lib/contrast/agent/protect/rule/xxe.rb +10 -4
- data/lib/contrast/agent/railtie.rb +2 -8
- data/lib/contrast/agent/reaction_processor.rb +5 -5
- data/lib/contrast/agent/request.rb +9 -12
- data/lib/contrast/agent/request_context.rb +12 -14
- data/lib/contrast/agent/request_handler.rb +35 -0
- data/lib/contrast/agent/response.rb +52 -30
- data/lib/contrast/agent/rewriter.rb +25 -11
- data/lib/contrast/agent/rule_set.rb +49 -0
- data/lib/contrast/agent/scope.rb +4 -12
- data/lib/contrast/agent/service_heartbeat.rb +1 -2
- data/lib/contrast/agent/settings_state.rb +10 -74
- data/lib/contrast/agent/socket_client.rb +17 -11
- data/lib/contrast/agent/static_analysis.rb +42 -0
- data/lib/contrast/agent/thread.rb +1 -1
- data/lib/contrast/agent/tracepoint_hook.rb +1 -5
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/api.rb +1 -1
- data/lib/contrast/api/decorators.rb +14 -0
- data/lib/contrast/api/decorators/application_settings.rb +37 -0
- data/lib/contrast/api/decorators/application_update.rb +66 -0
- data/lib/contrast/api/decorators/exclusion.rb +20 -0
- data/lib/contrast/api/decorators/input_analysis.rb +17 -0
- data/lib/contrast/api/decorators/server_features.rb +24 -0
- data/lib/contrast/api/speedracer.rb +31 -29
- data/lib/contrast/api/tcp_socket.rb +0 -2
- data/lib/contrast/components/agent.rb +27 -22
- data/lib/contrast/components/app_context.rb +18 -43
- data/lib/contrast/components/config.rb +7 -5
- data/lib/contrast/components/contrast_service.rb +0 -4
- data/lib/contrast/components/heap_dump.rb +12 -8
- data/lib/contrast/components/interface.rb +11 -10
- data/lib/contrast/components/logger.rb +3 -68
- data/lib/contrast/components/sampling.rb +22 -11
- data/lib/contrast/components/settings.rb +18 -5
- data/lib/contrast/config/base_configuration.rb +1 -0
- data/lib/contrast/config/default_value.rb +1 -0
- data/lib/contrast/config/protect_rule_configuration.rb +0 -14
- data/lib/contrast/configuration.rb +3 -5
- data/lib/contrast/extensions/framework/rails/action_controller_inheritance.rb +39 -0
- data/lib/contrast/extensions/framework/rails/active_record_named.rb +13 -8
- data/lib/contrast/extensions/ruby_core/assess.rb +1 -2
- data/lib/contrast/extensions/ruby_core/assess/assess_extension.rb +27 -22
- data/lib/contrast/extensions/ruby_core/assess/erb.rb +0 -8
- data/lib/contrast/extensions/ruby_core/assess/exec_trigger.rb +6 -8
- data/lib/contrast/extensions/ruby_core/assess/fiber.rb +88 -100
- data/lib/contrast/extensions/ruby_core/assess/hash.rb +32 -15
- data/lib/contrast/extensions/ruby_core/assess/kernel.rb +28 -27
- data/lib/contrast/extensions/ruby_core/assess/regexp.rb +74 -196
- data/lib/contrast/extensions/ruby_core/assess/string.rb +15 -7
- data/lib/contrast/extensions/ruby_core/assess/tilt_template_trigger.rb +29 -24
- data/lib/contrast/extensions/ruby_core/assess/xpath_library_trigger.rb +2 -2
- data/lib/contrast/extensions/ruby_core/eval_trigger.rb +0 -1
- data/lib/contrast/extensions/ruby_core/inventory/datastores.rb +2 -2
- data/lib/contrast/extensions/ruby_core/protect/applies_command_injection_rule.rb +9 -20
- data/lib/contrast/extensions/ruby_core/protect/applies_deserialization_rule.rb +9 -19
- data/lib/contrast/extensions/ruby_core/protect/applies_no_sqli_rule.rb +10 -27
- data/lib/contrast/extensions/ruby_core/protect/applies_path_traversal_rule.rb +13 -21
- data/lib/contrast/extensions/ruby_core/protect/applies_sqli_rule.rb +11 -23
- data/lib/contrast/extensions/ruby_core/protect/applies_xxe_rule.rb +62 -78
- data/lib/contrast/extensions/ruby_core/protect/rule_applicator.rb +50 -0
- data/lib/contrast/framework/base_support.rb +10 -0
- data/lib/contrast/framework/manager.rb +28 -2
- data/lib/contrast/framework/platform_version.rb +1 -0
- data/lib/contrast/framework/rails_support.rb +16 -0
- data/lib/contrast/framework/sinatra_support.rb +12 -2
- data/lib/contrast/framework/view_technologies_descriptor.rb +1 -0
- data/lib/contrast/tasks/service.rb +2 -8
- data/lib/contrast/utils/assess/sampling_util.rb +4 -9
- data/lib/contrast/utils/assess/tracking_util.rb +7 -1
- data/lib/contrast/utils/boolean_util.rb +2 -5
- data/lib/contrast/utils/cache.rb +0 -11
- data/lib/contrast/utils/class_util.rb +20 -1
- data/lib/contrast/utils/gemfile_reader.rb +5 -3
- data/lib/contrast/utils/hash_digest.rb +0 -4
- data/lib/contrast/utils/heap_dump_util.rb +12 -11
- data/lib/contrast/utils/invalid_configuration_util.rb +1 -1
- data/lib/contrast/utils/inventory_util.rb +2 -2
- data/lib/contrast/utils/io_util.rb +1 -11
- data/lib/contrast/utils/job_servers_running.rb +2 -2
- data/lib/contrast/utils/object_share.rb +1 -37
- data/lib/contrast/utils/os.rb +1 -25
- data/lib/contrast/utils/rack_assess_session_cookie.rb +3 -3
- data/lib/contrast/utils/rails_assess_configuration.rb +3 -3
- data/lib/contrast/utils/ruby_ast_rewriter.rb +5 -1
- data/lib/contrast/utils/service_response_util.rb +27 -53
- data/lib/contrast/utils/service_sender_util.rb +9 -5
- data/lib/contrast/utils/sinatra_helper.rb +0 -6
- data/lib/contrast/utils/stack_trace_utils.rb +86 -182
- data/lib/contrast/utils/string_utils.rb +18 -2
- data/lib/contrast/utils/tag_util.rb +11 -1
- data/lib/contrast/utils/thread_tracker.rb +2 -2
- data/lib/contrast/utils/timer.rb +0 -40
- data/resources/assess/policy.json +33 -21
- data/resources/protect/policy.json +9 -9
- data/ruby-agent.gemspec +7 -4
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +79 -54
- data/ext/cs__assess_regexp_track/cs__assess_regexp_track.c +0 -63
- data/ext/cs__assess_regexp_track/cs__assess_regexp_track.h +0 -29
- data/ext/cs__assess_regexp_track/extconf.rb +0 -2
- data/funchook/src/libfunchook.so +0 -0
- data/lib/contrast/agent/assess/frozen_properties.rb +0 -41
- data/lib/contrast/agent/logger_manager.rb +0 -116
- data/lib/contrast/delegators.rb +0 -9
- data/lib/contrast/delegators/application_update.rb +0 -32
- data/lib/contrast/utils/comment_range.rb +0 -19
- data/lib/contrast/utils/environment_util.rb +0 -82
- data/lib/contrast/utils/performs_logging.rb +0 -152
- data/resources/factory-bot-spec/spec_helper.rb +0 -30
- data/resources/rubocops/kernel/catch_cop.rb +0 -37
- data/resources/rubocops/kernel/require_cop.rb +0 -37
- data/resources/rubocops/kernel/require_relative_cop.rb +0 -33
- data/resources/rubocops/module/autoload_cop.rb +0 -37
- data/resources/rubocops/module/const_defined_cop.rb +0 -37
- data/resources/rubocops/module/const_get_cop.rb +0 -37
- data/resources/rubocops/module/const_set_cop.rb +0 -37
- data/resources/rubocops/module/constants_cop.rb +0 -37
- data/resources/rubocops/module/name_cop.rb +0 -37
- data/resources/rubocops/object/class_cop.rb +0 -37
- data/resources/rubocops/object/freeze_cop.rb +0 -37
- data/resources/rubocops/object/frozen_cop.rb +0 -37
- data/resources/rubocops/object/is_a_cop.rb +0 -37
- data/resources/rubocops/object/method_cop.rb +0 -37
- data/resources/rubocops/object/respond_to_cop.rb +0 -37
- data/resources/rubocops/object/singleton_class_cop.rb +0 -37
- data/resources/rubocops/regexp/spelling_cop.rb +0 -44
- data/resources/rubocops/thread/new_cop.rb +0 -39
- data/resources/ruby-spec/ancestors_spec.rb +0 -70
- data/resources/ruby-spec/modulo_spec.rb +0 -831
- data/resources/ruby-spec/parameters_spec.rb +0 -261
- data/resources/ruby-spec/ruby_spec_spec_helper.rb +0 -35
@@ -23,8 +23,7 @@ module Contrast
|
|
23
23
|
# it should break LOUDLY. Better to waste half an hour of the sysadmin's
|
24
24
|
# time than to silently fail to deliver functionality.
|
25
25
|
module Config
|
26
|
-
|
27
|
-
CONTRAST_ENV_MARKER = 'CONTRAST__'
|
26
|
+
CONTRAST_ENV_MARKER = 'CONTRAST__'
|
28
27
|
|
29
28
|
class Interface # :nodoc:
|
30
29
|
def initialize
|
@@ -51,7 +50,8 @@ module Contrast
|
|
51
50
|
end
|
52
51
|
|
53
52
|
def enabled?
|
54
|
-
Contrast::Utils::BooleanUtil.
|
53
|
+
@_enabled = !Contrast::Utils::BooleanUtil.false?(raw.enable) if @_enabled.nil?
|
54
|
+
@_enabled
|
55
55
|
end
|
56
56
|
|
57
57
|
def disabled?
|
@@ -59,11 +59,13 @@ module Contrast
|
|
59
59
|
end
|
60
60
|
|
61
61
|
def protect?
|
62
|
-
Contrast::Utils::BooleanUtil.true?(raw.protect.enable)
|
62
|
+
@_protect = Contrast::Utils::BooleanUtil.true?(raw.protect.enable) if @_protect.nil?
|
63
|
+
@_protect
|
63
64
|
end
|
64
65
|
|
65
66
|
def assess?
|
66
|
-
Contrast::Utils::BooleanUtil.true?(raw.assess.enable)
|
67
|
+
@_assess = Contrast::Utils::BooleanUtil.true?(raw.assess.enable) if @_assess.nil?
|
68
|
+
@_assess
|
67
69
|
end
|
68
70
|
|
69
71
|
def session_id
|
@@ -16,17 +16,21 @@ module Contrast
|
|
16
16
|
access_component :config
|
17
17
|
|
18
18
|
def heap_dump_enabled?
|
19
|
-
|
19
|
+
heap_dump_control[:enabled]
|
20
20
|
end
|
21
21
|
|
22
22
|
def heap_dump_control
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
23
|
+
@_heap_dump_control ||= begin
|
24
|
+
config = CONFIG.root&.agent&.heap_dump
|
25
|
+
{
|
26
|
+
enabled: true?(config&.enable),
|
27
|
+
path: File.absolute_path(config&.path),
|
28
|
+
count: config&.count.to_i || 0,
|
29
|
+
window: (config&.window_ms.to_f || 0) / 1000,
|
30
|
+
delay: (config&.delay_ms.to_f || 0) / 1000,
|
31
|
+
clean: true?(config&.clean)
|
32
|
+
}
|
33
|
+
end
|
30
34
|
end
|
31
35
|
end
|
32
36
|
end
|
@@ -97,7 +97,7 @@ module Contrast
|
|
97
97
|
#
|
98
98
|
# class Abc
|
99
99
|
# include Contrast::Components::Interface
|
100
|
-
# access_component :
|
100
|
+
# access_component :logging, :agent
|
101
101
|
#
|
102
102
|
# def function
|
103
103
|
# if AGENT.disabled?
|
@@ -151,6 +151,16 @@ Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:config] =
|
|
151
151
|
cs__scoped_require 'contrast/components/settings'
|
152
152
|
Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:settings] = [Contrast::Components::Settings]
|
153
153
|
|
154
|
+
cs__scoped_require 'contrast/components/assess'
|
155
|
+
cs__scoped_require 'contrast/components/protect'
|
156
|
+
cs__scoped_require 'contrast/components/inventory'
|
157
|
+
Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:analysis] = [Contrast::Components::Protect,
|
158
|
+
Contrast::Components::Assess,
|
159
|
+
Contrast::Components::Inventory]
|
160
|
+
|
161
|
+
cs__scoped_require 'contrast/components/logger'
|
162
|
+
Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:logging] = [Contrast::Components::Logger]
|
163
|
+
|
154
164
|
cs__scoped_require 'contrast/components/agent'
|
155
165
|
Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:agent] = [Contrast::Components::Agent]
|
156
166
|
|
@@ -163,15 +173,6 @@ Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:contrast_s
|
|
163
173
|
cs__scoped_require 'contrast/components/heap_dump'
|
164
174
|
Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:heap_dump] = [Contrast::Components::HeapDump]
|
165
175
|
|
166
|
-
cs__scoped_require 'contrast/components/logger'
|
167
|
-
Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:logging] = [Contrast::Components::Logger]
|
168
|
-
|
169
|
-
cs__scoped_require 'contrast/components/assess'
|
170
|
-
cs__scoped_require 'contrast/components/protect'
|
171
|
-
cs__scoped_require 'contrast/components/inventory'
|
172
|
-
Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:analysis] = [Contrast::Components::Protect,
|
173
|
-
Contrast::Components::Assess,
|
174
|
-
Contrast::Components::Inventory]
|
175
176
|
cs__scoped_require 'contrast/components/sampling'
|
176
177
|
Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:sampling] = [Contrast::Components::Sampling]
|
177
178
|
|
@@ -1,12 +1,14 @@
|
|
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/agent/logger'
|
5
|
+
|
4
6
|
module Contrast
|
5
7
|
module Components
|
6
8
|
module Logger
|
7
9
|
module InstanceMethods #:nodoc:
|
8
10
|
def logger
|
9
|
-
Contrast::
|
11
|
+
Contrast::Agent::Logger.instance.logger
|
10
12
|
end
|
11
13
|
end
|
12
14
|
ClassMethods = InstanceMethods
|
@@ -17,73 +19,6 @@ module Contrast
|
|
17
19
|
# Specifically, this allows for querying the state of the Agent Logger.
|
18
20
|
class Interface
|
19
21
|
include Contrast::Components::ComponentBase
|
20
|
-
|
21
|
-
%w[error? warn? info? debug?].each do |level|
|
22
|
-
define_method(level) { state.logger.send(level) }
|
23
|
-
end
|
24
|
-
|
25
|
-
# def trace? # TODO: RUBY-547
|
26
|
-
# config&.agent&.logger&.level && config.agent.logger.level.to_s.casecmp('TRACE').to_i.zero?
|
27
|
-
# end
|
28
|
-
|
29
|
-
def error *args
|
30
|
-
log_with_level(*args, :error)
|
31
|
-
end
|
32
|
-
|
33
|
-
def warn *args
|
34
|
-
log_with_level(*args, :warn)
|
35
|
-
end
|
36
|
-
|
37
|
-
def info *args
|
38
|
-
log_with_level(*args, :info)
|
39
|
-
end
|
40
|
-
|
41
|
-
def debug *args
|
42
|
-
log_with_level(*args, :debug)
|
43
|
-
end
|
44
|
-
|
45
|
-
def with_level *args
|
46
|
-
log_with_level(*args)
|
47
|
-
end
|
48
|
-
|
49
|
-
def debug_with_time msg
|
50
|
-
ret = nil
|
51
|
-
a = Contrast::Utils::Timer.now_ms
|
52
|
-
ret = yield if block_given?
|
53
|
-
z = Contrast::Utils::Timer.now_ms
|
54
|
-
log_with_level(nil, "#{ msg }: pid=#{ Process.pid }, elapsed=#{ z - a }ms", :debug)
|
55
|
-
ret
|
56
|
-
end
|
57
|
-
|
58
|
-
# def trace_with_time msg # TODO: RUBY-547
|
59
|
-
# ret = nil
|
60
|
-
# unless trace?
|
61
|
-
# ret = yield if block_given?
|
62
|
-
# return ret
|
63
|
-
# end
|
64
|
-
#
|
65
|
-
# a = Contrast::Utils::Timer.now_ms
|
66
|
-
# ret = yield if block_given?
|
67
|
-
# z = Contrast::Utils::Timer.now_ms
|
68
|
-
# log_with_level(nil, "#{ msg }: pid=#{ Process.pid }, elapsed=#{ z - a }ms", :debug)
|
69
|
-
# ret
|
70
|
-
# end
|
71
|
-
|
72
|
-
private
|
73
|
-
|
74
|
-
def log_with_level *args
|
75
|
-
if args.length == 2
|
76
|
-
msg, level = *args
|
77
|
-
state.cs__class.log_with_level(nil, msg, level)
|
78
|
-
elsif args.length == 3
|
79
|
-
exception, msg, level = *args
|
80
|
-
state.cs__class.log_with_level(exception, msg, level)
|
81
|
-
end
|
82
|
-
|
83
|
-
nil
|
84
|
-
rescue StandardError
|
85
|
-
nil
|
86
|
-
end
|
87
22
|
end
|
88
23
|
|
89
24
|
COMPONENT_INTERFACE = Interface.new
|
@@ -9,7 +9,7 @@ module Contrast
|
|
9
9
|
DEFAULT_SAMPLING_BASELINE = 5
|
10
10
|
DEFAULT_SAMPLING_REQUEST_FREQUENCY = 5
|
11
11
|
DEFAULT_SAMPLING_RESPONSE_FREQUENCY = 25
|
12
|
-
DEFAULT_SAMPLING_WINDOW_MS = 180_000
|
12
|
+
DEFAULT_SAMPLING_WINDOW_MS = 180_000
|
13
13
|
end
|
14
14
|
|
15
15
|
module ClassMethods #:nodoc:
|
@@ -17,18 +17,29 @@ module Contrast
|
|
17
17
|
include Constants
|
18
18
|
include Contrast::Components::Interface
|
19
19
|
|
20
|
-
access_component :config
|
20
|
+
access_component :config, :settings
|
21
21
|
|
22
|
-
def
|
23
|
-
|
22
|
+
def sampling_enabled?
|
23
|
+
sampling_control[:enabled]
|
24
|
+
end
|
25
|
+
|
26
|
+
def sampling_control
|
27
|
+
@_sampling_control ||= begin
|
28
|
+
cas = CONFIG.root.assess&.sampling
|
29
|
+
settings = SETTINGS&.assess_state&.[](:sampling_settings)
|
30
|
+
{
|
31
|
+
enabled: true?([cas&.enable, settings&.enabled, DEFAULT_SAMPLING_ENABLED].reject(&:nil?)[0]),
|
32
|
+
baseline: [cas&.baseline, settings&.baseline, DEFAULT_SAMPLING_BASELINE].map(&:to_i).find(&:positive?),
|
33
|
+
request_frequency: [cas&.request_frequency, settings&.request_frequency, DEFAULT_SAMPLING_REQUEST_FREQUENCY].map(&:to_i).find(&:positive?),
|
34
|
+
response_frequency: [cas&.response_frequency, settings&.response_frequency, DEFAULT_SAMPLING_RESPONSE_FREQUENCY].map(&:to_i).find(&:positive?),
|
35
|
+
window: [cas&.window_ms, settings&.window_ms, DEFAULT_SAMPLING_WINDOW_MS].map(&:to_i).find(&:positive?)
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
24
39
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
request_frequency: [cas&.request_frequency, settings&.request_frequency, DEFAULT_SAMPLING_REQUEST_FREQUENCY] .map(&:to_i).find(&:positive?),
|
29
|
-
response_frequency: [cas&.response_frequency, settings&.response_frequency, DEFAULT_SAMPLING_RESPONSE_FREQUENCY].map(&:to_i).find(&:positive?),
|
30
|
-
window: [cas&.window_ms, settings&.window_ms, DEFAULT_SAMPLING_WINDOW_MS] .map(&:to_i).find(&:positive?)
|
31
|
-
}
|
40
|
+
# Used to reset sampling when settings from TeamServer change
|
41
|
+
def reset_sampling_control
|
42
|
+
@_sampling_control = nil
|
32
43
|
end
|
33
44
|
end
|
34
45
|
|
@@ -59,7 +59,6 @@ module Contrast
|
|
59
59
|
PROTECT_STATE_ATTRS = %i[].cs__freeze
|
60
60
|
ASSESS_STATE_ATTRS = %i[sampling_features].cs__freeze
|
61
61
|
APPLICATION_STATE_ATTRS = %i[modes_by_id exclusion_matchers disabled_assess_rules session_id].cs__freeze
|
62
|
-
STATE_ATTRS = PROTECT_STATE_ATTRS | ASSESS_STATE_ATTRS | APPLICATION_STATE_ATTRS
|
63
62
|
|
64
63
|
# Meta-define an accessor for each state attribute.
|
65
64
|
begin
|
@@ -86,6 +85,24 @@ module Contrast
|
|
86
85
|
reset_state
|
87
86
|
end
|
88
87
|
|
88
|
+
def update_from_server_features server_features
|
89
|
+
# protect
|
90
|
+
begin
|
91
|
+
protect_state[:enabled] = server_features.protect_enabled?
|
92
|
+
end
|
93
|
+
|
94
|
+
# assess
|
95
|
+
begin
|
96
|
+
assess_state[:enabled] = server_features.assess_enabled?
|
97
|
+
assess_state[:sampling_settings] = server_features.assess.sampling
|
98
|
+
Contrast::Utils::Assess::SamplingUtil.instance.update
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def update_from_application_settings application_settings
|
103
|
+
application_state.merge!(application_settings.application_state_translation)
|
104
|
+
end
|
105
|
+
|
89
106
|
# Wipe state to zero.
|
90
107
|
def reset_state
|
91
108
|
@assess_rules = {}
|
@@ -123,10 +140,6 @@ module Contrast
|
|
123
140
|
Contrast::Agent::Protect::Rule::Csrf.new
|
124
141
|
end
|
125
142
|
|
126
|
-
def protect_rule name
|
127
|
-
@protect_rules[name]
|
128
|
-
end
|
129
|
-
|
130
143
|
# these are less 'settings' and more 'how do I behave.'
|
131
144
|
# relocate to Agent or Assess/Protect.
|
132
145
|
def protect_rule_mode rule_id
|
@@ -8,12 +8,6 @@ module Contrast
|
|
8
8
|
# Common Configuration settings. Those in this section pertain to the
|
9
9
|
# rule mode of a single protect rule in the Agent.
|
10
10
|
class ProtectRuleConfiguration < BaseConfiguration
|
11
|
-
# rubocop:disable Style/SymbolArray, Layout/SpaceBeforeComma, Layout/SpaceInsideArrayLiteralBrackets:
|
12
|
-
BLOCKING_RULES = ::Set.new([:BLOCK , :BLOCK_AT_PERIMETER ]).cs__freeze
|
13
|
-
PREFILTER_RULES = ::Set.new([ :BLOCK_AT_PERIMETER ]).cs__freeze
|
14
|
-
POSTFILTER_RULES = ::Set.new([:BLOCK , :PERMIT, :MONITOR]).cs__freeze
|
15
|
-
# rubocop:enable Style/SymbolArray, Layout/SpaceBeforeComma, Layout/SpaceInsideArrayLiteralBrackets:
|
16
|
-
|
17
11
|
KEYS = {
|
18
12
|
enable: EMPTY_VALUE,
|
19
13
|
mode: EMPTY_VALUE,
|
@@ -24,14 +18,6 @@ module Contrast
|
|
24
18
|
def initialize hsh
|
25
19
|
super(hsh, KEYS)
|
26
20
|
end
|
27
|
-
|
28
|
-
def off?
|
29
|
-
mode == 'off'
|
30
|
-
end
|
31
|
-
|
32
|
-
def on?
|
33
|
-
!off?
|
34
|
-
end
|
35
21
|
end
|
36
22
|
end
|
37
23
|
end
|
@@ -63,11 +63,9 @@ module Contrast
|
|
63
63
|
# in an infinite loop on the to_sym method used later.
|
64
64
|
def method_missing symbol, *args
|
65
65
|
with_contrast_scope do
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
super
|
70
|
-
end
|
66
|
+
root.public_send(symbol, *args)
|
67
|
+
rescue NoMethodError => _e
|
68
|
+
super
|
71
69
|
end
|
72
70
|
end
|
73
71
|
|
@@ -0,0 +1,39 @@
|
|
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 ActionController
|
5
|
+
module Railties
|
6
|
+
# Used to monkey patch all the inherited calls in action_pack
|
7
|
+
#
|
8
|
+
# This is the usual entry point for Rails inheritance work, so it should
|
9
|
+
# catch most of the calls to inherited.
|
10
|
+
module Helpers
|
11
|
+
alias_method :cs__patched_inherited, :inherited
|
12
|
+
def inherited klass
|
13
|
+
klass&.instance_variable_set(:@cs__defining_class, true)
|
14
|
+
cs__patched_inherited(klass)
|
15
|
+
ensure
|
16
|
+
klass&.instance_variable_set(:@cs__defining_class, false)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
module ActiveRecord
|
23
|
+
module AttributeMethods
|
24
|
+
# Used to monkey patch all the inherited calls in action_pack
|
25
|
+
module TimeZoneConversion
|
26
|
+
module ClassMethods #:nodoc:
|
27
|
+
private
|
28
|
+
|
29
|
+
alias_method :cs__patched_inherited, :inherited
|
30
|
+
def inherited klass
|
31
|
+
klass&.instance_variable_set(:@cs__defining_class, true)
|
32
|
+
cs__patched_inherited(klass)
|
33
|
+
ensure
|
34
|
+
klass&.instance_variable_set(:@cs__defining_class, false)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -13,19 +13,14 @@ module ActiveRecord
|
|
13
13
|
# TODO: RUBY-534
|
14
14
|
module ClassMethods
|
15
15
|
include Contrast::Components::Interface
|
16
|
-
access_component :
|
16
|
+
access_component :agent, :logging
|
17
17
|
|
18
18
|
def _cs__rewrite method_name, body
|
19
19
|
return body unless AGENT.rewrite_interpolation?
|
20
20
|
return body unless body.is_a?(Proc)
|
21
21
|
|
22
22
|
location = body.source_location
|
23
|
-
return body
|
24
|
-
|
25
|
-
# Good news, once we patch the body once, the source location
|
26
|
-
# becomes eval. We may need to fix this later though (so it may
|
27
|
-
# be bad news)
|
28
|
-
return body if location.empty? || location[0].empty? || location[0].include?('eval')
|
23
|
+
return body unless _cs__location_available?(location)
|
29
24
|
|
30
25
|
opener = Contrast::Agent::ClassReopener.new(Contrast::Agent::ModuleData.new(self))
|
31
26
|
original_source_code = opener.source_code(location, method_name)
|
@@ -43,9 +38,19 @@ module ActiveRecord
|
|
43
38
|
|
44
39
|
unbound_eval(cs__name, new_method_source)
|
45
40
|
rescue SyntaxError, StandardError => e
|
46
|
-
logger.debug(
|
41
|
+
logger.debug('Can\'t parse method source in scoped method', e, method: method_name)
|
47
42
|
body
|
48
43
|
end
|
44
|
+
|
45
|
+
# Good news, once we patch the body once, the source location
|
46
|
+
# becomes eval. We may need to fix this later though (so it may
|
47
|
+
# be bad news)
|
48
|
+
def _cs__location_available? location
|
49
|
+
return false if location.nil?
|
50
|
+
return false if location.empty? || location[0].empty? || location[0].include?('eval')
|
51
|
+
|
52
|
+
true
|
53
|
+
end
|
49
54
|
end
|
50
55
|
end
|
51
56
|
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
|
4
4
|
module Contrast
|
5
5
|
module CoreExtensions
|
6
|
-
# Our top level
|
6
|
+
# Our top level Assess namespace in the Core Extensions section of our
|
7
7
|
# code. These patches are those that are invoked directly from a patched
|
8
8
|
# Class.
|
9
9
|
#
|
@@ -31,7 +31,6 @@ module Contrast
|
|
31
31
|
cs__scoped_require 'contrast/agent/assess/policy/patcher'
|
32
32
|
|
33
33
|
# classes that don't play nice w/ our standard propagation
|
34
|
-
cs__scoped_require 'contrast/agent/assess/frozen_properties'
|
35
34
|
cs__scoped_require 'contrast/extensions/ruby_core/assess/assess_extension'
|
36
35
|
# this needs to come first b/c array and others work on strings and
|
37
36
|
# expect them to be trackable
|