contrast-agent 3.12.0 → 3.13.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.dockerignore +0 -1
- data/.gitignore +1 -1
- data/.simplecov +1 -1
- data/Rakefile +31 -0
- data/ext/build_funchook.rb +0 -2
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +2 -8
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.h +0 -1
- data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +1 -6
- data/ext/cs__assess_yield_track/cs__assess_yield_track.c +1 -5
- data/ext/cs__assess_yield_track/cs__assess_yield_track.h +0 -1
- data/ext/cs__common/cs__common.c +24 -0
- data/ext/cs__common/cs__common.h +3 -0
- data/ext/cs__common/extconf.rb +0 -14
- data/ext/extconf_common.rb +0 -28
- data/lib/contrast.rb +3 -1
- data/lib/contrast/agent.rb +14 -2
- data/lib/contrast/agent/assess/contrast_event.rb +28 -167
- data/lib/contrast/agent/assess/events/source_event.rb +3 -7
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +1 -1
- data/lib/contrast/agent/assess/policy/policy_node.rb +4 -98
- data/lib/contrast/agent/assess/policy/propagation_method.rb +1 -2
- data/lib/contrast/agent/assess/policy/propagation_node.rb +5 -1
- data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/insert.rb +1 -4
- data/lib/contrast/agent/assess/policy/propagator/match_data.rb +9 -1
- data/lib/contrast/agent/assess/policy/propagator/remove.rb +6 -11
- data/lib/contrast/agent/assess/policy/propagator/select.rb +4 -4
- data/lib/contrast/agent/assess/policy/propagator/split.rb +2 -2
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +4 -4
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +6 -10
- data/lib/contrast/agent/assess/policy/source_method.rb +1 -2
- data/lib/contrast/agent/assess/policy/trigger_method.rb +2 -10
- data/lib/contrast/agent/assess/policy/trigger_node.rb +16 -4
- data/lib/contrast/agent/assess/properties.rb +4 -382
- data/lib/contrast/agent/assess/property/evented.rb +78 -0
- data/lib/contrast/agent/assess/property/tagged.rb +339 -0
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +2 -20
- data/lib/contrast/agent/assess/tag.rb +27 -12
- data/lib/contrast/agent/at_exit_hook.rb +3 -1
- data/lib/contrast/agent/exclusion_matcher.rb +2 -2
- data/lib/contrast/agent/inventory/policy/datastores.rb +0 -1
- data/lib/contrast/agent/middleware.rb +2 -14
- data/lib/contrast/agent/patching/policy/patch.rb +1 -1
- data/lib/contrast/agent/patching/policy/policy.rb +3 -3
- data/lib/contrast/agent/patching/policy/policy_node.rb +2 -2
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +2 -2
- data/lib/contrast/agent/protect/rule/base.rb +19 -31
- data/lib/contrast/agent/protect/rule/base_service.rb +1 -1
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +2 -7
- data/lib/contrast/agent/protect/rule/xxe.rb +1 -0
- data/lib/contrast/agent/reaction_processor.rb +3 -3
- data/lib/contrast/agent/request.rb +92 -331
- data/lib/contrast/agent/request_context.rb +15 -15
- data/lib/contrast/agent/request_handler.rb +1 -1
- data/lib/contrast/agent/response.rb +2 -14
- data/lib/contrast/agent/scope.rb +1 -1
- data/lib/contrast/agent/service_heartbeat.rb +7 -9
- data/lib/contrast/agent/static_analysis.rb +1 -1
- data/lib/contrast/agent/thread_watcher.rb +49 -0
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/agent/worker_thread.rb +24 -0
- data/lib/contrast/api.rb +3 -5
- data/lib/contrast/api/communication.rb +20 -0
- data/lib/contrast/api/communication/connection_status.rb +41 -0
- data/lib/contrast/api/communication/messaging_queue.rb +79 -0
- data/lib/contrast/{utils/service_response_util.rb → api/communication/response_processor.rb} +9 -18
- data/lib/contrast/api/communication/service_lifecycle.rb +61 -0
- data/lib/contrast/api/communication/socket.rb +45 -0
- data/lib/contrast/api/communication/socket_client.rb +76 -0
- data/lib/contrast/api/communication/speedracer.rb +111 -0
- data/lib/contrast/api/communication/tcp_socket.rb +31 -0
- data/lib/contrast/api/communication/unix_socket.rb +27 -0
- data/lib/contrast/api/decorators.rb +10 -0
- data/lib/contrast/api/decorators/address.rb +60 -0
- data/lib/contrast/api/decorators/application_settings.rb +7 -3
- data/lib/contrast/api/decorators/application_update.rb +0 -9
- data/lib/contrast/api/decorators/http_request.rb +139 -0
- data/lib/contrast/api/decorators/message.rb +75 -0
- data/lib/contrast/api/decorators/rasp_rule_sample.rb +28 -0
- data/lib/contrast/api/decorators/route_coverage.rb +57 -0
- data/lib/contrast/api/decorators/trace_event.rb +99 -0
- data/lib/contrast/api/decorators/trace_event_object.rb +57 -0
- data/lib/contrast/api/decorators/trace_event_signature.rb +46 -0
- data/lib/contrast/api/decorators/trace_taint_range.rb +51 -0
- data/lib/contrast/api/decorators/trace_taint_range_tags.rb +109 -0
- data/lib/contrast/api/decorators/user_input.rb +40 -0
- data/lib/contrast/components/app_context.rb +0 -7
- data/lib/contrast/components/config.rb +4 -9
- data/lib/contrast/components/interface.rb +1 -1
- data/lib/contrast/components/settings.rb +0 -6
- data/lib/contrast/configuration.rb +2 -2
- data/lib/contrast/extension/assess.rb +0 -1
- data/lib/contrast/extension/assess/assess_extension.rb +1 -2
- data/lib/contrast/extension/assess/fiber.rb +1 -1
- data/lib/contrast/extension/assess/string.rb +1 -1
- data/lib/contrast/extension/inventory.rb +0 -1
- data/lib/contrast/framework/base_support.rb +0 -23
- data/lib/contrast/framework/manager.rb +0 -9
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +1 -3
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +3 -4
- data/lib/contrast/framework/rails/support.rb +3 -32
- data/lib/contrast/framework/sinatra/patch/base.rb +1 -1
- data/lib/contrast/framework/sinatra/support.rb +11 -22
- data/lib/contrast/funchook/funchook.rb +45 -0
- data/lib/contrast/logger/application.rb +1 -1
- data/lib/contrast/logger/format.rb +51 -0
- data/lib/contrast/logger/log.rb +16 -9
- data/lib/contrast/utils/assess/tracking_util.rb +45 -20
- data/lib/contrast/utils/class_util.rb +3 -1
- data/lib/contrast/utils/hash_digest.rb +11 -2
- data/lib/contrast/utils/invalid_configuration_util.rb +1 -17
- data/lib/contrast/utils/inventory_util.rb +2 -7
- data/lib/contrast/utils/object_share.rb +0 -1
- data/lib/contrast/utils/os.rb +16 -4
- data/lib/contrast/utils/stack_trace_utils.rb +0 -1
- data/lib/contrast/utils/tag_util.rb +1 -1
- data/lib/contrast/utils/thread_tracker.rb +1 -14
- data/lib/contrast/utils/timer.rb +1 -17
- data/resources/deadzone/policy.json +5 -0
- data/ruby-agent.gemspec +4 -4
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +49 -71
- data/funchook/Makefile +0 -29
- data/funchook/autom4te.cache/output.0 +0 -4976
- data/funchook/autom4te.cache/requests +0 -78
- data/funchook/autom4te.cache/traces.0 +0 -364
- data/funchook/config.log +0 -490
- data/funchook/config.status +0 -1016
- data/funchook/configure +0 -4976
- data/funchook/src/Makefile +0 -70
- data/funchook/src/config.h +0 -101
- data/funchook/src/config.h.in +0 -100
- data/funchook/src/decoder.o +0 -0
- data/funchook/src/distorm.o +0 -0
- data/funchook/src/funchook.o +0 -0
- data/funchook/src/funchook_io.o +0 -0
- data/funchook/src/funchook_syscall.o +0 -0
- data/funchook/src/funchook_unix.o +0 -0
- data/funchook/src/funchook_x86.o +0 -0
- data/funchook/src/instructions.o +0 -0
- data/funchook/src/insts.o +0 -0
- data/funchook/src/libfunchook.so +0 -0
- data/funchook/src/mnemonics.o +0 -0
- data/funchook/src/operands.o +0 -0
- data/funchook/src/os_func.o +0 -0
- data/funchook/src/os_func_unix.o +0 -0
- data/funchook/src/prefix.o +0 -0
- data/funchook/src/printf_base.o +0 -0
- data/funchook/src/textdefs.o +0 -0
- data/funchook/src/wstring.o +0 -0
- data/funchook/test/Makefile +0 -43
- data/funchook/test/funchook_test +0 -0
- data/funchook/test/libfunchook_test.so +0 -0
- data/funchook/test/test_main.o +0 -0
- data/funchook/test/x86_64_test.o +0 -0
- data/lib/contrast/agent/assess/adjusted_span.rb +0 -27
- data/lib/contrast/agent/socket_client.rb +0 -134
- data/lib/contrast/api/connection_status.rb +0 -49
- data/lib/contrast/api/socket.rb +0 -43
- data/lib/contrast/api/speedracer.rb +0 -188
- data/lib/contrast/api/tcp_socket.rb +0 -29
- data/lib/contrast/api/unix_socket.rb +0 -25
- data/lib/contrast/framework/sinatra/application_helper.rb +0 -51
- data/lib/contrast/framework/view_technologies_descriptor.rb +0 -21
- data/lib/contrast/internal_exception.rb +0 -8
- data/lib/contrast/utils/cache.rb +0 -58
- data/lib/contrast/utils/service_sender_util.rb +0 -167
- data/lib/contrast/utils/sinatra_helper.rb +0 -49
@@ -65,15 +65,11 @@ module Contrast
|
|
65
65
|
# 2) I'll set the event's source and target to TS values.
|
66
66
|
# 3) Return the highlight or the first source/target as the taint
|
67
67
|
# target.
|
68
|
-
def determine_taint_target
|
68
|
+
def determine_taint_target event_dtm
|
69
69
|
return unless @policy_node&.targets&.any?
|
70
70
|
|
71
|
-
|
72
|
-
|
73
|
-
"P#{ @highlight }"
|
74
|
-
else
|
75
|
-
@policy_node.target_string
|
76
|
-
end
|
71
|
+
event_dtm.source = @policy_node.source_string if @policy_node.source_string
|
72
|
+
event_dtm.target = @highlight ? "P#{ @highlight }" : @policy_node.target_string
|
77
73
|
@highlight || @policy_node.targets[0]
|
78
74
|
end
|
79
75
|
end
|
@@ -20,7 +20,7 @@ module Contrast
|
|
20
20
|
# such that calls to that method will result in a Source Event.
|
21
21
|
#
|
22
22
|
# @param klass [Class] the Class to taint
|
23
|
-
# @param tainted_columns [Hash
|
23
|
+
# @param tainted_columns [Hash{String => Contrast::Agent::Assess::Properties}]
|
24
24
|
# the name of the method to taint, mapped to the properties it
|
25
25
|
# should apply
|
26
26
|
def create_sources klass, tainted_columns
|
@@ -2,6 +2,7 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
cs__scoped_require 'contrast/agent/patching/policy/policy_node'
|
5
|
+
cs__scoped_require 'contrast/api/decorators/trace_taint_range_tags'
|
5
6
|
|
6
7
|
module Contrast
|
7
8
|
module Agent
|
@@ -69,7 +70,7 @@ module Contrast
|
|
69
70
|
# 1) Split on ','
|
70
71
|
# 2) If 'O', add the source, else it's P (we don't have R sources) and
|
71
72
|
# needs to be converted. P type will either be P:name or P# where #
|
72
|
-
# is the index of the
|
73
|
+
# is the index of the parameter. Drop the P and store the int as int
|
73
74
|
# or name as symbol
|
74
75
|
def generate_sources
|
75
76
|
if source_string
|
@@ -137,7 +138,8 @@ module Contrast
|
|
137
138
|
return unless tags
|
138
139
|
|
139
140
|
tags.each do |tag|
|
140
|
-
next if VALID_TAGS.include?(tag) ||
|
141
|
+
next if Contrast::Api::Decorators::TraceTaintRangeTags::VALID_TAGS.include?(tag) ||
|
142
|
+
Contrast::Api::Decorators::TraceTaintRangeTags::VALID_SOURCE_TAGS.include?(tag)
|
141
143
|
|
142
144
|
raise(ArgumentError,
|
143
145
|
"#{ node_class } #{ id } had an invalid tag. #{ tag } is not a known value.")
|
@@ -173,102 +175,6 @@ module Contrast
|
|
173
175
|
@event_action
|
174
176
|
end
|
175
177
|
|
176
|
-
# EventTagTypeDTM
|
177
|
-
VALID_TAGS = %w[
|
178
|
-
XML_ENCODED
|
179
|
-
XML_DECODED
|
180
|
-
HTML_ENCODED
|
181
|
-
HTML_DECODED
|
182
|
-
URL_ENCODED
|
183
|
-
URL_DECODED
|
184
|
-
CSS_ENCODED
|
185
|
-
CSS_DECODED
|
186
|
-
BASE64_ENCODED
|
187
|
-
BASE64_DECODED
|
188
|
-
JAVASCRIPT_ENCODED
|
189
|
-
JAVASCRIPT_DECODED
|
190
|
-
JAVA_ENCODED
|
191
|
-
JAVA_DECODED
|
192
|
-
CSV_ENCODED
|
193
|
-
CSV_DECODED
|
194
|
-
SQL_ENCODED
|
195
|
-
SQL_DECODED
|
196
|
-
LDAP_ENCODED
|
197
|
-
LDAP_DECODED
|
198
|
-
XPATH_ENCODED
|
199
|
-
XPATH_DECODED
|
200
|
-
OS_ENCODED
|
201
|
-
OS_DECODED
|
202
|
-
VBSCRIPT_ENCODED
|
203
|
-
VBSCRIPT_DECODED
|
204
|
-
POTENTIAL_SANITIZED
|
205
|
-
POTENTIAL_VALIDATED
|
206
|
-
NO_CONTROL_CHARS
|
207
|
-
CUSTOM
|
208
|
-
|
209
|
-
CUSTOM_ENCODED
|
210
|
-
CUSTOM_ENCODED_CMD_INJECTION
|
211
|
-
CUSTOM_ENCODED_EXPRESSION_LANGUAGE_INJECTION
|
212
|
-
CUSTOM_ENCODED_HEADER_INJECTION
|
213
|
-
CUSTOM_ENCODED_HQL_INJECTION
|
214
|
-
CUSTOM_ENCODED_LDAP_INJECTION
|
215
|
-
CUSTOM_ENCODED_LOG_INJECTION
|
216
|
-
CUSTOM_ENCODED_NOSQL_INJECTION
|
217
|
-
CUSTOM_ENCODED_PATH_TRAVERSAL
|
218
|
-
CUSTOM_ENCODED_REDOS
|
219
|
-
CUSTOM_ENCODED_REFLECTED_XSS
|
220
|
-
CUSTOM_ENCODED_REFLECTION_INJECTION
|
221
|
-
CUSTOM_ENCODED_SMTP_INJECTION
|
222
|
-
CUSTOM_ENCODED_SQL_INJECTION
|
223
|
-
CUSTOM_ENCODED_SSRF
|
224
|
-
CUSTOM_ENCODED_STORED_XSS
|
225
|
-
CUSTOM_ENCODED_TRUST_BOUNDARY_VIOLATION
|
226
|
-
CUSTOM_ENCODED_UNSAFE_CODE_EXECUTION
|
227
|
-
CUSTOM_ENCODED_UNSAFE_READLINE
|
228
|
-
CUSTOM_ENCODED_UNSAFE_XML_DECODE
|
229
|
-
CUSTOM_ENCODED_UNTRUSTED_DESERIALIZATION
|
230
|
-
CUSTOM_ENCODED_UNVALIDATED_FORWARD
|
231
|
-
CUSTOM_ENCODED_UNVALIDATED_REDIRECT
|
232
|
-
CUSTOM_ENCODED_XPATH_INJECTION
|
233
|
-
CUSTOM_ENCODED_XXE
|
234
|
-
CUSTOM_SECURITY_CONTROL_APPLIED
|
235
|
-
|
236
|
-
CUSTOM_VALIDATED
|
237
|
-
CUSTOM_VALIDATED_CMD_INJECTION
|
238
|
-
CUSTOM_VALIDATED_EXPRESSION_LANGUAGE_INJECTION
|
239
|
-
CUSTOM_VALIDATED_HEADER_INJECTION
|
240
|
-
CUSTOM_VALIDATED_HQL_INJECTION
|
241
|
-
CUSTOM_VALIDATED_LDAP_INJECTION
|
242
|
-
CUSTOM_VALIDATED_LOG_INJECTION
|
243
|
-
CUSTOM_VALIDATED_NOSQL_INJECTION
|
244
|
-
CUSTOM_VALIDATED_PATH_TRAVERSAL
|
245
|
-
CUSTOM_VALIDATED_REDOS
|
246
|
-
CUSTOM_VALIDATED_REFLECTED_XSS
|
247
|
-
CUSTOM_VALIDATED_REFLECTION_INJECTION
|
248
|
-
CUSTOM_VALIDATED_SMTP_INJECTION
|
249
|
-
CUSTOM_VALIDATED_SQL_INJECTION
|
250
|
-
CUSTOM_VALIDATED_SSRF
|
251
|
-
CUSTOM_VALIDATED_STORED_XSS
|
252
|
-
CUSTOM_VALIDATED_TRUST_BOUNDARY_VIOLATION
|
253
|
-
CUSTOM_VALIDATED_UNSAFE_CODE_EXECUTION
|
254
|
-
CUSTOM_VALIDATED_UNSAFE_READLINE
|
255
|
-
CUSTOM_VALIDATED_UNSAFE_XML_DECODE
|
256
|
-
CUSTOM_VALIDATED_UNTRUSTED_DESERIALIZATION
|
257
|
-
CUSTOM_VALIDATED_UNVALIDATED_FORWARD
|
258
|
-
CUSTOM_VALIDATED_UNVALIDATED_REDIRECT
|
259
|
-
CUSTOM_VALIDATED_XPATH_INJECTION
|
260
|
-
CUSTOM_VALIDATED_XXE
|
261
|
-
|
262
|
-
DATABASE_WRITE
|
263
|
-
].cs__freeze
|
264
|
-
|
265
|
-
VALID_SOURCE_TAGS = %w[
|
266
|
-
NO_NEWLINES
|
267
|
-
UNTRUSTED
|
268
|
-
CROSS_SITE
|
269
|
-
LIMITED_CHARS
|
270
|
-
].cs__freeze
|
271
|
-
|
272
178
|
# The keys used to read from policy.json to create the individual
|
273
179
|
# policy nodes. These are common across node types
|
274
180
|
JSON_SOURCE = 'source'
|
@@ -203,8 +203,7 @@ module Contrast
|
|
203
203
|
|
204
204
|
length = Contrast::Utils::StringUtils.ret_length(target)
|
205
205
|
propagation_node.tags.each do |tag|
|
206
|
-
|
207
|
-
target.cs__properties.add_tag(tag, span)
|
206
|
+
target.cs__properties.add_tag(tag, 0...length)
|
208
207
|
end
|
209
208
|
end
|
210
209
|
|
@@ -2,6 +2,8 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
cs__scoped_require 'contrast/agent/assess/policy/policy_node'
|
5
|
+
cs__scoped_require 'contrast/api/decorators/trace_taint_range_tags'
|
6
|
+
|
5
7
|
module Contrast
|
6
8
|
module Agent
|
7
9
|
module Assess
|
@@ -73,7 +75,9 @@ module Contrast
|
|
73
75
|
return unless untags
|
74
76
|
|
75
77
|
untags.each do |tag|
|
76
|
-
|
78
|
+
unless Contrast::Api::Decorators::TraceTaintRangeTags::VALID_TAGS.include?(tag)
|
79
|
+
raise(ArgumentError, "#{ node_type } #{ id } did not have a valid untag. #{ tag } is not a known value.")
|
80
|
+
end
|
77
81
|
raise(ArgumentError, "#{ node_type } #{ id } had the same tag and untag, #{ tag }.") if tags&.include?(tag)
|
78
82
|
end
|
79
83
|
end
|
@@ -26,7 +26,7 @@ module Contrast
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def propagate _propagation_node, _preshift, _target
|
29
|
-
raise
|
29
|
+
raise NoMethodError("Expected Base propagator subclass: #{ cs__class } to implement #propagate")
|
30
30
|
end
|
31
31
|
end
|
32
32
|
end
|
@@ -35,10 +35,7 @@ module Contrast
|
|
35
35
|
# Depending what's inserted, we might be wrong. For instance, inserting 'foo'
|
36
36
|
# into 'asdfasdf' could result in 'asdfoofasdf'. we'd be off by one b/c of the 'f'
|
37
37
|
insert_point = target.rindex(source, insert_point)
|
38
|
-
|
39
|
-
overflow = Contrast::Agent::Assess::AdjustedSpan.new(
|
40
|
-
insert_point,
|
41
|
-
insert_point + source.length)
|
38
|
+
overflow = insert_point...(insert_point + source.length)
|
42
39
|
|
43
40
|
# handle shifting the inserted range
|
44
41
|
target.cs__properties.shift_tags([overflow])
|
@@ -14,6 +14,8 @@ module Contrast
|
|
14
14
|
def square_bracket_tagger propagation_node, preshift, ret, _block
|
15
15
|
if ret.is_a?(Array)
|
16
16
|
ret.each_with_index do |return_value, index|
|
17
|
+
next unless return_value
|
18
|
+
|
17
19
|
target_matchdata_index = if preshift.args[0].is_a?(Range)
|
18
20
|
arg_range = preshift.args[0]
|
19
21
|
arg_range.to_a.empty? ? index + 1 : arg_range.to_a[index]
|
@@ -32,6 +34,8 @@ module Contrast
|
|
32
34
|
|
33
35
|
def captures_tagger propagation_node, preshift, ret, _block
|
34
36
|
ret.each_with_index do |return_value, index|
|
37
|
+
next unless return_value
|
38
|
+
|
35
39
|
targetted_index = index + 1
|
36
40
|
square_bracket_single(targetted_index, preshift, return_value, propagation_node)
|
37
41
|
end
|
@@ -40,6 +44,8 @@ module Contrast
|
|
40
44
|
|
41
45
|
def to_a_tagger propagation_node, preshift, ret, _block
|
42
46
|
ret.each_with_index do |return_value, index|
|
47
|
+
next unless return_value
|
48
|
+
|
43
49
|
square_bracket_single(index, preshift, return_value, propagation_node)
|
44
50
|
end
|
45
51
|
ret
|
@@ -47,6 +53,8 @@ module Contrast
|
|
47
53
|
|
48
54
|
def values_at_tagger propagation_node, preshift, ret, _block
|
49
55
|
ret.each_with_index do |return_value, return_index|
|
56
|
+
next unless return_value
|
57
|
+
|
50
58
|
original_group_arg_index = preshift.args[return_index]
|
51
59
|
square_bracket_single(original_group_arg_index, preshift, return_value, propagation_node)
|
52
60
|
end
|
@@ -59,7 +67,7 @@ module Contrast
|
|
59
67
|
original_start_index = preshift.object.begin(argument_index)
|
60
68
|
original_end_index = preshift.object.end(argument_index)
|
61
69
|
original_properties = preshift.object.cs__properties
|
62
|
-
applicable_tags = original_properties.tags_at_range(
|
70
|
+
applicable_tags = original_properties.tags_at_range(original_start_index...original_end_index)
|
63
71
|
return if applicable_tags.empty?
|
64
72
|
|
65
73
|
applicable_tags.each do |tag_name, tag_ranges|
|
@@ -32,7 +32,7 @@ module Contrast
|
|
32
32
|
target_idx = 0
|
33
33
|
|
34
34
|
remove_ranges = []
|
35
|
-
|
35
|
+
start = nil
|
36
36
|
|
37
37
|
# loop over the target, the result of the delete
|
38
38
|
# every range of characters that it differs from the source
|
@@ -44,13 +44,12 @@ module Contrast
|
|
44
44
|
source_char = source_chars[source_idx]
|
45
45
|
if target_char == source_char
|
46
46
|
target_idx += 1
|
47
|
-
if
|
48
|
-
|
49
|
-
|
50
|
-
current_range = nil
|
47
|
+
if start
|
48
|
+
remove_ranges << (start...source_idx)
|
49
|
+
start = nil
|
51
50
|
end
|
52
51
|
else
|
53
|
-
|
52
|
+
start ||= source_idx
|
54
53
|
end
|
55
54
|
source_idx += 1
|
56
55
|
end
|
@@ -58,11 +57,7 @@ module Contrast
|
|
58
57
|
# once we're done looping over the target, anything left
|
59
58
|
# over is extra from the source that was deleted. tags
|
60
59
|
# applying to it need to be removed.
|
61
|
-
if source_idx != source_chars.length
|
62
|
-
remove_ranges << Contrast::Agent::Assess::AdjustedSpan.new(
|
63
|
-
source_idx,
|
64
|
-
source_chars.length)
|
65
|
-
end
|
60
|
+
remove_ranges << (source_idx...source_chars.length) if source_idx != source_chars.length
|
66
61
|
|
67
62
|
# handle deleting the removed ranges
|
68
63
|
target.cs__properties.delete_tags_at_ranges(remove_ranges)
|
@@ -50,19 +50,19 @@ module Contrast
|
|
50
50
|
length = args[1] || 1
|
51
51
|
# (void) negative range
|
52
52
|
arg += source.length if arg.negative?
|
53
|
-
|
53
|
+
arg...(arg + length)
|
54
54
|
end
|
55
55
|
|
56
56
|
def handle_string arg, source
|
57
57
|
idx = source.index(arg)
|
58
|
-
|
58
|
+
idx...(idx + arg.length)
|
59
59
|
end
|
60
60
|
|
61
61
|
def handle_regexp args, arg, source
|
62
62
|
match_data = arg.match(source)
|
63
63
|
# nil has the same meaning as 0. use full match
|
64
64
|
group = args[1] || 0
|
65
|
-
|
65
|
+
match_data.begin(group)...match_data.end(group)
|
66
66
|
end
|
67
67
|
|
68
68
|
def handle_range arg, source
|
@@ -74,7 +74,7 @@ module Contrast
|
|
74
74
|
finish += source.length if finish.negative?
|
75
75
|
finish += 1 unless arg.exclude_end?
|
76
76
|
|
77
|
-
|
77
|
+
start...finish
|
78
78
|
end
|
79
79
|
|
80
80
|
def determine_select_range source, args
|
@@ -52,7 +52,7 @@ module Contrast
|
|
52
52
|
current_index = 0
|
53
53
|
target.each do |elem|
|
54
54
|
elem_length = elem.length
|
55
|
-
range =
|
55
|
+
range = current_index...(current_index + elem_length)
|
56
56
|
tags = source.cs__properties.tags_at_range(range)
|
57
57
|
|
58
58
|
elem.cs__properties.clear_tags
|
@@ -139,7 +139,7 @@ module Contrast
|
|
139
139
|
def instrument_string_split
|
140
140
|
if @_instrument_string_split.nil?
|
141
141
|
@_instrument_string_split = begin
|
142
|
-
cs__scoped_require 'cs__assess_yield_track/cs__assess_yield_track' if AGENT.patch_yield?
|
142
|
+
cs__scoped_require 'cs__assess_yield_track/cs__assess_yield_track' if AGENT.patch_yield? && Funchook.available?
|
143
143
|
true
|
144
144
|
rescue StandardError => e
|
145
145
|
logger.error('Error loading split rb_yield patch', e)
|
@@ -2,6 +2,7 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
cs__scoped_require 'contrast/components/interface'
|
5
|
+
cs__scoped_require 'contrast/utils/duck_utils'
|
5
6
|
|
6
7
|
module Contrast
|
7
8
|
module Agent
|
@@ -109,7 +110,7 @@ module Contrast
|
|
109
110
|
last_idx = idx ? idx + 1 : nil
|
110
111
|
start_index = idx
|
111
112
|
end_index = idx + incoming.length
|
112
|
-
ranges <<
|
113
|
+
ranges << (start_index...end_index)
|
113
114
|
break unless global
|
114
115
|
end
|
115
116
|
ret.cs__properties.delete_tags_at_ranges(ranges)
|
@@ -133,12 +134,11 @@ module Contrast
|
|
133
134
|
end
|
134
135
|
|
135
136
|
def pattern_gsub preshift, ret
|
136
|
-
return unless ret
|
137
|
+
return unless Contrast::Utils::DuckUtils.trackable?(ret)
|
137
138
|
|
138
139
|
source = preshift.object
|
139
140
|
source.cs__properties.tag_keys.each do |key|
|
140
|
-
|
141
|
-
ret.cs__properties.add_tag(key, span)
|
141
|
+
ret.cs__properties.add_tag(key, 0...1)
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
@@ -28,23 +28,19 @@ module Contrast
|
|
28
28
|
else
|
29
29
|
remove_ranges = []
|
30
30
|
ret_chars = ret.chars
|
31
|
-
|
31
|
+
start = nil
|
32
32
|
source_chars.each_with_index do |char, idx|
|
33
33
|
if ret_chars[idx] == char
|
34
|
-
next unless
|
34
|
+
next unless start
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
curr_span = nil
|
36
|
+
remove_ranges << (start...idx)
|
37
|
+
start = nil
|
39
38
|
else
|
40
|
-
|
39
|
+
start ||= idx
|
41
40
|
end
|
42
41
|
end
|
43
42
|
# account for the last char being different
|
44
|
-
if
|
45
|
-
curr_span.stop = source_chars.length
|
46
|
-
remove_ranges << curr_span
|
47
|
-
end
|
43
|
+
remove_ranges << (start...source_chars.length) if start
|
48
44
|
ret.cs__properties.delete_tags_at_ranges(remove_ranges, false)
|
49
45
|
end
|
50
46
|
|
@@ -12,7 +12,6 @@ cs__scoped_require 'set'
|
|
12
12
|
|
13
13
|
cs__scoped_require 'contrast/utils/object_share'
|
14
14
|
cs__scoped_require 'contrast/utils/sha256_builder'
|
15
|
-
cs__scoped_require 'contrast/agent/assess/adjusted_span'
|
16
15
|
cs__scoped_require 'contrast/agent/assess/policy/source_validation/source_validation'
|
17
16
|
|
18
17
|
cs__scoped_require 'contrast/components/interface'
|
@@ -170,7 +169,7 @@ module Contrast
|
|
170
169
|
next unless Contrast::Agent::Assess::Policy::SourceValidation.valid?(tag, source_type, source_name)
|
171
170
|
|
172
171
|
length = Contrast::Utils::StringUtils.ret_length(target)
|
173
|
-
target.cs__properties.add_tag(tag,
|
172
|
+
target.cs__properties.add_tag(tag, 0...length)
|
174
173
|
target.cs__properties.add_properties(source_node.properties)
|
175
174
|
logger.trace('Source detected',
|
176
175
|
node_id: source_node.id,
|
@@ -18,7 +18,7 @@ module Contrast
|
|
18
18
|
# it was not, a Finding report is issued to the Service
|
19
19
|
module TriggerMethod
|
20
20
|
include Contrast::Components::Interface
|
21
|
-
access_component :analysis, :logging
|
21
|
+
access_component :analysis, :logging
|
22
22
|
|
23
23
|
# The level of TeamServer compliance our traces meet
|
24
24
|
CURRENT_FINDING_VERSION = 2
|
@@ -89,14 +89,12 @@ module Contrast
|
|
89
89
|
|
90
90
|
finding = Contrast::Api::Dtm::Finding.new
|
91
91
|
finding.rule_id = Contrast::Utils::StringUtils.protobuf_safe_string(trigger_node.rule_id)
|
92
|
-
finding.session_id = SETTINGS.session_id
|
93
92
|
finding.version = CURRENT_FINDING_VERSION
|
94
93
|
|
95
94
|
build_from_source(finding, source)
|
96
95
|
trigger_event = Contrast::Agent::Assess::Events::EventFactory.build(trigger_node, source, object, ret, args).to_dtm_event
|
97
96
|
finding.events << trigger_event
|
98
97
|
build_hash(finding, source)
|
99
|
-
build_tags(context)
|
100
98
|
finding.routes << context.route if context.route
|
101
99
|
context.activity.findings << finding
|
102
100
|
logger.trace('Finding created',
|
@@ -230,7 +228,7 @@ module Contrast
|
|
230
228
|
else
|
231
229
|
logger.warn('Trigger source is of unknown type. Unable to inspect.',
|
232
230
|
node_id: trigger_node.id,
|
233
|
-
source_id:
|
231
|
+
source_id: source.__id__,
|
234
232
|
source_type: source.cs__class.to_s)
|
235
233
|
logger.trace(source.to_s[0..99])
|
236
234
|
end
|
@@ -265,12 +263,6 @@ module Contrast
|
|
265
263
|
finding.hash_code = Contrast::Utils::StringUtils.force_utf8(hash_code)
|
266
264
|
finding.preflight = Contrast::Utils::PreflightUtil.create_preflight(finding)
|
267
265
|
end
|
268
|
-
|
269
|
-
def build_tags context
|
270
|
-
return unless ASSESS.tags
|
271
|
-
|
272
|
-
context.activity.finding_tags = Contrast::Utils::StringUtils.force_utf8(ASSESS.tags)
|
273
|
-
end
|
274
266
|
end
|
275
267
|
end
|
276
268
|
end
|