contrast-agent 3.13.0 → 3.16.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 +18 -16
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.h +1 -0
- 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 +31 -16
- data/ext/cs__assess_string/cs__assess_string.h +6 -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 +48 -39
- data/ext/cs__common/cs__common.h +16 -21
- 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 -46
- data/lib/contrast/agent/assess.rb +12 -12
- data/lib/contrast/agent/assess/contrast_event.rb +151 -85
- data/lib/contrast/agent/assess/events/event_factory.rb +2 -2
- data/lib/contrast/agent/assess/events/source_event.rb +3 -3
- data/lib/contrast/agent/assess/finalizers/freeze.rb +15 -0
- data/lib/contrast/agent/assess/finalizers/hash.rb +97 -0
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +11 -4
- data/lib/contrast/agent/assess/policy/patcher.rb +6 -6
- data/lib/contrast/agent/assess/policy/policy.rb +9 -11
- data/lib/contrast/agent/assess/policy/policy_node.rb +17 -12
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +9 -4
- data/lib/contrast/agent/assess/policy/preshift.rb +13 -7
- data/lib/contrast/agent/assess/policy/propagation_method.rb +64 -44
- 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/append.rb +8 -5
- data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/center.rb +9 -5
- data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/database_write.rb +6 -4
- data/lib/contrast/agent/assess/policy/propagator/insert.rb +7 -4
- data/lib/contrast/agent/assess/policy/propagator/keep.rb +4 -1
- data/lib/contrast/agent/assess/policy/propagator/match_data.rb +7 -9
- data/lib/contrast/agent/assess/policy/propagator/next.rb +7 -5
- data/lib/contrast/agent/assess/policy/propagator/prepend.rb +13 -5
- data/lib/contrast/agent/assess/policy/propagator/remove.rb +8 -4
- data/lib/contrast/agent/assess/policy/propagator/replace.rb +5 -2
- data/lib/contrast/agent/assess/policy/propagator/reverse.rb +7 -5
- data/lib/contrast/agent/assess/policy/propagator/select.rb +13 -7
- data/lib/contrast/agent/assess/policy/propagator/splat.rb +10 -9
- data/lib/contrast/agent/assess/policy/propagator/split.rb +27 -22
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +52 -35
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +11 -5
- data/lib/contrast/agent/assess/policy/rewriter_patch.rb +5 -5
- data/lib/contrast/agent/assess/policy/source_method.rb +90 -72
- 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/reflected_xss.rb +16 -12
- data/lib/contrast/agent/assess/policy/trigger/xpath.rb +2 -2
- data/lib/contrast/agent/assess/policy/trigger_method.rb +81 -33
- data/lib/contrast/agent/assess/policy/trigger_node.rb +41 -46
- data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -1
- data/lib/contrast/agent/assess/policy/trigger_validation/trigger_validation.rb +2 -2
- data/lib/contrast/agent/assess/properties.rb +15 -5
- data/lib/contrast/agent/assess/property/evented.rb +7 -20
- data/lib/contrast/agent/assess/property/tagged.rb +13 -7
- data/lib/contrast/agent/assess/property/updated.rb +131 -0
- 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_key.rb +58 -5
- data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +24 -9
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +84 -16
- data/lib/contrast/agent/assess/tag.rb +1 -1
- data/lib/contrast/agent/assess/tracker.rb +66 -0
- data/lib/contrast/agent/at_exit_hook.rb +6 -6
- data/lib/contrast/agent/class_reopener.rb +14 -11
- 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 +32 -32
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +9 -9
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +23 -22
- data/lib/contrast/agent/patching/policy/module_policy.rb +11 -11
- data/lib/contrast/agent/patching/policy/patch.rb +15 -15
- data/lib/contrast/agent/patching/policy/patcher.rb +43 -44
- data/lib/contrast/agent/patching/policy/policy.rb +23 -12
- 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 +6 -8
- 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 +4 -4
- 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/no_sqli/mongo_no_sql_scanner.rb +1 -0
- 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 +45 -43
- data/lib/contrast/agent/request_context.rb +10 -6
- data/lib/contrast/agent/response.rb +23 -12
- data/lib/contrast/agent/rewriter.rb +6 -9
- data/lib/contrast/agent/service_heartbeat.rb +2 -2
- data/lib/contrast/agent/static_analysis.rb +9 -9
- 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 +3 -6
- data/lib/contrast/api/communication/response_processor.rb +1 -1
- data/lib/contrast/api/communication/socket_client.rb +41 -6
- 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 +20 -19
- data/lib/contrast/api/decorators/application_settings.rb +3 -2
- data/lib/contrast/api/decorators/application_update.rb +7 -8
- 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 +4 -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 +28 -25
- 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 +50 -39
- data/lib/contrast/components/config.rb +7 -17
- data/lib/contrast/components/contrast_service.rb +10 -10
- 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/components/settings.rb +20 -23
- data/lib/contrast/config.rb +18 -18
- data/lib/contrast/config/application_configuration.rb +5 -2
- data/lib/contrast/config/base_configuration.rb +2 -2
- data/lib/contrast/config/protect_rule_configuration.rb +1 -1
- data/lib/contrast/config/service_configuration.rb +8 -0
- data/lib/contrast/configuration.rb +93 -52
- data/lib/contrast/extension/assess.rb +21 -22
- data/lib/contrast/extension/assess/array.rb +18 -11
- data/lib/contrast/extension/assess/erb.rb +11 -3
- data/lib/contrast/extension/assess/eval_trigger.rb +7 -7
- data/lib/contrast/extension/assess/exec_trigger.rb +2 -2
- data/lib/contrast/extension/assess/fiber.rb +14 -14
- data/lib/contrast/extension/assess/hash.rb +7 -6
- data/lib/contrast/extension/assess/kernel.rb +34 -28
- data/lib/contrast/extension/assess/marshal.rb +67 -0
- data/lib/contrast/extension/assess/regexp.rb +10 -9
- data/lib/contrast/extension/assess/string.rb +23 -23
- 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 +4 -4
- data/lib/contrast/extension/protect/psych.rb +2 -2
- data/lib/contrast/framework/base_support.rb +1 -1
- data/lib/contrast/framework/manager.rb +10 -11
- data/lib/contrast/framework/rack/patch/session_cookie.rb +22 -28
- 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/action_controller_live_buffer.rb +13 -13
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +6 -12
- data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +11 -11
- data/lib/contrast/framework/rails/patch/support.rb +4 -4
- data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +11 -11
- data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +12 -12
- data/lib/contrast/framework/rails/rewrite/active_record_named.rb +4 -4
- data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +12 -12
- data/lib/contrast/framework/rails/support.rb +64 -14
- data/lib/contrast/framework/sinatra/patch/base.rb +12 -12
- data/lib/contrast/framework/sinatra/patch/support.rb +1 -1
- data/lib/contrast/framework/sinatra/support.rb +6 -6
- data/lib/contrast/funchook/funchook.rb +1 -1
- data/lib/contrast/logger/application.rb +13 -5
- data/lib/contrast/logger/format.rb +22 -9
- data/lib/contrast/logger/log.rb +17 -10
- 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 +49 -4
- data/lib/contrast/utils/boolean_util.rb +1 -1
- data/lib/contrast/utils/class_util.rb +2 -2
- data/lib/contrast/utils/duck_utils.rb +0 -10
- data/lib/contrast/utils/env_configuration_item.rb +2 -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 +21 -22
- 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 +11 -6
- data/resources/assess/policy.json +31 -22
- data/resources/deadzone/policy.json +5 -0
- data/ruby-agent.gemspec +21 -19
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +67 -29
- data/lib/contrast/agent/assess/insulator.rb +0 -49
- data/lib/contrast/agent/require_state.rb +0 -61
- data/lib/contrast/extension/assess/assess_extension.rb +0 -147
- data/lib/contrast/utils/freeze_util.rb +0 -32
@@ -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
|
@@ -47,8 +47,6 @@ module Contrast
|
|
47
47
|
return if scope_for_current_ec.instance_variable_get(:@contrast_scope) > 1
|
48
48
|
|
49
49
|
target = info_hash[:back_ref]
|
50
|
-
return unless Contrast::Utils::DuckUtils.trackable?(target)
|
51
|
-
|
52
50
|
with_contrast_scope do
|
53
51
|
result = info_hash[:result]
|
54
52
|
return unless result
|
@@ -56,8 +54,11 @@ module Contrast
|
|
56
54
|
string = info_hash[:string]
|
57
55
|
return unless string
|
58
56
|
|
59
|
-
|
60
|
-
|
57
|
+
properties = Contrast::Agent::Assess::Tracker.properties(target)
|
58
|
+
return unless properties
|
59
|
+
|
60
|
+
properties.splat_from(string, target)
|
61
|
+
properties.build_event(
|
61
62
|
REGEXP_EQUAL_SQUIGGLE_NODE,
|
62
63
|
target,
|
63
64
|
self,
|
@@ -70,9 +71,9 @@ module Contrast
|
|
70
71
|
|
71
72
|
def instrument_regexp_track
|
72
73
|
@_instrument_regexp_track ||= begin
|
73
|
-
|
74
|
-
|
75
|
-
|
74
|
+
require 'cs__assess_regexp/cs__assess_regexp'
|
75
|
+
true
|
76
|
+
end
|
76
77
|
rescue StandardError, LoadError => e
|
77
78
|
logger.error('Error loading regexp track patch', e)
|
78
79
|
false
|
@@ -1,15 +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
|
-
|
6
|
-
cs__scoped_require 'contrast/extension/assess/assess_extension'
|
7
|
-
|
8
|
-
# This patch installs our extension as early as possible. The alternative is to
|
9
|
-
# litter our code with Contrast::Utils::DuckUtils.trackable? checks.
|
10
|
-
class String
|
11
|
-
include Contrast::Extension::Assess::AssessExtension
|
12
|
-
end
|
4
|
+
require 'contrast/agent/assess/policy/propagation_node'
|
5
|
+
require 'contrast/components/interface'
|
13
6
|
|
14
7
|
module Contrast
|
15
8
|
module Extension
|
@@ -40,23 +33,32 @@ module Contrast
|
|
40
33
|
def track_interpolation inputs, result
|
41
34
|
return unless AGENT.interpolation_enabled?
|
42
35
|
return if in_contrast_scope?
|
43
|
-
return unless inputs.any?(
|
36
|
+
return unless inputs.any? { |input| Contrast::Agent::Assess::Tracker.tracked?(input) }
|
44
37
|
|
45
38
|
with_contrast_scope do
|
39
|
+
properties = Contrast::Agent::Assess::Tracker.properties(result)
|
40
|
+
return unless properties
|
41
|
+
|
42
|
+
parent_events = []
|
46
43
|
offset = 0
|
47
44
|
inputs.each do |input|
|
48
|
-
|
45
|
+
properties.copy_from(input, result, offset)
|
49
46
|
offset += input.length
|
47
|
+
parent_event = Contrast::Agent::Assess::Tracker.properties(input)&.event
|
48
|
+
parent_events << parent_event if parent_event
|
50
49
|
end
|
51
|
-
|
50
|
+
properties.build_event(INTERPOLATION_NODE, result, inputs, result, inputs)
|
51
|
+
properties.event.instance_variable_set(:@_parent_events, parent_events)
|
52
52
|
end
|
53
|
+
rescue StandardError => e
|
54
|
+
logger.error('Unable to track interpolation', e)
|
53
55
|
end
|
54
56
|
|
55
57
|
def instrument_string
|
56
58
|
@_instrument_string ||= begin
|
57
|
-
|
58
|
-
|
59
|
-
|
59
|
+
require 'cs__assess_string/cs__assess_string'
|
60
|
+
true
|
61
|
+
end
|
60
62
|
rescue StandardError, LoadError => e
|
61
63
|
logger.error('Error loading hash track patch', e)
|
62
64
|
false
|
@@ -65,14 +67,12 @@ module Contrast
|
|
65
67
|
def instrument_string_interpolation
|
66
68
|
if @_instrument_string_interpolation.nil?
|
67
69
|
@_instrument_string_interpolation = begin
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
false
|
75
|
-
end
|
70
|
+
require 'cs__assess_string_interpolation26/cs__assess_string_interpolation26' if AGENT.patch_interpolation? && Funchook.available?
|
71
|
+
true
|
72
|
+
rescue StandardError, LoadError => e
|
73
|
+
logger.error('Error loading interpolation patch', e)
|
74
|
+
false
|
75
|
+
end
|
76
76
|
end
|
77
77
|
@_instrument_string_interpolation
|
78
78
|
end
|
@@ -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,9 +30,9 @@ module Contrast
|
|
30
30
|
|
31
31
|
def instrument
|
32
32
|
@_instrument ||= begin
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
require 'cs__protect_kernel/cs__protect_kernel'
|
34
|
+
true
|
35
|
+
end
|
36
36
|
rescue StandardError, LoadError => e
|
37
37
|
logger.error('Error loading kernel protect patch', e)
|
38
38
|
false
|
@@ -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
|
@@ -46,7 +46,7 @@ module Contrast
|
|
46
46
|
#
|
47
47
|
# By default, and hopefully in all cases, we won't need these patches,
|
48
48
|
# so we're allowing nil here rather than raising an exception.
|
49
|
-
def before_load_patches
|
49
|
+
def before_load_patches!; end
|
50
50
|
|
51
51
|
# Some Frameworks require specific patching for their classes to handle
|
52
52
|
# functionality like routing. To accommodate this, this method provides
|
@@ -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
|
@@ -39,9 +39,9 @@ module Contrast
|
|
39
39
|
# configuration.
|
40
40
|
def before_load_patches!
|
41
41
|
@_before_load_patches ||= begin
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
SUPPORTED_FRAMEWORKS.each(&:before_load_patches!)
|
43
|
+
true
|
44
|
+
end
|
45
45
|
end
|
46
46
|
|
47
47
|
# Return all the After Load Patches for all the Frameworks we know, even
|
@@ -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
|
@@ -24,15 +24,15 @@ module Contrast
|
|
24
24
|
|
25
25
|
def instrument
|
26
26
|
@_instrument ||= begin
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
27
|
+
::Rack::Session::Cookie.class_eval do
|
28
|
+
alias_method :cs__patched_initialize, :initialize
|
29
|
+
def initialize app, options = {}
|
30
|
+
Contrast::Framework::Rack::Patch::SessionCookie.analyze(options)
|
31
|
+
cs__patched_initialize(app, options)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
true
|
35
|
+
end
|
36
36
|
end
|
37
37
|
|
38
38
|
def analyze options
|
@@ -67,12 +67,10 @@ module Contrast
|
|
67
67
|
options,
|
68
68
|
safe_default: false)
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
caller_locations(10, 9)[0])
|
75
|
-
end
|
70
|
+
cs__report_finding(
|
71
|
+
CS__SECURE_RULE_NAME,
|
72
|
+
options,
|
73
|
+
caller_locations(10, 9)[0])
|
76
74
|
rescue StandardError => e
|
77
75
|
begin
|
78
76
|
logger.error('Unable to track call to secure session', e)
|
@@ -88,12 +86,10 @@ module Contrast
|
|
88
86
|
safe_default: false,
|
89
87
|
comparison_type: :greater_than)
|
90
88
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
caller_locations(10, 9)[0])
|
96
|
-
end
|
89
|
+
cs__report_finding(
|
90
|
+
CS__SESSION_TIMEOUT_NAME,
|
91
|
+
options,
|
92
|
+
caller_locations(10, 9)[0])
|
97
93
|
rescue StandardError => e
|
98
94
|
begin
|
99
95
|
logger.error('Unable to track call to set session timeout', e)
|
@@ -105,12 +101,10 @@ module Contrast
|
|
105
101
|
def apply_httponly options
|
106
102
|
return unless vulnerable_setting?(:httponly, true, options)
|
107
103
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
caller_locations(10, 9)[0])
|
113
|
-
end
|
104
|
+
cs__report_finding(
|
105
|
+
CS__HTTPONLY_NAME,
|
106
|
+
options,
|
107
|
+
caller_locations(10, 9)[0])
|
114
108
|
rescue StandardError => e
|
115
109
|
begin
|
116
110
|
logger.error('Unable to track call to httponly', e)
|
@@ -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
|
@@ -19,19 +19,19 @@ module Contrast
|
|
19
19
|
|
20
20
|
def instrument
|
21
21
|
@_instrument ||= begin
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
22
|
+
::ActionController::Live::Buffer.class_eval do
|
23
|
+
# normally pre->in->post filters are applied however, in a streamed response
|
24
|
+
# we can run into a case where it's pre -> in -> post -> more infilters
|
25
|
+
# in order to submit anything found during the infilters after the response has
|
26
|
+
# been written we need to explicitly send them
|
27
|
+
alias_method :cs__close, :close
|
28
|
+
def close
|
29
|
+
Contrast::Framework::Rails::Patch::ActionControllerLiveBuffer.send_messages
|
30
|
+
cs__close
|
31
|
+
end
|
32
|
+
end
|
33
|
+
true
|
34
|
+
end
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -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
|
@@ -12,7 +12,7 @@ module Contrast
|
|
12
12
|
module AssessConfiguration
|
13
13
|
include Contrast::Components::Interface
|
14
14
|
|
15
|
-
access_component :agent, :analysis, :logging
|
15
|
+
access_component :agent, :analysis, :logging
|
16
16
|
|
17
17
|
CS__SESSION_TIMEOUT_NAME = 'session-timeout'
|
18
18
|
SAFE_SESSION_TIMEOUT = (30 * 60 * 1000)
|
@@ -52,9 +52,7 @@ module Contrast
|
|
52
52
|
return unless vulnerable_setting?(:expire_after, SAFE_SESSION_TIMEOUT, args, comparison_type: :greater_than, safe_default: false)
|
53
53
|
|
54
54
|
rails_session_settings = args[1]
|
55
|
-
|
56
|
-
cs__report_finding(CS__SESSION_TIMEOUT_NAME, rails_session_settings, caller_locations(6, 5)[0])
|
57
|
-
end
|
55
|
+
cs__report_finding(CS__SESSION_TIMEOUT_NAME, rails_session_settings, caller_locations(3, 2)[0])
|
58
56
|
rescue StandardError => e
|
59
57
|
begin
|
60
58
|
logger.error('Unable to track call to set session timeout', e)
|
@@ -68,9 +66,7 @@ module Contrast
|
|
68
66
|
return unless vulnerable_setting?(:secure, true, args)
|
69
67
|
|
70
68
|
rails_session_settings = args[1]
|
71
|
-
|
72
|
-
cs__report_finding(CS__SECURE_RULE_NAME, rails_session_settings, caller_locations(6, 5)[0])
|
73
|
-
end
|
69
|
+
cs__report_finding(CS__SECURE_RULE_NAME, rails_session_settings, caller_locations(3, 2)[0])
|
74
70
|
rescue StandardError => e
|
75
71
|
begin
|
76
72
|
logger.error('Unable to track call to disable secure cookies', e)
|
@@ -84,9 +80,7 @@ module Contrast
|
|
84
80
|
return unless vulnerable_setting?(:httponly, true, args)
|
85
81
|
|
86
82
|
rails_session_settings = args[1]
|
87
|
-
|
88
|
-
cs__report_finding(CS__HTTPONLY_RULE_NAME, rails_session_settings, caller_locations(6, 5)[0])
|
89
|
-
end
|
83
|
+
cs__report_finding(CS__HTTPONLY_RULE_NAME, rails_session_settings, caller_locations(3, 2)[0])
|
90
84
|
rescue StandardError => e
|
91
85
|
begin
|
92
86
|
logger.error('Unable to track call to disable httponly in session cookie', e)
|