contrast-agent 3.13.2 → 3.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/contrast_service +1 -7
- data/ext/cs__assess_active_record_named/cs__active_record_named.c +8 -7
- data/ext/cs__assess_array/cs__assess_array.c +6 -5
- data/ext/cs__assess_basic_object/cs__assess_basic_object.c +5 -5
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +2 -1
- data/ext/cs__assess_hash/cs__assess_hash.c +18 -17
- data/ext/cs__assess_hash/cs__assess_hash.h +2 -1
- data/ext/cs__assess_kernel/cs__assess_kernel.c +7 -8
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +4 -5
- data/ext/cs__assess_module/cs__assess_module.c +6 -6
- data/ext/cs__assess_regexp/cs__assess_regexp.c +4 -4
- data/ext/cs__assess_string/cs__assess_string.c +20 -4
- data/ext/cs__assess_string/cs__assess_string.h +4 -1
- data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +4 -2
- data/ext/cs__assess_yield_track/cs__assess_yield_track.c +2 -2
- data/ext/cs__common/cs__common.c +44 -37
- data/ext/cs__common/cs__common.h +15 -20
- data/ext/cs__contrast_patch/cs__contrast_patch.c +27 -25
- data/ext/cs__contrast_patch/cs__contrast_patch.h +5 -7
- data/ext/cs__protect_kernel/cs__protect_kernel.c +11 -12
- data/ext/cs__protect_kernel/cs__protect_kernel.h +2 -2
- data/lib/contrast-agent.rb +1 -1
- data/lib/contrast.rb +13 -23
- data/lib/contrast/agent.rb +39 -39
- data/lib/contrast/agent/assess.rb +11 -12
- data/lib/contrast/agent/assess/contrast_event.rb +11 -9
- data/lib/contrast/agent/assess/events/event_factory.rb +2 -2
- data/lib/contrast/agent/assess/events/source_event.rb +2 -2
- data/lib/contrast/agent/assess/finalizers/finalize.rb +21 -0
- data/lib/contrast/agent/assess/finalizers/freeze.rb +13 -0
- data/lib/contrast/agent/assess/finalizers/hash.rb +53 -0
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +1 -1
- data/lib/contrast/agent/assess/policy/patcher.rb +5 -5
- data/lib/contrast/agent/assess/policy/policy.rb +9 -9
- data/lib/contrast/agent/assess/policy/policy_node.rb +2 -2
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +3 -3
- data/lib/contrast/agent/assess/policy/preshift.rb +15 -5
- data/lib/contrast/agent/assess/policy/propagation_method.rb +25 -22
- data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -2
- data/lib/contrast/agent/assess/policy/propagator.rb +18 -18
- data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/database_write.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/match_data.rb +3 -2
- data/lib/contrast/agent/assess/policy/propagator/prepend.rb +5 -0
- data/lib/contrast/agent/assess/policy/propagator/split.rb +4 -4
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +5 -4
- data/lib/contrast/agent/assess/policy/rewriter_patch.rb +5 -5
- data/lib/contrast/agent/assess/policy/source_method.rb +5 -14
- data/lib/contrast/agent/assess/policy/source_validation/cross_site_validator.rb +1 -1
- data/lib/contrast/agent/assess/policy/source_validation/source_validation.rb +1 -1
- data/lib/contrast/agent/assess/policy/trigger/xpath.rb +1 -1
- data/lib/contrast/agent/assess/policy/trigger_method.rb +5 -5
- data/lib/contrast/agent/assess/policy/trigger_node.rb +3 -3
- data/lib/contrast/agent/assess/policy/trigger_validation/trigger_validation.rb +2 -2
- data/lib/contrast/agent/assess/properties.rb +13 -5
- data/lib/contrast/agent/assess/property/evented.rb +2 -2
- data/lib/contrast/agent/assess/property/tagged.rb +4 -4
- data/lib/contrast/agent/assess/rule.rb +2 -2
- data/lib/contrast/agent/assess/rule/base.rb +3 -4
- data/lib/contrast/agent/assess/rule/provider.rb +3 -3
- data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +1 -1
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +2 -2
- data/lib/contrast/agent/at_exit_hook.rb +1 -1
- data/lib/contrast/agent/class_reopener.rb +7 -6
- data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +1 -1
- data/lib/contrast/agent/deadzone/policy/policy.rb +2 -2
- data/lib/contrast/agent/disable_reaction.rb +1 -1
- data/lib/contrast/agent/exclusion_matcher.rb +1 -1
- data/lib/contrast/agent/inventory/policy/datastores.rb +2 -2
- data/lib/contrast/agent/inventory/policy/policy.rb +3 -3
- data/lib/contrast/agent/inventory/policy/trigger_node.rb +1 -1
- data/lib/contrast/agent/middleware.rb +33 -32
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +4 -4
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +6 -5
- data/lib/contrast/agent/patching/policy/module_policy.rb +1 -1
- data/lib/contrast/agent/patching/policy/patch.rb +15 -15
- data/lib/contrast/agent/patching/policy/patcher.rb +30 -22
- data/lib/contrast/agent/patching/policy/policy.rb +6 -6
- data/lib/contrast/agent/patching/policy/policy_node.rb +1 -1
- data/lib/contrast/agent/patching/policy/trigger_node.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +3 -3
- data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +3 -3
- data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +3 -3
- data/lib/contrast/agent/protect/policy/policy.rb +8 -8
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +1 -1
- data/lib/contrast/agent/protect/policy/trigger_node.rb +1 -1
- data/lib/contrast/agent/protect/rule.rb +18 -18
- data/lib/contrast/agent/protect/rule/base.rb +4 -3
- data/lib/contrast/agent/protect/rule/base_service.rb +1 -1
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +5 -5
- data/lib/contrast/agent/protect/rule/deserialization.rb +1 -1
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +1 -1
- data/lib/contrast/agent/protect/rule/no_sqli.rb +1 -1
- data/lib/contrast/agent/protect/rule/path_traversal.rb +4 -5
- data/lib/contrast/agent/protect/rule/sqli.rb +2 -2
- data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +1 -1
- data/lib/contrast/agent/protect/rule/xss.rb +1 -1
- data/lib/contrast/agent/protect/rule/xxe.rb +3 -5
- data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +2 -2
- data/lib/contrast/agent/railtie.rb +1 -1
- data/lib/contrast/agent/reaction_processor.rb +2 -2
- data/lib/contrast/agent/request.rb +11 -9
- data/lib/contrast/agent/request_context.rb +10 -6
- data/lib/contrast/agent/response.rb +6 -6
- data/lib/contrast/agent/rewriter.rb +5 -6
- data/lib/contrast/agent/service_heartbeat.rb +2 -2
- data/lib/contrast/agent/static_analysis.rb +3 -3
- data/lib/contrast/agent/thread.rb +1 -1
- data/lib/contrast/agent/thread_watcher.rb +2 -2
- data/lib/contrast/agent/tracepoint_hook.rb +1 -1
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/api.rb +4 -4
- data/lib/contrast/api/communication.rb +9 -9
- data/lib/contrast/api/communication/messaging_queue.rb +2 -2
- data/lib/contrast/api/communication/response_processor.rb +1 -1
- data/lib/contrast/api/communication/socket_client.rb +5 -5
- data/lib/contrast/api/communication/speedracer.rb +1 -1
- data/lib/contrast/api/communication/tcp_socket.rb +1 -1
- data/lib/contrast/api/communication/unix_socket.rb +1 -1
- data/lib/contrast/api/decorators.rb +14 -14
- data/lib/contrast/api/decorators/address.rb +7 -6
- data/lib/contrast/api/decorators/application_settings.rb +3 -2
- data/lib/contrast/api/decorators/application_update.rb +5 -4
- data/lib/contrast/api/decorators/http_request.rb +13 -12
- data/lib/contrast/api/decorators/input_analysis.rb +3 -2
- data/lib/contrast/api/decorators/message.rb +3 -2
- data/lib/contrast/api/decorators/rasp_rule_sample.rb +2 -1
- data/lib/contrast/api/decorators/route_coverage.rb +3 -2
- data/lib/contrast/api/decorators/server_features.rb +3 -2
- data/lib/contrast/api/decorators/trace_event.rb +3 -2
- data/lib/contrast/api/decorators/trace_event_object.rb +6 -5
- data/lib/contrast/api/decorators/trace_event_signature.rb +5 -4
- data/lib/contrast/api/decorators/trace_taint_range.rb +4 -3
- data/lib/contrast/api/decorators/user_input.rb +4 -4
- data/lib/contrast/common_agent_configuration.rb +2 -2
- data/lib/contrast/components/agent.rb +2 -2
- data/lib/contrast/components/app_context.rb +1 -1
- data/lib/contrast/components/config.rb +4 -4
- data/lib/contrast/components/contrast_service.rb +1 -1
- data/lib/contrast/components/interface.rb +15 -15
- data/lib/contrast/components/logger.rb +1 -1
- data/lib/contrast/components/scope.rb +3 -3
- data/lib/contrast/config.rb +18 -18
- data/lib/contrast/config/base_configuration.rb +2 -2
- data/lib/contrast/config/protect_rule_configuration.rb +1 -1
- data/lib/contrast/configuration.rb +5 -5
- data/lib/contrast/extension/assess.rb +22 -21
- data/lib/contrast/extension/assess/array.rb +4 -4
- data/lib/contrast/extension/assess/assess_extension.rb +27 -29
- data/lib/contrast/extension/assess/eval_trigger.rb +3 -3
- data/lib/contrast/extension/assess/exec_trigger.rb +1 -1
- data/lib/contrast/extension/assess/fiber.rb +3 -3
- data/lib/contrast/extension/assess/hash.rb +5 -3
- data/lib/contrast/extension/assess/kernel.rb +7 -6
- data/lib/contrast/extension/assess/marshal.rb +62 -0
- data/lib/contrast/extension/assess/regexp.rb +3 -3
- data/lib/contrast/extension/assess/string.rb +5 -5
- data/lib/contrast/extension/inventory.rb +4 -4
- data/lib/contrast/extension/kernel.rb +1 -1
- data/lib/contrast/extension/module.rb +1 -1
- data/lib/contrast/extension/protect.rb +3 -3
- data/lib/contrast/extension/protect/kernel.rb +2 -2
- data/lib/contrast/extension/protect/psych.rb +2 -2
- data/lib/contrast/framework/manager.rb +7 -8
- data/lib/contrast/framework/rack/patch/session_cookie.rb +1 -1
- data/lib/contrast/framework/rack/patch/support.rb +1 -1
- data/lib/contrast/framework/rack/support.rb +2 -2
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +2 -2
- data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +1 -1
- data/lib/contrast/framework/rails/patch/support.rb +3 -3
- data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +2 -2
- data/lib/contrast/framework/rails/rewrite/active_record_named.rb +2 -2
- data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +2 -2
- data/lib/contrast/framework/rails/support.rb +62 -14
- data/lib/contrast/framework/sinatra/patch/base.rb +1 -1
- data/lib/contrast/framework/sinatra/patch/support.rb +1 -1
- data/lib/contrast/framework/sinatra/support.rb +2 -2
- data/lib/contrast/funchook/funchook.rb +1 -1
- data/lib/contrast/logger/application.rb +2 -2
- data/lib/contrast/logger/format.rb +22 -9
- data/lib/contrast/logger/log.rb +10 -8
- data/lib/contrast/logger/request.rb +30 -0
- data/lib/contrast/tasks/config.rb +1 -1
- data/lib/contrast/tasks/service.rb +2 -2
- data/lib/contrast/utils/assess/sampling_util.rb +2 -2
- data/lib/contrast/utils/assess/tracking_util.rb +1 -1
- data/lib/contrast/utils/boolean_util.rb +1 -1
- data/lib/contrast/utils/class_util.rb +2 -2
- data/lib/contrast/utils/freeze_util.rb +1 -1
- data/lib/contrast/utils/gemfile_reader.rb +5 -5
- data/lib/contrast/utils/hash_digest.rb +2 -1
- data/lib/contrast/utils/heap_dump_util.rb +2 -2
- data/lib/contrast/utils/invalid_configuration_util.rb +1 -1
- data/lib/contrast/utils/inventory_util.rb +4 -4
- data/lib/contrast/utils/io_util.rb +1 -1
- data/lib/contrast/utils/os.rb +1 -1
- data/lib/contrast/utils/ruby_ast_rewriter.rb +1 -1
- data/lib/contrast/utils/sha256_builder.rb +2 -2
- data/lib/contrast/utils/stack_trace_utils.rb +2 -2
- data/lib/contrast/utils/string_utils.rb +1 -1
- data/ruby-agent.gemspec +5 -5
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +22 -19
- data/lib/contrast/agent/assess/insulator.rb +0 -49
- data/lib/contrast/agent/require_state.rb +0 -61
@@ -1,8 +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
|
-
|
5
|
-
|
4
|
+
require 'contrast/agent/assess/policy/propagation_node'
|
5
|
+
require 'contrast/components/interface'
|
6
6
|
|
7
7
|
module Contrast
|
8
8
|
module Extension
|
@@ -70,7 +70,7 @@ module Contrast
|
|
70
70
|
|
71
71
|
def instrument_regexp_track
|
72
72
|
@_instrument_regexp_track ||= begin
|
73
|
-
|
73
|
+
require 'cs__assess_regexp/cs__assess_regexp'
|
74
74
|
true
|
75
75
|
end
|
76
76
|
rescue StandardError, LoadError => e
|
@@ -1,9 +1,9 @@
|
|
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
|
-
|
5
|
-
|
6
|
-
|
4
|
+
require 'contrast/agent/assess/policy/propagation_node'
|
5
|
+
require 'contrast/components/interface'
|
6
|
+
require 'contrast/extension/assess/assess_extension'
|
7
7
|
|
8
8
|
# This patch installs our extension as early as possible. The alternative is to
|
9
9
|
# litter our code with Contrast::Utils::DuckUtils.trackable? checks.
|
@@ -54,7 +54,7 @@ module Contrast
|
|
54
54
|
|
55
55
|
def instrument_string
|
56
56
|
@_instrument_string ||= begin
|
57
|
-
|
57
|
+
require 'cs__assess_string/cs__assess_string'
|
58
58
|
true
|
59
59
|
end
|
60
60
|
rescue StandardError, LoadError => e
|
@@ -66,7 +66,7 @@ module Contrast
|
|
66
66
|
if @_instrument_string_interpolation.nil?
|
67
67
|
@_instrument_string_interpolation = begin
|
68
68
|
if AGENT.patch_interpolation? && Funchook.available?
|
69
|
-
|
69
|
+
require 'cs__assess_string_interpolation26/cs__assess_string_interpolation26'
|
70
70
|
end
|
71
71
|
true
|
72
72
|
rescue StandardError, LoadError => e
|
@@ -11,11 +11,11 @@ module Contrast
|
|
11
11
|
# relevant given the move to C based patching and the lessons learned
|
12
12
|
# therein.
|
13
13
|
module Inventory
|
14
|
-
|
14
|
+
require 'contrast/security_exception'
|
15
15
|
# patching
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
require 'contrast/agent/inventory/policy/trigger_node'
|
17
|
+
require 'contrast/agent/inventory/policy/policy'
|
18
|
+
require 'contrast/agent/patching/policy/patcher'
|
19
19
|
end
|
20
20
|
end
|
21
21
|
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
|
-
|
4
|
+
require 'contrast/components/scope'
|
5
5
|
|
6
6
|
# This is a reasonable place for the Kernel#catch hook to live.
|
7
7
|
# No current plans for component re-design, but if we had some kind of
|
@@ -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
|
-
|
4
|
+
require 'contrast/utils/object_share'
|
5
5
|
|
6
6
|
# Some developers override various methods on Module, which can often involve
|
7
7
|
# changing expected method parity/behavior which in turn prevents us from being
|
@@ -11,10 +11,10 @@ module Contrast
|
|
11
11
|
# relevant given the move to C based patching and the lessons learned
|
12
12
|
# therein.
|
13
13
|
module Protect
|
14
|
-
|
14
|
+
require 'contrast/security_exception'
|
15
15
|
# patching
|
16
|
-
|
17
|
-
|
16
|
+
require 'contrast/agent/protect/policy/trigger_node'
|
17
|
+
require 'contrast/agent/protect/policy/policy'
|
18
18
|
end
|
19
19
|
end
|
20
20
|
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
|
-
|
4
|
+
require 'contrast/components/interface'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Extension
|
@@ -30,7 +30,7 @@ module Contrast
|
|
30
30
|
|
31
31
|
def instrument
|
32
32
|
@_instrument ||= begin
|
33
|
-
|
33
|
+
require 'cs__protect_kernel/cs__protect_kernel'
|
34
34
|
true
|
35
35
|
end
|
36
36
|
rescue StandardError, LoadError => e
|
@@ -2,6 +2,6 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
if defined?(Psych)
|
5
|
-
|
6
|
-
|
5
|
+
require 'contrast/agent/protect/policy/applies_deserialization_rule'
|
6
|
+
require 'cs__patched_psych/cs__patched_psych'
|
7
7
|
end
|
@@ -1,12 +1,12 @@
|
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
4
|
+
require 'contrast/framework/platform_version'
|
5
|
+
require 'contrast/framework/rack/support'
|
6
|
+
require 'contrast/framework/rails/support'
|
7
|
+
require 'contrast/framework/sinatra/support'
|
8
|
+
require 'contrast/components/interface'
|
9
|
+
require 'contrast/utils/class_util'
|
10
10
|
|
11
11
|
module Contrast
|
12
12
|
module Framework
|
@@ -128,10 +128,9 @@ module Contrast
|
|
128
128
|
# @param method_name [Symbol] the method to call on each FrameworkSupport class
|
129
129
|
# @return [Array]
|
130
130
|
def data_for_all_frameworks method_name
|
131
|
-
|
131
|
+
@_frameworks.flat_map do |framework|
|
132
132
|
framework.send(method_name)
|
133
133
|
end.compact
|
134
|
-
data
|
135
134
|
end
|
136
135
|
|
137
136
|
# This returns a single object from the first framework to successfully respond
|
@@ -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
|
-
|
4
|
+
require 'contrast/components/interface'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Framework
|
@@ -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
|
-
|
4
|
+
require 'contrast/agent/patching/policy/after_load_patch'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Framework
|
@@ -1,8 +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
|
-
|
5
|
-
|
4
|
+
require 'contrast/framework/base_support'
|
5
|
+
require 'contrast/framework/rack/patch/support'
|
6
6
|
|
7
7
|
module Contrast
|
8
8
|
module Framework
|
@@ -1,8 +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
|
-
|
5
|
-
|
4
|
+
require 'contrast/components/interface'
|
5
|
+
require 'contrast/utils/invalid_configuration_util'
|
6
6
|
|
7
7
|
module Contrast
|
8
8
|
module Framework
|
@@ -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
|
-
|
4
|
+
require 'contrast/framework/rails/patch/assess_configuration'
|
5
5
|
module Contrast
|
6
6
|
module Framework
|
7
7
|
module Rails
|
@@ -1,8 +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
|
-
|
5
|
-
|
4
|
+
require 'contrast/framework/rails/patch/rails_application_configuration'
|
5
|
+
require 'contrast/agent/patching/policy/after_load_patch'
|
6
6
|
|
7
7
|
module Contrast
|
8
8
|
module Framework
|
@@ -20,7 +20,7 @@ module Contrast
|
|
20
20
|
# (i.e., where we normally patch) we will miss the configuration
|
21
21
|
# and will never be able to report session misconfiguration rules.
|
22
22
|
Contrast::Framework::Rails::Patch::RailsApplicationConfiguration.instrument
|
23
|
-
|
23
|
+
require 'contrast/agent/railtie' if ::Rails::VERSION::MAJOR.to_i >= 3
|
24
24
|
end
|
25
25
|
|
26
26
|
# (See BaseSupport#after_load_patches)
|
@@ -17,9 +17,9 @@ module Contrast
|
|
17
17
|
@_instrument ||= begin
|
18
18
|
::ActionController::Railties::Helpers.class_eval do
|
19
19
|
alias_method :cs__patched_helper_inherited, :inherited
|
20
|
-
def inherited klass
|
20
|
+
def inherited klass # rubocop:disable Lint/MissingSuper
|
21
21
|
klass&.instance_variable_set(:@cs__defining_class, true)
|
22
|
-
cs__patched_helper_inherited(klass)
|
22
|
+
cs__patched_helper_inherited(klass) # This calls the original inherited, which should handle super as needed.
|
23
23
|
ensure
|
24
24
|
klass&.instance_variable_set(:@cs__defining_class, false)
|
25
25
|
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
|
-
|
4
|
+
require 'contrast/components/interface'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Framework
|
@@ -58,7 +58,7 @@ module Contrast
|
|
58
58
|
|
59
59
|
def instrument
|
60
60
|
@_instrument_named_track ||= begin
|
61
|
-
|
61
|
+
require 'cs__assess_active_record_named/cs__assess_active_record_named'
|
62
62
|
true
|
63
63
|
end
|
64
64
|
rescue StandardError, LoadError => e
|
@@ -16,9 +16,9 @@ module Contrast
|
|
16
16
|
private
|
17
17
|
|
18
18
|
alias_method :cs__patched_inherited, :inherited
|
19
|
-
def inherited klass
|
19
|
+
def inherited klass # rubocop:disable Lint/MissingSuper
|
20
20
|
klass&.instance_variable_set(:@cs__defining_class, true)
|
21
|
-
cs__patched_inherited(klass)
|
21
|
+
cs__patched_inherited(klass) # This calls the original inherited, which should handle super as needed.
|
22
22
|
ensure
|
23
23
|
klass&.instance_variable_set(:@cs__defining_class, false)
|
24
24
|
end
|
@@ -1,10 +1,10 @@
|
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
require 'contrast/api/dtm.pb'
|
5
|
+
require 'contrast/framework/base_support'
|
6
|
+
require 'contrast/framework/rails/patch/support'
|
7
|
+
require 'contrast/utils/string_utils'
|
8
8
|
|
9
9
|
module Contrast
|
10
10
|
module Framework
|
@@ -42,10 +42,7 @@ module Contrast
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def collect_routes
|
45
|
-
|
46
|
-
Contrast::Api::Dtm::RouteCoverage.from_action_dispatch_journey(route)
|
47
|
-
end
|
48
|
-
routes
|
45
|
+
find_all_routes(::Rails.application, [])
|
49
46
|
end
|
50
47
|
|
51
48
|
def current_route request
|
@@ -59,13 +56,17 @@ module Contrast
|
|
59
56
|
full_routes = ::Rails.application.routes.router.send(:find_routes, request.rack_request)
|
60
57
|
return if full_routes.empty?
|
61
58
|
|
62
|
-
full_route = full_routes[0]
|
63
|
-
return unless full_route
|
64
|
-
|
65
|
-
route = full_route[2] # route w/ highest precedence
|
66
|
-
return unless route
|
59
|
+
full_route = full_routes[0]
|
67
60
|
|
68
|
-
|
61
|
+
# the route is directly implemented within the application
|
62
|
+
if direct_route?(full_route)
|
63
|
+
route = full_route[2] # route w/ highest precedence
|
64
|
+
Contrast::Api::Dtm::RouteCoverage.from_action_dispatch_journey(route)
|
65
|
+
else
|
66
|
+
engine_route(full_route, request)
|
67
|
+
end
|
68
|
+
rescue StandardError => _e
|
69
|
+
nil
|
69
70
|
end
|
70
71
|
|
71
72
|
def retrieve_request env
|
@@ -79,6 +80,53 @@ module Contrast
|
|
79
80
|
|
80
81
|
env[AC_INSTANCE].cs__class.included_modules.include?(::ActionController::Live)
|
81
82
|
end
|
83
|
+
|
84
|
+
private
|
85
|
+
|
86
|
+
# route is not mounted within an engine
|
87
|
+
def direct_route? full_route
|
88
|
+
full_route[2]&.app&.cs__class == ActionDispatch::Routing::RouteSet::Dispatcher ||
|
89
|
+
(full_route[2].cs__class == ActionDispatch::Journey::Route && full_route[2]&.app&.cs__class == ActionDispatch::Routing::Mapper::Constraints)
|
90
|
+
end
|
91
|
+
|
92
|
+
def engine_route full_route, request
|
93
|
+
engine_route = full_route[2] # supposed route - but actually an Engine mount point
|
94
|
+
return unless engine_route
|
95
|
+
|
96
|
+
engine_mount_name = engine_route.name
|
97
|
+
return unless engine_mount_name
|
98
|
+
|
99
|
+
engine_path_segments = request.rack_request.path_info.split(engine_mount_name)
|
100
|
+
return if engine_path_segments.empty?
|
101
|
+
|
102
|
+
path_within_engine = engine_path_segments[-1]
|
103
|
+
return unless path_within_engine
|
104
|
+
|
105
|
+
engine_router = engine_route.app&.app&.routes&.router
|
106
|
+
return unless engine_router
|
107
|
+
|
108
|
+
# Get all routes regardless of http method
|
109
|
+
matching_routes = engine_router.send(:filter_routes, path_within_engine)
|
110
|
+
return unless matching_routes
|
111
|
+
|
112
|
+
# filter for current http method
|
113
|
+
reportable_routes = engine_router.send(:match_routes, matching_routes, request.rack_request)
|
114
|
+
return if reportable_routes.empty?
|
115
|
+
|
116
|
+
Contrast::Api::Dtm::RouteCoverage.from_action_dispatch_journey(reportable_routes[0])
|
117
|
+
end
|
118
|
+
|
119
|
+
# Rails engine routes need to be detected by inspecting Engine class route set
|
120
|
+
def find_all_routes app, route_list
|
121
|
+
app.routes.routes.each do |route|
|
122
|
+
if route.cs__respond_to?(:app) && route.app.cs__class == ActionDispatch::Routing::RouteSet::Dispatcher
|
123
|
+
route_list << Contrast::Api::Dtm::RouteCoverage.from_action_dispatch_journey(route)
|
124
|
+
elsif route.app.app.cs__respond_to?(:routes)
|
125
|
+
route_list += find_all_routes(route.app.app, [])
|
126
|
+
end
|
127
|
+
end
|
128
|
+
route_list
|
129
|
+
end
|
82
130
|
end
|
83
131
|
end
|
84
132
|
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
|
-
|
4
|
+
require 'contrast/framework/sinatra/support'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Framework
|
@@ -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
|
-
|
4
|
+
require 'contrast/agent/patching/policy/after_load_patch'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Framework
|
@@ -1,8 +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
|
-
|
5
|
-
|
4
|
+
require 'contrast/framework/base_support'
|
5
|
+
require 'contrast/framework/sinatra/patch/support'
|
6
6
|
|
7
7
|
module Contrast
|
8
8
|
module Framework
|
@@ -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
|
-
|
4
|
+
require 'contrast/components/interface'
|
5
5
|
# This module is used to find funchook library and determine availability
|
6
6
|
module Funchook
|
7
7
|
include Contrast::Components::Interface
|
@@ -1,11 +1,11 @@
|
|
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
|
-
|
4
|
+
require 'contrast/components/interface'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Logger
|
8
|
-
#
|
8
|
+
# Our decorator for the Ougai logger allowing for the logging of the
|
9
9
|
# application environment, used to provide context during troubleshooting.
|
10
10
|
module Application
|
11
11
|
include Contrast::Components::Interface
|
@@ -1,8 +1,9 @@
|
|
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
|
-
|
5
|
-
|
4
|
+
require 'ougai'
|
5
|
+
require 'contrast/utils/object_share'
|
6
|
+
require 'contrast/utils/thread_tracker'
|
6
7
|
|
7
8
|
module Contrast
|
8
9
|
module Logger
|
@@ -31,21 +32,33 @@ module Contrast
|
|
31
32
|
|
32
33
|
private
|
33
34
|
|
34
|
-
# The extra values to add to the Bunyan hash.
|
35
|
-
# thread, we'll create it once and then store it, rather than create a
|
36
|
-
# new hash on every log call.
|
35
|
+
# The extra values to add to the Bunyan hash.
|
37
36
|
# @return [Hash{Symbol => Object}] the extra data to log
|
38
|
-
# tid: current thread id
|
39
37
|
def format_hash
|
40
|
-
|
38
|
+
thread_hash.merge(request_hash)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Because this is unique per thread, we'll create it once and then store
|
42
|
+
# it, rather than create a new hash on every log call during the request.
|
43
|
+
def thread_hash
|
44
|
+
hash = LOG_TRACKER.get(:logging_hash)
|
41
45
|
unless hash
|
42
46
|
hash = {
|
43
|
-
|
47
|
+
thread_id: Thread.current.object_id
|
44
48
|
}
|
45
|
-
LOG_TRACKER.set(:
|
49
|
+
LOG_TRACKER.set(:logging_hash, hash)
|
46
50
|
end
|
47
51
|
hash
|
48
52
|
end
|
53
|
+
|
54
|
+
NO_REQUEST_HASH = { request_id: -1 }.cs__freeze
|
55
|
+
def request_hash
|
56
|
+
@request_tracker_defined ||= defined?(Contrast::Agent) &&
|
57
|
+
defined?(Contrast::Agent::REQUEST_TRACKER)
|
58
|
+
return NO_REQUEST_HASH unless @request_tracker_defined
|
59
|
+
|
60
|
+
Contrast::Agent::REQUEST_TRACKER&.current&.logging_hash || NO_REQUEST_HASH
|
61
|
+
end
|
49
62
|
end
|
50
63
|
end
|
51
64
|
end
|