contrast-agent 3.14.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +18 -15
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.h +1 -0
- data/ext/cs__assess_string/cs__assess_string.c +24 -25
- data/ext/cs__assess_string/cs__assess_string.h +3 -1
- data/ext/cs__common/cs__common.c +4 -2
- data/ext/cs__common/cs__common.h +1 -1
- data/lib/contrast.rb +1 -1
- data/lib/contrast/agent.rb +4 -12
- data/lib/contrast/agent/assess.rb +1 -0
- data/lib/contrast/agent/assess/contrast_event.rb +143 -79
- data/lib/contrast/agent/assess/events/source_event.rb +1 -1
- data/lib/contrast/agent/assess/finalizers/freeze.rb +3 -1
- data/lib/contrast/agent/assess/finalizers/hash.rb +45 -1
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +10 -3
- data/lib/contrast/agent/assess/policy/patcher.rb +1 -1
- data/lib/contrast/agent/assess/policy/policy.rb +0 -2
- data/lib/contrast/agent/assess/policy/policy_node.rb +15 -10
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +19 -3
- data/lib/contrast/agent/assess/policy/preshift.rb +7 -11
- data/lib/contrast/agent/assess/policy/propagation_method.rb +50 -33
- 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/database_write.rb +5 -3
- 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 +4 -7
- data/lib/contrast/agent/assess/policy/propagator/next.rb +7 -5
- data/lib/contrast/agent/assess/policy/propagator/prepend.rb +8 -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 +24 -19
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +47 -31
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +11 -5
- data/lib/contrast/agent/assess/policy/source_method.rb +85 -58
- data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +16 -12
- data/lib/contrast/agent/assess/policy/trigger/xpath.rb +1 -1
- data/lib/contrast/agent/assess/policy/trigger_method.rb +76 -28
- data/lib/contrast/agent/assess/policy/trigger_node.rb +38 -43
- data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -1
- data/lib/contrast/agent/assess/properties.rb +2 -0
- data/lib/contrast/agent/assess/property/evented.rb +5 -18
- data/lib/contrast/agent/assess/property/tagged.rb +9 -3
- data/lib/contrast/agent/assess/property/updated.rb +131 -0
- data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +58 -5
- data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +23 -8
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +83 -14
- 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 +5 -5
- data/lib/contrast/agent/class_reopener.rb +7 -5
- data/lib/contrast/agent/inventory.rb +15 -0
- data/lib/contrast/agent/inventory/dependencies.rb +50 -0
- data/lib/contrast/agent/inventory/dependency_analysis.rb +37 -0
- data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +104 -0
- data/lib/contrast/agent/inventory/gemfile_digest_cache.rb +38 -0
- data/lib/contrast/agent/middleware.rb +1 -3
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +5 -5
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +20 -20
- data/lib/contrast/agent/patching/policy/module_policy.rb +10 -10
- data/lib/contrast/agent/patching/policy/patch.rb +6 -0
- data/lib/contrast/agent/patching/policy/patcher.rb +13 -22
- data/lib/contrast/agent/patching/policy/policy.rb +17 -6
- data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +3 -5
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +4 -3
- data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +1 -1
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +9 -25
- data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +1 -0
- data/lib/contrast/agent/request.rb +34 -34
- data/lib/contrast/agent/request_handler.rb +1 -1
- data/lib/contrast/agent/response.rb +17 -6
- data/lib/contrast/agent/rewriter.rb +1 -3
- data/lib/contrast/agent/scope.rb +59 -53
- data/lib/contrast/agent/static_analysis.rb +7 -7
- data/lib/contrast/agent/tracepoint_hook.rb +1 -1
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/api/communication/messaging_queue.rb +1 -4
- data/lib/contrast/api/communication/socket_client.rb +36 -1
- data/lib/contrast/api/decorators.rb +3 -0
- data/lib/contrast/api/decorators/address.rb +13 -14
- data/lib/contrast/api/decorators/application_update.rb +2 -4
- data/lib/contrast/api/decorators/library.rb +53 -0
- data/lib/contrast/api/decorators/library_usage_update.rb +30 -0
- data/lib/contrast/api/decorators/message.rb +1 -0
- data/lib/contrast/api/decorators/trace_event.rb +25 -23
- data/lib/contrast/common_agent_configuration.rb +2 -1
- data/lib/contrast/components/agent.rb +6 -5
- data/lib/contrast/components/app_context.rb +49 -38
- data/lib/contrast/components/config.rb +30 -48
- data/lib/contrast/components/contrast_service.rb +9 -9
- data/lib/contrast/components/interface.rb +25 -3
- data/lib/contrast/components/inventory.rb +6 -1
- data/lib/contrast/components/scope.rb +49 -6
- data/lib/contrast/components/settings.rb +23 -23
- data/lib/contrast/config/application_configuration.rb +5 -2
- data/lib/contrast/config/inventory_configuration.rb +2 -2
- data/lib/contrast/config/service_configuration.rb +8 -0
- data/lib/contrast/configuration.rb +88 -47
- data/lib/contrast/extension/assess.rb +0 -2
- data/lib/contrast/extension/assess/array.rb +15 -8
- data/lib/contrast/extension/assess/erb.rb +11 -3
- data/lib/contrast/extension/assess/eval_trigger.rb +6 -6
- data/lib/contrast/extension/assess/exec_trigger.rb +1 -4
- data/lib/contrast/extension/assess/fiber.rb +12 -12
- data/lib/contrast/extension/assess/hash.rb +5 -6
- data/lib/contrast/extension/assess/kernel.rb +28 -23
- data/lib/contrast/extension/assess/marshal.rb +11 -6
- data/lib/contrast/extension/assess/regexp.rb +8 -7
- data/lib/contrast/extension/assess/string.rb +21 -21
- data/lib/contrast/extension/protect/kernel.rb +3 -3
- data/lib/contrast/framework/base_support.rb +1 -1
- data/lib/contrast/framework/manager.rb +3 -3
- data/lib/contrast/framework/rack/patch/session_cookie.rb +22 -28
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +13 -13
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +5 -11
- data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +10 -10
- data/lib/contrast/framework/rails/patch/support.rb +1 -1
- 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 +3 -3
- data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +12 -12
- data/lib/contrast/framework/rails/support.rb +5 -0
- data/lib/contrast/framework/sinatra/patch/base.rb +11 -11
- data/lib/contrast/framework/sinatra/support.rb +4 -4
- data/lib/contrast/logger/application.rb +11 -3
- data/lib/contrast/logger/log.rb +7 -2
- data/lib/contrast/utils/assess/tracking_util.rb +48 -3
- data/lib/contrast/utils/duck_utils.rb +0 -10
- data/lib/contrast/utils/env_configuration_item.rb +2 -1
- data/lib/contrast/utils/invalid_configuration_util.rb +20 -21
- data/lib/contrast/utils/inventory_util.rb +0 -7
- data/lib/contrast/utils/sha256_builder.rb +0 -12
- data/lib/contrast/utils/string_utils.rb +10 -5
- data/resources/assess/policy.json +31 -22
- data/ruby-agent.gemspec +21 -18
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +71 -30
- data/lib/contrast/agent/assess/finalizers/finalize.rb +0 -21
- data/lib/contrast/extension/assess/assess_extension.rb +0 -145
- data/lib/contrast/utils/boolean_util.rb +0 -30
- data/lib/contrast/utils/freeze_util.rb +0 -32
- data/lib/contrast/utils/gemfile_reader.rb +0 -193
@@ -26,7 +26,7 @@ module Contrast
|
|
26
26
|
|
27
27
|
action = properties['action']
|
28
28
|
write_marker = write?(action, *args)
|
29
|
-
possible_write = write_marker && possible_write(write_marker)
|
29
|
+
possible_write = write_marker && possible_write?(write_marker)
|
30
30
|
path_traversal_rule(path, possible_write, object, method)
|
31
31
|
|
32
32
|
# If the action was copy, we need to handle the write half of it.
|
@@ -48,7 +48,7 @@ module Contrast
|
|
48
48
|
|
49
49
|
private
|
50
50
|
|
51
|
-
def possible_write input
|
51
|
+
def possible_write? input
|
52
52
|
input.cs__respond_to?(:to_s) &&
|
53
53
|
input.to_s.include?(Contrast::Utils::ObjectShare::WRITE_FLAG)
|
54
54
|
end
|
@@ -62,7 +62,7 @@ module Contrast
|
|
62
62
|
return true if action == WRITE
|
63
63
|
|
64
64
|
write_marker = args.length > 1 ? args[1] : nil
|
65
|
-
write_marker && possible_write(write_marker)
|
65
|
+
write_marker && possible_write?(write_marker)
|
66
66
|
end
|
67
67
|
|
68
68
|
def path_traversal_rule path, possible_write, object, method
|
@@ -83,6 +83,7 @@ module Contrast
|
|
83
83
|
tmp = CS__SAFER_REL_PATHS.map { |r| "#{ pwd }/#{ r }" }
|
84
84
|
gems = ENV['GEM_PATH']
|
85
85
|
tmp += gems.split(Contrast::Utils::ObjectShare::COLON) if gems
|
86
|
+
tmp.map!(&:downcase)
|
86
87
|
tmp
|
87
88
|
else
|
88
89
|
[]
|
@@ -27,7 +27,7 @@ module Contrast
|
|
27
27
|
def apply_rule__io method, _exception, _properties, object, args
|
28
28
|
need_rewind = false
|
29
29
|
potential_xml = args[0]
|
30
|
-
return unless potential_xml
|
30
|
+
return unless potential_xml.cs__respond_to?(:rewind)
|
31
31
|
|
32
32
|
xml = potential_xml.read
|
33
33
|
need_rewind = true
|
@@ -1,7 +1,6 @@
|
|
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
|
-
require 'contrast/agent/at_exit_hook'
|
5
4
|
require 'contrast/agent/protect/rule/base_service'
|
6
5
|
require 'contrast/utils/stack_trace_utils'
|
7
6
|
require 'contrast/utils/object_share'
|
@@ -45,11 +44,6 @@ module Contrast
|
|
45
44
|
raise Contrast::SecurityException.new(
|
46
45
|
self,
|
47
46
|
"Command Injection rule triggered. Call to #{ classname }.#{ method } blocked.")
|
48
|
-
ensure
|
49
|
-
# Kernel#exec replaces the current process and does not go through
|
50
|
-
# at_exit hooks. Kernel#` runs as a subshell - messages appended
|
51
|
-
# here do not seem to be present in the original process.
|
52
|
-
Contrast::Agent::AtExitHook.on_exit if %i[exec `].include?(method.to_sym)
|
53
47
|
end
|
54
48
|
|
55
49
|
def build_attack_with_match context, input_analysis_result, result, candidate_string, **kwargs
|
@@ -104,37 +98,27 @@ module Contrast
|
|
104
98
|
|
105
99
|
def report_command_execution context, command, **kwargs
|
106
100
|
return unless report_any_command_execution?
|
107
|
-
return
|
101
|
+
return if protect_excluded_by_code?
|
108
102
|
|
109
103
|
build_attack_with_match(context, nil, nil, command, **kwargs)
|
110
104
|
end
|
111
105
|
|
112
106
|
def find_probable_attacker context, potential_attack_string, ia_results, **kwargs
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
next unless chained_command?(input_analysis_result.value)
|
118
|
-
|
119
|
-
most_likely = input_analysis_result
|
120
|
-
break
|
121
|
-
end
|
122
|
-
end
|
123
|
-
return result unless most_likely
|
107
|
+
return unless chained_command?(potential_attack_string)
|
108
|
+
|
109
|
+
likely_attacker = ia_results.find { |input_analysis_result| chained_command?(input_analysis_result.value) }
|
110
|
+
return unless likely_attacker
|
124
111
|
|
125
|
-
|
112
|
+
build_attack_with_match(
|
126
113
|
context,
|
127
|
-
|
128
|
-
|
114
|
+
likely_attacker,
|
115
|
+
nil,
|
129
116
|
potential_attack_string,
|
130
117
|
**kwargs)
|
131
|
-
result
|
132
118
|
end
|
133
119
|
|
134
120
|
def chained_command? command
|
135
|
-
|
136
|
-
|
137
|
-
false
|
121
|
+
CHAINED_COMMAND_CHARS.match(command)
|
138
122
|
end
|
139
123
|
|
140
124
|
# Part of the Hardening for Command Injection detection is the
|
@@ -46,42 +46,42 @@ module Contrast
|
|
46
46
|
# Should also handle the ;jsessionid.
|
47
47
|
def normalized_uri
|
48
48
|
@_normalized_uri ||= begin
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
49
|
+
path = rack_request.path
|
50
|
+
uri = path.split(Contrast::Utils::ObjectShare::SEMICOLON)[0] # remove ;jsessionid
|
51
|
+
uri = uri.split(Contrast::Utils::ObjectShare::QUESTION_MARK)[0] # remove ?query_string=
|
52
|
+
uri.gsub(INNER_REST_TOKEN, INNER_NUMBER_MARKER) # replace interior tokens
|
53
|
+
uri.gsub(LAST_REST_TOKEN, LAST_NUMBER_MARKER) # replace last token
|
54
|
+
end
|
55
55
|
end
|
56
56
|
|
57
57
|
def document_type
|
58
58
|
@_document_type ||= begin
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
59
|
+
if /xml/i.match?(content_type) || body&.start_with?('<?xml')
|
60
|
+
:XML
|
61
|
+
elsif /json/i.match?(content_type) || body&.match?(/\s*[{\[]/)
|
62
|
+
:JSON
|
63
|
+
else
|
64
|
+
:NORMAL
|
65
|
+
end
|
66
|
+
end
|
67
67
|
end
|
68
68
|
|
69
69
|
# Header keys upcased and any underscores replaced with dashes
|
70
70
|
def headers
|
71
71
|
@_headers ||= begin
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
72
|
+
with_contrast_scope do
|
73
|
+
hash = {}
|
74
|
+
env.each do |key, value|
|
75
|
+
next unless key
|
76
|
+
|
77
|
+
name = key.to_s
|
78
|
+
next unless name.start_with?(Contrast::Utils::ObjectShare::HTTP_SCORE)
|
79
|
+
|
80
|
+
hash[Contrast::Utils::StringUtils.normalized_key(name)] = value
|
81
|
+
end
|
82
|
+
hash
|
83
|
+
end
|
84
|
+
end
|
85
85
|
end
|
86
86
|
|
87
87
|
def body
|
@@ -121,13 +121,13 @@ module Contrast
|
|
121
121
|
|
122
122
|
def file_names
|
123
123
|
@_file_names ||= begin
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
124
|
+
names = {}
|
125
|
+
parsed_data = Rack::Multipart.parse_multipart(rack_request.env)
|
126
|
+
traverse_parsed_multipart(parsed_data, names)
|
127
|
+
rescue StandardError => _e
|
128
|
+
logger.warn('Unable to parse multipart request!')
|
129
|
+
{}
|
130
|
+
end
|
131
131
|
end
|
132
132
|
|
133
133
|
def hash_id
|
@@ -18,7 +18,7 @@ module Contrast
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def send_activity_messages
|
21
|
-
Contrast::
|
21
|
+
Contrast::Agent::Inventory::DependencyUsageAnalysis.instance.generate_library_usage(context.activity)
|
22
22
|
[context.server_activity, context.activity, context.observed_route].each do |message|
|
23
23
|
Contrast::Agent.messaging_queue.send_event_eventually(message)
|
24
24
|
end
|
@@ -44,14 +44,9 @@ module Contrast
|
|
44
44
|
context_response = Contrast::Api::Dtm::HttpResponse.new
|
45
45
|
context_response.response_code = response_code.to_i
|
46
46
|
headers&.each_pair do |key, value|
|
47
|
-
|
48
|
-
v = Contrast::Utils::StringUtils.force_utf8(value)
|
49
|
-
context_response.response_headers[k] = v
|
47
|
+
append_pair(context_response.normalized_response_headers, key, value)
|
50
48
|
end
|
51
|
-
context_response.parsed_response_headers = true
|
52
|
-
|
53
49
|
context_response.response_body_binary = Contrast::Utils::StringUtils.force_utf8(body)
|
54
|
-
context_response.parsed_response_body = false
|
55
50
|
|
56
51
|
doc_type = document_type
|
57
52
|
context_response.document_type = doc_type if doc_type
|
@@ -97,6 +92,22 @@ module Contrast
|
|
97
92
|
|
98
93
|
private
|
99
94
|
|
95
|
+
# From the dtm for normalized_response_headers:
|
96
|
+
# Key is UPPERCASE_UNDERSCORE
|
97
|
+
#
|
98
|
+
# Example: Content-Type: text/html; charset=utf-8
|
99
|
+
# "CONTENT_TYPE" => Content-Type,["text/html; charset=utf8"]
|
100
|
+
def append_pair map, key, value
|
101
|
+
return unless key && value
|
102
|
+
return if value.is_a?(Hash)
|
103
|
+
|
104
|
+
safe_key = Contrast::Utils::StringUtils.force_utf8(key)
|
105
|
+
hash_key = Contrast::Utils::StringUtils.normalized_key(safe_key)
|
106
|
+
map[hash_key] ||= Contrast::Api::Dtm::Pair.new
|
107
|
+
map[hash_key].key = safe_key
|
108
|
+
map[hash_key].values << Contrast::Utils::StringUtils.force_utf8(value)
|
109
|
+
end
|
110
|
+
|
100
111
|
HTTP_PREFIX = /^[Hh][Tt][Tt][Pp][_-]/i.cs__freeze
|
101
112
|
|
102
113
|
# Given some holder of the content of the response's body, extract that
|
@@ -61,9 +61,7 @@ module Contrast
|
|
61
61
|
status ||= Contrast::Agent::Patching::Policy::PatchStatus.get_status(mod)
|
62
62
|
status.failed_rewrite!
|
63
63
|
ensure
|
64
|
-
|
65
|
-
opener&.commit_patches
|
66
|
-
end
|
64
|
+
opener&.commit_patches
|
67
65
|
logger.trace('Rewriting complete',
|
68
66
|
module: module_data.name,
|
69
67
|
result: Contrast::Agent::Patching::Policy::PatchStatus.get_status(
|
data/lib/contrast/agent/scope.rb
CHANGED
@@ -15,67 +15,73 @@ module Contrast
|
|
15
15
|
# Instead, we should say "If I'm already doing Contrast things, don't track
|
16
16
|
# this"
|
17
17
|
class Scope
|
18
|
-
# The following %i[] list is the authoritative list
|
19
|
-
# of scopes. If you define a new symbol here, you'll
|
20
|
-
# get scope methods:
|
21
|
-
# %i[monkey] ->
|
22
|
-
# enter_monkey_scope!
|
23
|
-
# exit_monkey_scope!
|
24
|
-
# in_monkey_scope?
|
25
|
-
# with_monkey_scope { special_monkey_function }
|
26
18
|
SCOPE_LIST = %i[contrast deserialization].cs__freeze
|
27
19
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
instance_variable_set(iv_sym, 0)
|
32
|
-
end
|
20
|
+
def initialize
|
21
|
+
instance_variable_set(:@contrast_scope, 0)
|
22
|
+
instance_variable_set(:@deserialization_scope, 0)
|
33
23
|
end
|
34
24
|
|
35
|
-
|
36
|
-
|
25
|
+
def in_contrast_scope?
|
26
|
+
instance_variable_get(:@contrast_scope).positive?
|
27
|
+
end
|
37
28
|
|
38
|
-
|
39
|
-
|
40
|
-
|
29
|
+
def in_deserialization_scope?
|
30
|
+
instance_variable_get(:@deserialization_scope).positive?
|
31
|
+
end
|
41
32
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
33
|
+
def enter_contrast_scope!
|
34
|
+
level = instance_variable_get(:@contrast_scope)
|
35
|
+
instance_variable_set(:@contrast_scope, level + 1)
|
36
|
+
end
|
47
37
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
# should cancel each other out.
|
53
|
-
#
|
54
|
-
# so we prefer this sequence:
|
55
|
-
# scope = 0
|
56
|
-
# exit = -1
|
57
|
-
# enter = 0
|
58
|
-
# enter = 1
|
59
|
-
# exit = 0
|
60
|
-
# scope = 0
|
61
|
-
#
|
62
|
-
# over this sequence:
|
63
|
-
# scope = 0
|
64
|
-
# exit = 0
|
65
|
-
# enter = 1
|
66
|
-
# enter = 2
|
67
|
-
# exit = 1
|
68
|
-
# scope = 1
|
69
|
-
level = instance_variable_get(iv_sym)
|
70
|
-
instance_variable_set(iv_sym, level - 1)
|
71
|
-
end
|
38
|
+
def enter_deserialization_scope!
|
39
|
+
level = instance_variable_get(:@deserialization_scope)
|
40
|
+
instance_variable_set(:@deserialization_scope, level + 1)
|
41
|
+
end
|
72
42
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
43
|
+
# Scope Exits...
|
44
|
+
# by design, can go below zero.
|
45
|
+
# every exit/enter pair (regardless of series)
|
46
|
+
# should cancel each other out.
|
47
|
+
#
|
48
|
+
# so we prefer this sequence:
|
49
|
+
# scope = 0
|
50
|
+
# exit = -1
|
51
|
+
# enter = 0
|
52
|
+
# enter = 1
|
53
|
+
# exit = 0
|
54
|
+
# scope = 0
|
55
|
+
#
|
56
|
+
# over this sequence:
|
57
|
+
# scope = 0
|
58
|
+
# exit = 0
|
59
|
+
# enter = 1
|
60
|
+
# enter = 2
|
61
|
+
# exit = 1
|
62
|
+
# scope = 1
|
63
|
+
def exit_contrast_scope!
|
64
|
+
level = instance_variable_get(:@contrast_scope)
|
65
|
+
instance_variable_set(:@contrast_scope, level - 1)
|
66
|
+
end
|
67
|
+
|
68
|
+
def exit_deserialization_scope!
|
69
|
+
level = instance_variable_get(:@deserialization_scope)
|
70
|
+
instance_variable_set(:@deserialization_scope, level - 1)
|
71
|
+
end
|
72
|
+
|
73
|
+
def with_contrast_scope
|
74
|
+
enter_contrast_scope!
|
75
|
+
yield
|
76
|
+
ensure
|
77
|
+
exit_contrast_scope!
|
78
|
+
end
|
79
|
+
|
80
|
+
def with_deserialization_scope
|
81
|
+
enter_deserialization_scope!
|
82
|
+
yield
|
83
|
+
ensure
|
84
|
+
exit_deserialization_scope!
|
79
85
|
end
|
80
86
|
|
81
87
|
# Dynamic versions of the above.
|
@@ -2,7 +2,7 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
require 'contrast/components/interface'
|
5
|
-
require 'contrast/
|
5
|
+
require 'contrast/agent/inventory'
|
6
6
|
require 'contrast/api/decorators/application_update'
|
7
7
|
|
8
8
|
module Contrast
|
@@ -17,12 +17,12 @@ module Contrast
|
|
17
17
|
# report the already-loaded gems.
|
18
18
|
def catchup
|
19
19
|
@_catchup ||= begin
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
20
|
+
with_contrast_scope do
|
21
|
+
Contrast::Agent::Inventory::DependencyUsageAnalysis.instance.catchup
|
22
|
+
send_inventory_message
|
23
|
+
true
|
24
|
+
end
|
25
|
+
end
|
26
26
|
rescue StandardError => e
|
27
27
|
logger.warn('Unable to run post-initialization static analysis', e)
|
28
28
|
end
|
@@ -35,7 +35,7 @@ module Contrast
|
|
35
35
|
path = tracepoint_event.path
|
36
36
|
return if path&.include?('contrast')
|
37
37
|
|
38
|
-
Contrast::
|
38
|
+
Contrast::Agent::Inventory::DependencyUsageAnalysis.instance.associate_file(path) if path
|
39
39
|
Contrast::Agent::Patching::Policy::Patcher.patch_specific_module(loaded_module)
|
40
40
|
Contrast::Agent::Assess::Policy::RewriterPatch.rewrite_interpolation(loaded_module)
|
41
41
|
Contrast::Agent::Assess::Policy::PolicyScanner.scan(tracepoint_event)
|
@@ -67,10 +67,7 @@ module Contrast
|
|
67
67
|
def preprocess_event event
|
68
68
|
return unless event.is_a?(Contrast::Api::Dtm::Activity)
|
69
69
|
|
70
|
-
#
|
71
|
-
event.finding_tags = Contrast::Utils::StringUtils.force_utf8(ASSESS.tags)
|
72
|
-
|
73
|
-
# and see if they're even enabled
|
70
|
+
# See if they're even enabled
|
74
71
|
event.findings.delete_if { |finding| ASSESS.rule_disabled?(finding.rule_id) }
|
75
72
|
end
|
76
73
|
end
|