contrast-agent 4.2.0 → 4.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +1 -0
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +22 -10
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.h +4 -3
- data/lib/contrast/agent.rb +5 -1
- data/lib/contrast/agent/assess.rb +0 -9
- data/lib/contrast/agent/assess/contrast_event.rb +49 -132
- data/lib/contrast/agent/assess/contrast_object.rb +54 -0
- data/lib/contrast/agent/assess/events/source_event.rb +4 -9
- data/lib/contrast/agent/assess/finalizers/hash.rb +7 -0
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +17 -3
- data/lib/contrast/agent/assess/policy/patcher.rb +4 -3
- data/lib/contrast/agent/assess/policy/policy_node.rb +31 -59
- data/lib/contrast/agent/assess/policy/preshift.rb +3 -3
- data/lib/contrast/agent/assess/policy/propagation_method.rb +41 -32
- data/lib/contrast/agent/assess/policy/propagation_node.rb +12 -24
- data/lib/contrast/agent/assess/policy/propagator/append.rb +29 -15
- data/lib/contrast/agent/assess/policy/propagator/center.rb +1 -2
- data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/database_write.rb +21 -18
- data/lib/contrast/agent/assess/policy/propagator/insert.rb +1 -2
- data/lib/contrast/agent/assess/policy/propagator/keep.rb +1 -2
- data/lib/contrast/agent/assess/policy/propagator/match_data.rb +3 -2
- data/lib/contrast/agent/assess/policy/propagator/next.rb +1 -2
- data/lib/contrast/agent/assess/policy/propagator/prepend.rb +1 -2
- data/lib/contrast/agent/assess/policy/propagator/remove.rb +2 -4
- data/lib/contrast/agent/assess/policy/propagator/replace.rb +1 -2
- data/lib/contrast/agent/assess/policy/propagator/reverse.rb +1 -2
- data/lib/contrast/agent/assess/policy/propagator/select.rb +3 -4
- data/lib/contrast/agent/assess/policy/propagator/splat.rb +25 -17
- data/lib/contrast/agent/assess/policy/propagator/split.rb +83 -120
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +41 -25
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +3 -7
- data/lib/contrast/agent/assess/policy/source_method.rb +2 -14
- data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +5 -8
- data/lib/contrast/agent/assess/policy/trigger/xpath.rb +1 -1
- data/lib/contrast/agent/assess/policy/trigger_method.rb +13 -8
- data/lib/contrast/agent/assess/policy/trigger_node.rb +28 -7
- data/lib/contrast/agent/assess/policy/trigger_validation/redos_validator.rb +59 -0
- data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -3
- data/lib/contrast/agent/assess/policy/trigger_validation/trigger_validation.rb +6 -4
- data/lib/contrast/agent/assess/policy/trigger_validation/xss_validator.rb +2 -4
- data/lib/contrast/agent/assess/properties.rb +0 -2
- data/lib/contrast/agent/assess/property/tagged.rb +56 -32
- data/lib/contrast/agent/assess/tracker.rb +16 -18
- data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +7 -0
- data/lib/contrast/agent/middleware.rb +134 -55
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +4 -0
- data/lib/contrast/agent/patching/policy/method_policy.rb +1 -1
- data/lib/contrast/agent/patching/policy/patch.rb +4 -4
- data/lib/contrast/agent/patching/policy/patch_status.rb +1 -1
- data/lib/contrast/agent/patching/policy/patcher.rb +51 -44
- data/lib/contrast/agent/patching/policy/trigger_node.rb +5 -2
- data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +47 -1
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +53 -0
- data/lib/contrast/agent/protect/rule/base.rb +63 -14
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +3 -3
- data/lib/contrast/agent/protect/rule/default_scanner.rb +1 -4
- data/lib/contrast/agent/protect/rule/deserialization.rb +4 -1
- data/lib/contrast/agent/protect/rule/no_sqli.rb +3 -3
- data/lib/contrast/agent/protect/rule/sqli.rb +20 -14
- data/lib/contrast/agent/protect/rule/xxe.rb +32 -11
- data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +10 -6
- data/lib/contrast/agent/reaction_processor.rb +1 -1
- data/lib/contrast/agent/request_context.rb +12 -0
- data/lib/contrast/agent/response.rb +5 -5
- data/lib/contrast/agent/rewriter.rb +3 -3
- data/lib/contrast/agent/scope.rb +33 -13
- data/lib/contrast/agent/static_analysis.rb +13 -7
- data/lib/contrast/agent/thread.rb +1 -1
- data/lib/contrast/agent/thread_watcher.rb +20 -5
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/api/communication/messaging_queue.rb +18 -21
- data/lib/contrast/api/communication/response_processor.rb +8 -1
- data/lib/contrast/api/communication/socket_client.rb +22 -14
- data/lib/contrast/api/decorators.rb +2 -0
- data/lib/contrast/api/decorators/agent_startup.rb +58 -0
- data/lib/contrast/api/decorators/application_startup.rb +51 -0
- data/lib/contrast/api/decorators/library.rb +1 -0
- data/lib/contrast/api/decorators/library_usage_update.rb +1 -0
- data/lib/contrast/api/decorators/route_coverage.rb +15 -5
- data/lib/contrast/api/decorators/trace_event.rb +58 -42
- data/lib/contrast/api/decorators/trace_event_object.rb +11 -3
- data/lib/contrast/api/decorators/trace_event_signature.rb +27 -5
- data/lib/contrast/api/decorators/user_input.rb +2 -1
- data/lib/contrast/common_agent_configuration.rb +1 -1
- data/lib/contrast/components/agent.rb +2 -0
- data/lib/contrast/components/app_context.rb +4 -22
- data/lib/contrast/components/assess.rb +36 -0
- data/lib/contrast/components/interface.rb +5 -3
- data/lib/contrast/components/sampling.rb +48 -6
- data/lib/contrast/components/scope.rb +23 -0
- data/lib/contrast/components/settings.rb +8 -7
- data/lib/contrast/config/assess_configuration.rb +2 -1
- data/lib/contrast/extension/assess/array.rb +1 -2
- data/lib/contrast/extension/assess/erb.rb +1 -3
- data/lib/contrast/extension/assess/exec_trigger.rb +1 -1
- data/lib/contrast/extension/assess/fiber.rb +2 -3
- data/lib/contrast/extension/assess/hash.rb +4 -2
- data/lib/contrast/extension/assess/kernel.rb +1 -2
- data/lib/contrast/extension/assess/marshal.rb +34 -26
- data/lib/contrast/extension/assess/regexp.rb +3 -8
- data/lib/contrast/extension/assess/string.rb +1 -2
- data/lib/contrast/framework/base_support.rb +51 -53
- data/lib/contrast/framework/manager.rb +16 -14
- data/lib/contrast/framework/rack/patch/session_cookie.rb +1 -1
- data/lib/contrast/framework/rack/support.rb +2 -1
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +1 -1
- data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +1 -1
- data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +1 -1
- data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +1 -1
- data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +1 -1
- data/lib/contrast/framework/rails/support.rb +44 -44
- data/lib/contrast/framework/sinatra/support.rb +102 -42
- data/lib/contrast/logger/application.rb +0 -3
- data/lib/contrast/logger/log.rb +31 -15
- data/lib/contrast/utils/class_util.rb +3 -1
- data/lib/contrast/utils/duck_utils.rb +1 -1
- data/lib/contrast/utils/heap_dump_util.rb +103 -87
- data/lib/contrast/utils/invalid_configuration_util.rb +21 -12
- data/lib/contrast/utils/object_share.rb +3 -3
- data/lib/contrast/utils/preflight_util.rb +1 -1
- data/lib/contrast/utils/resource_loader.rb +1 -1
- data/lib/contrast/utils/sha256_builder.rb +2 -2
- data/lib/contrast/utils/string_utils.rb +1 -1
- data/lib/contrast/utils/tag_util.rb +9 -13
- data/resources/assess/policy.json +12 -18
- data/resources/deadzone/policy.json +150 -0
- data/resources/protect/policy.json +12 -0
- data/ruby-agent.gemspec +60 -19
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +124 -112
- data/lib/contrast/agent/assess/rule.rb +0 -18
- data/lib/contrast/agent/assess/rule/base.rb +0 -52
- data/lib/contrast/agent/assess/rule/redos.rb +0 -67
- data/lib/contrast/framework/sinatra/patch/base.rb +0 -83
- data/lib/contrast/framework/sinatra/patch/support.rb +0 -27
- data/lib/contrast/utils/prevent_serialization.rb +0 -52
@@ -29,13 +29,21 @@ module Contrast
|
|
29
29
|
ELLIPSIS = '...'
|
30
30
|
UNTRUNCATED_PORTION_LENGTH = 25
|
31
31
|
TRUNCATION_LENGTH = (UNTRUNCATED_PORTION_LENGTH * 2) + ELLIPSIS.length
|
32
|
-
|
32
|
+
|
33
|
+
# Convert the given Object into a Contrast::Api::Dtm::TraceEventObject
|
34
|
+
#
|
35
|
+
# @param contrast_object [Contrast::Agent::Assess::ContrastObject, nil]
|
36
|
+
# the thing to convert, if any
|
37
|
+
# @param truncate [Boolean] if the converted object can/should be
|
38
|
+
# truncated.
|
39
|
+
# @return [Contrast::Api::Dtm::TraceEventObject]
|
40
|
+
def build contrast_object, truncate
|
33
41
|
event_object = new
|
34
42
|
with_contrast_scope do
|
35
|
-
obj_string = Contrast::Utils::StringUtils.force_utf8(object)
|
43
|
+
obj_string = Contrast::Utils::StringUtils.force_utf8(contrast_object&.object)
|
36
44
|
obj_string = truncate(obj_string) if truncate && obj_string.length > TRUNCATION_LENGTH
|
37
45
|
event_object.value = Base64.encode64(obj_string)
|
38
|
-
event_object.tracked =
|
46
|
+
event_object.tracked = contrast_object&.tracked?
|
39
47
|
end
|
40
48
|
event_object
|
41
49
|
end
|
@@ -17,27 +17,49 @@ module Contrast
|
|
17
17
|
|
18
18
|
# Class methods for TraceEventSignature
|
19
19
|
module ClassMethods
|
20
|
+
# Convert the given composites into components that TeamServer can
|
21
|
+
# understand in order to build a representation of the method
|
22
|
+
# invoked.
|
23
|
+
#
|
24
|
+
# @param ret_obj [Contrast::Agent::Assess::ContrastObject, nil] the
|
25
|
+
# return value of the method call.
|
26
|
+
# @param policy_node [Contrast::Agent::Assess::Policy::PolicyNode]
|
27
|
+
# the policy which pertains to the method invoked.
|
28
|
+
# @param args [Array<Contrast::Agent::Assess::ContrastObject>, nil]
|
29
|
+
# @return [Contrast::Api::Dtm::TraceEventSignature]
|
20
30
|
def build ret_obj, policy_node, args
|
21
31
|
signature = new
|
22
|
-
return_type =
|
23
|
-
signature.return_type = Contrast::Utils::StringUtils.force_utf8(return_type)
|
32
|
+
signature.return_type = Contrast::Utils::StringUtils.force_utf8(type_name(ret_obj))
|
24
33
|
signature.class_name = Contrast::Utils::StringUtils.force_utf8(policy_node.class_name)
|
25
34
|
signature.method_name = Contrast::Utils::StringUtils.force_utf8(policy_node.method_name)
|
26
35
|
if args
|
27
36
|
args&.each do |arg|
|
28
|
-
|
29
|
-
signature.arg_types << Contrast::Utils::StringUtils.force_utf8(arg_type)
|
37
|
+
signature.arg_types << Contrast::Utils::StringUtils.force_utf8(type_name(arg))
|
30
38
|
end
|
31
39
|
end
|
32
40
|
signature.constructor = policy_node.method_name == :new
|
33
41
|
# if there's a ret, then this method isn't nil. not 100% full proof since you can
|
34
42
|
# return nil, but this is the best we've got currently.
|
35
|
-
signature.void_method = ret_obj.nil?
|
43
|
+
signature.void_method = ret_obj.nil? || ret_obj.object.nil?
|
36
44
|
# 8 is STATIC in Java... we have to placate them for now
|
37
45
|
# it has been requested that flags be removed since it isn't used
|
38
46
|
signature.flags = 8 unless policy_node.instance_method?
|
39
47
|
signature
|
40
48
|
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
# While Ruby signatures do not require neither a return type and can
|
53
|
+
# return anything depending on inputs, code paths, etc, nor constant
|
54
|
+
# parameter types, TeamServer was designed with strongly typed
|
55
|
+
# languages (Java) in mind, so we need types in our signatures.
|
56
|
+
#
|
57
|
+
# @param contrast_object [Contrast::Agent::Assess::ContrastObject, nil]
|
58
|
+
# the object to find the type of
|
59
|
+
# @return [String] the name of the module of the ret_obj, or `nil`
|
60
|
+
def type_name contrast_object
|
61
|
+
contrast_object ? contrast_object.object_type : Contrast::Utils::ObjectShare::NIL_STRING
|
62
|
+
end
|
41
63
|
end
|
42
64
|
end
|
43
65
|
end
|
@@ -12,7 +12,8 @@ module Contrast
|
|
12
12
|
module UserInput
|
13
13
|
UNKNOWN_USER_INPUT = Contrast::Api::Dtm::UserInput.new.tap do |user_input|
|
14
14
|
user_input.input_type = :UNKNOWN
|
15
|
-
end
|
15
|
+
end
|
16
|
+
UNKNOWN_USER_INPUT.cs__freeze
|
16
17
|
|
17
18
|
def self.included klass
|
18
19
|
klass.extend(ClassMethods)
|
@@ -66,7 +66,7 @@ module Contrast
|
|
66
66
|
|
67
67
|
%w[name default description required_languages display].each do |field|
|
68
68
|
# TODO: RUBY-1052
|
69
|
-
define_method(field) { hsh[field].dup } # rubocop:disable Kernel/DefineMethod
|
69
|
+
define_method(field) { hsh[field].dup } # rubocop:disable Performance/Kernel/DefineMethod
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
@@ -2,6 +2,8 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'rubygems/version'
|
5
|
+
require 'contrast/api/decorators/agent_startup'
|
6
|
+
require 'contrast/api/decorators/application_startup'
|
5
7
|
require 'contrast/utils/object_share'
|
6
8
|
|
7
9
|
module Contrast
|
@@ -77,31 +79,11 @@ module Contrast
|
|
77
79
|
end
|
78
80
|
|
79
81
|
def build_app_startup_message
|
80
|
-
|
81
|
-
|
82
|
-
msg.group = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.group
|
83
|
-
msg.app_version = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.version.to_s
|
84
|
-
msg.code = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.code
|
85
|
-
msg.metadata = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.metadata
|
86
|
-
# Other fields have limits in TeamServer, the rest don't.
|
87
|
-
msg.session_id = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.session_id, truncate: false
|
88
|
-
msg.session_metadata = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.session_metadata, truncate: false
|
89
|
-
|
90
|
-
msg
|
82
|
+
Contrast::Api::Dtm::ApplicationCreate.build
|
91
83
|
end
|
92
84
|
|
93
85
|
def build_agent_startup_message
|
94
|
-
msg = Contrast::Api::Dtm::AgentStartup.
|
95
|
-
msg.server_name = Contrast::Utils::StringUtils.protobuf_format server_name
|
96
|
-
msg.server_path = Contrast::Utils::StringUtils.protobuf_format server_path
|
97
|
-
msg.server_type = Contrast::Utils::StringUtils.protobuf_format server_type
|
98
|
-
msg.server_version = Contrast::Agent::VERSION
|
99
|
-
msg.version = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server.version
|
100
|
-
msg.environment = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server.environment
|
101
|
-
msg.server_tags = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.server.tags
|
102
|
-
msg.application_tags = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.application.tags
|
103
|
-
msg.library_tags = Contrast::Utils::StringUtils.protobuf_format CONFIG.root.inventory.tags
|
104
|
-
msg.finding_tags = Contrast::Utils::StringUtils.protobuf_format ASSESS.tags
|
86
|
+
msg = Contrast::Api::Dtm::AgentStartup.build(server_name, server_path, server_type)
|
105
87
|
logger.info('Application context',
|
106
88
|
server_name: msg.server_name,
|
107
89
|
server_path: msg.server_path,
|
@@ -35,6 +35,42 @@ module Contrast
|
|
35
35
|
disabled_rules.include?(name)
|
36
36
|
end
|
37
37
|
|
38
|
+
# The value of the stacktrace should be treated as an ENUM. We upcase it for
|
39
|
+
# faster comparisons when we use it. Anything not one of the known values of
|
40
|
+
# 'NONE', 'SOME', or 'ALL' is treated as 'ALL'
|
41
|
+
#
|
42
|
+
# @return [Symbol] the normalized value of CONFIG.root.assess.stacktraces
|
43
|
+
def capture_stacktrace_value
|
44
|
+
@_capture_stacktrace_value ||= case CONFIG.root.assess.stacktraces.upcase
|
45
|
+
when 'NONE'
|
46
|
+
:NONE
|
47
|
+
when 'SOME'
|
48
|
+
:SOME
|
49
|
+
else
|
50
|
+
:ALL
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Consider capture_stacktrace_value along with the node type
|
55
|
+
# to dertmine whether stacktraces should be captured.
|
56
|
+
#
|
57
|
+
# capture_stacktrace_value -> (:ALL, :NONE, :SOME)
|
58
|
+
# node types (SourceNode, PolicyNode, TriggerNode, PropagationNode)
|
59
|
+
#
|
60
|
+
# @param policy_node [Contrast::Agent::Assess::Policy::PolicyNode] The node in question.
|
61
|
+
# @param return [Boolean] to capture or not to capture, that is the question.
|
62
|
+
def capture_stacktrace? policy_node
|
63
|
+
return true if capture_stacktrace_value == :ALL
|
64
|
+
|
65
|
+
return false if capture_stacktrace_value == :NONE
|
66
|
+
|
67
|
+
# Below here capture_stacktrace_value must be :SOME.
|
68
|
+
return true if policy_node.cs__is_a?(Contrast::Agent::Assess::Policy::SourceNode)
|
69
|
+
return true if policy_node.cs__is_a?(Contrast::Agent::Assess::Policy::TriggerNode)
|
70
|
+
|
71
|
+
false
|
72
|
+
end
|
73
|
+
|
38
74
|
def scan_response?
|
39
75
|
@_scan_response = !false?(CONFIG.root.assess.enable_scan_response) if @_scan_response.nil?
|
40
76
|
@_scan_response
|
@@ -168,9 +168,11 @@ Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:settings]
|
|
168
168
|
require 'contrast/components/assess'
|
169
169
|
require 'contrast/components/protect'
|
170
170
|
require 'contrast/components/inventory'
|
171
|
-
Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:analysis] = [
|
172
|
-
|
173
|
-
|
171
|
+
Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:analysis] = [
|
172
|
+
Contrast::Components::Protect,
|
173
|
+
Contrast::Components::Assess,
|
174
|
+
Contrast::Components::Inventory
|
175
|
+
]
|
174
176
|
|
175
177
|
require 'contrast/components/logger'
|
176
178
|
Contrast::Components::ComponentReceiverClassInterface::COMPONENT_MAP[:logging] = [Contrast::Components::Logger]
|
@@ -25,14 +25,14 @@ module Contrast
|
|
25
25
|
|
26
26
|
def sampling_control
|
27
27
|
@_sampling_control ||= begin
|
28
|
-
|
28
|
+
config_settings = CONFIG.root.assess&.sampling
|
29
29
|
settings = SETTINGS&.assess_state&.[](:sampling_settings)
|
30
30
|
{
|
31
|
-
enabled:
|
32
|
-
baseline:
|
33
|
-
request_frequency:
|
34
|
-
response_frequency:
|
35
|
-
window:
|
31
|
+
enabled: enabled?(config_settings, settings),
|
32
|
+
baseline: baseline(config_settings, settings),
|
33
|
+
request_frequency: request_frequency(config_settings, settings),
|
34
|
+
response_frequency: response_frequency(config_settings, settings),
|
35
|
+
window: window(config_settings, settings)
|
36
36
|
}
|
37
37
|
end
|
38
38
|
end
|
@@ -41,6 +41,48 @@ module Contrast
|
|
41
41
|
def reset_sampling_control
|
42
42
|
@_sampling_control = nil
|
43
43
|
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
# @param config_settings [Contrast::Config::SamplingConfiguration] the Sampling configuration as provided by
|
48
|
+
# local user input
|
49
|
+
# @param settings [Contrast::Api::Settings::Sampling] the Sampling settings as provided by TeamServer
|
50
|
+
# @return [Boolean] the resolution of the config_settings, settings, and default value
|
51
|
+
def enabled? config_settings, settings
|
52
|
+
true?([config_settings&.enable, settings&.enabled, DEFAULT_SAMPLING_ENABLED].reject(&:nil?)[0])
|
53
|
+
end
|
54
|
+
|
55
|
+
# @param config_settings [Contrast::Config::SamplingConfiguration] the Sampling configuration as provided by
|
56
|
+
# local user input
|
57
|
+
# @param settings [Contrast::Api::Settings::Sampling] the Sampling settings as provided by TeamServer
|
58
|
+
# @return [Integer] the resolution of the config_settings, settings, and default value
|
59
|
+
def baseline config_settings, settings
|
60
|
+
[config_settings&.baseline, settings&.baseline, DEFAULT_SAMPLING_BASELINE].map(&:to_i).find(&:positive?)
|
61
|
+
end
|
62
|
+
|
63
|
+
# @param config_settings [Contrast::Config::SamplingConfiguration] the Sampling configuration as provided by
|
64
|
+
# local user input
|
65
|
+
# @param settings [Contrast::Api::Settings::Sampling] the Sampling settings as provided by TeamServer
|
66
|
+
# @return [Integer] the resolution of the config_settings, settings, and default value
|
67
|
+
def request_frequency config_settings, settings
|
68
|
+
[config_settings&.request_frequency, settings&.request_frequency, DEFAULT_SAMPLING_REQUEST_FREQUENCY].map(&:to_i).find(&:positive?)
|
69
|
+
end
|
70
|
+
|
71
|
+
# @param config_settings [Contrast::Config::SamplingConfiguration] the Sampling configuration as provided by
|
72
|
+
# local user input
|
73
|
+
# @param settings [Contrast::Api::Settings::Sampling] the Sampling settings as provided by TeamServer
|
74
|
+
# @return [Integer] the resolution of the config_settings, settings, and default value
|
75
|
+
def response_frequency config_settings, settings
|
76
|
+
[config_settings&.response_frequency, settings&.response_frequency, DEFAULT_SAMPLING_RESPONSE_FREQUENCY].map(&:to_i).find(&:positive?)
|
77
|
+
end
|
78
|
+
|
79
|
+
# @param config_settings [Contrast::Config::SamplingConfiguration] the Sampling configuration as provided by
|
80
|
+
# local user input
|
81
|
+
# @param settings [Contrast::Api::Settings::Sampling] the Sampling settings as provided by TeamServer
|
82
|
+
# @return [Integer] the resolution of the config_settings, settings, and default value
|
83
|
+
def window config_settings, settings
|
84
|
+
[config_settings&.window_ms, settings&.window_ms, DEFAULT_SAMPLING_WINDOW_MS].map(&:to_i).find(&:positive?)
|
85
|
+
end
|
44
86
|
end
|
45
87
|
|
46
88
|
module InstanceMethods #:nodoc:
|
@@ -56,6 +56,10 @@ module Contrast
|
|
56
56
|
scope_for_current_ec.enter_deserialization_scope!
|
57
57
|
end
|
58
58
|
|
59
|
+
def enter_split_scope!
|
60
|
+
scope_for_current_ec.enter_split_scope!
|
61
|
+
end
|
62
|
+
|
59
63
|
def enter_scope! name
|
60
64
|
scope_for_current_ec.enter_scope! name
|
61
65
|
end
|
@@ -68,6 +72,10 @@ module Contrast
|
|
68
72
|
scope_for_current_ec.exit_deserialization_scope!
|
69
73
|
end
|
70
74
|
|
75
|
+
def exit_split_scope!
|
76
|
+
scope_for_current_ec.exit_split_scope!
|
77
|
+
end
|
78
|
+
|
71
79
|
def exit_scope! name
|
72
80
|
scope_for_current_ec.exit_scope! name
|
73
81
|
end
|
@@ -80,6 +88,14 @@ module Contrast
|
|
80
88
|
scope_for_current_ec.in_deserialization_scope?
|
81
89
|
end
|
82
90
|
|
91
|
+
def in_split_scope?
|
92
|
+
scope_for_current_ec.in_split_scope?
|
93
|
+
end
|
94
|
+
|
95
|
+
def split_scope_depth
|
96
|
+
scope_for_current_ec.split_scope_depth
|
97
|
+
end
|
98
|
+
|
83
99
|
def in_scope? name
|
84
100
|
scope_for_current_ec.in_scope? name
|
85
101
|
end
|
@@ -97,6 +113,13 @@ module Contrast
|
|
97
113
|
scope_for_current_ec.exit_deserialization_scope!
|
98
114
|
end
|
99
115
|
|
116
|
+
def with_split_scope
|
117
|
+
scope_for_current_ec.enter_split_scope!
|
118
|
+
yield
|
119
|
+
ensure
|
120
|
+
scope_for_current_ec.exit_split_scope!
|
121
|
+
end
|
122
|
+
|
100
123
|
# TODO: RUBY-572
|
101
124
|
#
|
102
125
|
# Current behavior is to no-op if we're not "in a request context".
|
@@ -28,8 +28,8 @@ module Contrast
|
|
28
28
|
|
29
29
|
def assess_state
|
30
30
|
@assess_state ||= { # rubocop:disable Naming/MemoizedInstanceVariableName
|
31
|
-
enabled: false,
|
32
|
-
sampling_features: nil
|
31
|
+
enabled: false, # Boolean
|
32
|
+
sampling_features: nil # Contrast::Api::Settings::Sampling
|
33
33
|
}
|
34
34
|
end
|
35
35
|
|
@@ -58,21 +58,21 @@ module Contrast
|
|
58
58
|
|
59
59
|
PROTECT_STATE_ATTRS.each do |attr|
|
60
60
|
# TODO: RUBY-1052
|
61
|
-
define_method(attr) do # rubocop:disable Kernel/DefineMethod
|
61
|
+
define_method(attr) do # rubocop:disable Performance/Kernel/DefineMethod
|
62
62
|
protect_state[attr]
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
66
66
|
ASSESS_STATE_ATTRS.each do |attr|
|
67
67
|
# TODO: RUBY-1052
|
68
|
-
define_method(attr) do # rubocop:disable Kernel/DefineMethod
|
68
|
+
define_method(attr) do # rubocop:disable Performance/Kernel/DefineMethod
|
69
69
|
assess_state[attr]
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
73
|
APPLICATION_STATE_ATTRS.each do |attr|
|
74
74
|
# TODO: RUBY-1052
|
75
|
-
define_method(attr) do # rubocop:disable Kernel/DefineMethod
|
75
|
+
define_method(attr) do # rubocop:disable Performance/Kernel/DefineMethod
|
76
76
|
application_state[attr]
|
77
77
|
end
|
78
78
|
end
|
@@ -95,6 +95,7 @@ module Contrast
|
|
95
95
|
exclusion_matchers.select(&:code?)
|
96
96
|
end
|
97
97
|
|
98
|
+
# @param server_features [Contrast::Api::Settings::ServerFeatures]
|
98
99
|
def update_from_server_features server_features
|
99
100
|
# protect
|
100
101
|
|
@@ -109,6 +110,7 @@ module Contrast
|
|
109
110
|
Contrast::Utils::Assess::SamplingUtil.instance.update
|
110
111
|
end
|
111
112
|
|
113
|
+
# @param application_settings [Contrast::Api::Settings::ApplicationSettings]
|
112
114
|
def update_from_application_settings application_settings
|
113
115
|
application_state.merge!(application_settings.application_state_translation)
|
114
116
|
end
|
@@ -126,9 +128,8 @@ module Contrast
|
|
126
128
|
end
|
127
129
|
|
128
130
|
def build_assess_rules
|
131
|
+
# TODO: RUBY-1120 actually build assess_rules.
|
129
132
|
@assess_rules = {}
|
130
|
-
|
131
|
-
Contrast::Agent::Assess::Rule::Redos.new
|
132
133
|
end
|
133
134
|
|
134
135
|
def build_protect_rules
|
@@ -11,7 +11,8 @@ module Contrast
|
|
11
11
|
enable: EMPTY_VALUE,
|
12
12
|
enable_scan_response: Contrast::Config::DefaultValue.new('true'),
|
13
13
|
sampling: Contrast::Config::SamplingConfiguration,
|
14
|
-
rules: Contrast::Config::AssessRulesConfiguration
|
14
|
+
rules: Contrast::Config::AssessRulesConfiguration,
|
15
|
+
stacktraces: Contrast::Config::DefaultValue.new('ALL')
|
15
16
|
}.cs__freeze
|
16
17
|
|
17
18
|
def initialize hsh
|
@@ -39,8 +39,7 @@ module Contrast
|
|
39
39
|
return ret if Contrast::Agent::Patching::Policy::Patch.skip_assess_analysis?
|
40
40
|
|
41
41
|
with_contrast_scope do
|
42
|
-
properties = Contrast::Agent::Assess::Tracker.properties(ret)
|
43
|
-
return ret unless properties
|
42
|
+
return ret unless (properties = Contrast::Agent::Assess::Tracker.properties!(ret))
|
44
43
|
|
45
44
|
shift = 0
|
46
45
|
separator_length = separator.nil? ? 0 : separator.to_s.length
|
@@ -6,9 +6,7 @@ module ERBPropagator
|
|
6
6
|
class << self
|
7
7
|
def result_tagger patcher, preshift, ret, _block
|
8
8
|
return unless preshift.args.length >= 1
|
9
|
-
|
10
|
-
properties = Contrast::Agent::Assess::Tracker.properties(ret)
|
11
|
-
return unless properties
|
9
|
+
return unless (properties = Contrast::Agent::Assess::Tracker.properties!(ret))
|
12
10
|
|
13
11
|
used_binding = preshift.args[0]
|
14
12
|
binding_variable_set = used_binding.local_variables
|
@@ -61,8 +61,7 @@ module Contrast
|
|
61
61
|
|
62
62
|
with_contrast_scope do
|
63
63
|
results.each do |result|
|
64
|
-
result_properties = Contrast::Agent::Assess::Tracker.properties(result)
|
65
|
-
next unless result_properties
|
64
|
+
next unless (result_properties = Contrast::Agent::Assess::Tracker.properties!(result))
|
66
65
|
|
67
66
|
result_properties.splat_from(fiber, result)
|
68
67
|
result_properties.build_event(
|
@@ -82,7 +81,7 @@ module Contrast
|
|
82
81
|
return unless underlying.is_a?(String) && !underlying.empty?
|
83
82
|
|
84
83
|
with_contrast_scope do
|
85
|
-
properties = Contrast::Agent::Assess::Tracker.properties(fiber)
|
84
|
+
properties = Contrast::Agent::Assess::Tracker.properties!(fiber)
|
86
85
|
return unless properties
|
87
86
|
|
88
87
|
properties.splat_from(underlying, fiber)
|