contrast-agent 6.6.3 → 6.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/.gitmodules +0 -3
- data/ext/cs__scope/cs__scope.c +1 -1
- data/lib/contrast/agent/assess/contrast_event.rb +2 -24
- data/lib/contrast/agent/assess/events/source_event.rb +7 -61
- data/lib/contrast/agent/assess/finalizers/hash.rb +11 -0
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +0 -55
- data/lib/contrast/agent/assess/policy/policy_node.rb +3 -3
- data/lib/contrast/agent/assess/policy/policy_node_utils.rb +0 -1
- data/lib/contrast/agent/assess/policy/propagation_node.rb +4 -4
- data/lib/contrast/agent/assess/policy/source_method.rb +24 -1
- data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +7 -5
- data/lib/contrast/agent/assess/policy/trigger/xpath.rb +6 -1
- data/lib/contrast/agent/assess/policy/trigger_method.rb +38 -119
- data/lib/contrast/agent/assess/policy/trigger_node.rb +3 -3
- data/lib/contrast/agent/assess/property/evented.rb +2 -12
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +42 -82
- data/lib/contrast/agent/assess/rule/response/base_rule.rb +11 -27
- data/lib/contrast/agent/assess/rule/response/body_rule.rb +1 -3
- data/lib/contrast/agent/assess/rule/response/cache_control_header_rule.rb +77 -62
- data/lib/contrast/agent/assess/rule/response/csp_header_insecure_rule.rb +1 -1
- data/lib/contrast/agent/assess/rule/response/framework/rails_support.rb +6 -1
- data/lib/contrast/agent/assess/rule/response/header_rule.rb +5 -5
- data/lib/contrast/agent/assess/rule/response/hsts_header_rule.rb +1 -1
- data/lib/contrast/agent/assess/rule/response/x_xss_protection_header_rule.rb +1 -1
- data/lib/contrast/agent/assess/tracker.rb +1 -7
- data/lib/contrast/agent/at_exit_hook.rb +1 -7
- data/lib/contrast/agent/excluder.rb +206 -0
- data/lib/contrast/agent/exclusion_matcher.rb +6 -0
- data/lib/contrast/agent/inventory/database_config.rb +18 -23
- data/lib/contrast/agent/middleware.rb +0 -1
- data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +4 -0
- data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +1 -0
- data/lib/contrast/agent/protect/rule/base.rb +64 -24
- data/lib/contrast/agent/protect/rule/base_service.rb +1 -0
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +18 -104
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_backdoors.rb +129 -0
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_base_rule.rb +169 -0
- data/lib/contrast/agent/protect/rule/deserialization.rb +7 -5
- data/lib/contrast/agent/protect/rule/path_traversal.rb +9 -7
- data/lib/contrast/agent/protect/rule/sql_sample_builder.rb +16 -14
- data/lib/contrast/agent/protect/rule/sqli/sqli_base_rule.rb +51 -0
- data/lib/contrast/agent/protect/rule/sqli/sqli_semantic/sqli_dangerous_functions.rb +67 -0
- data/lib/contrast/agent/protect/rule/sqli.rb +6 -31
- data/lib/contrast/agent/protect/rule/xxe.rb +11 -6
- data/lib/contrast/agent/protect/rule.rb +3 -1
- data/lib/contrast/agent/reporting/attack_result/attack_result.rb +8 -0
- data/lib/contrast/agent/reporting/attack_result/rasp_rule_sample.rb +91 -36
- data/lib/contrast/agent/reporting/attack_result/user_input.rb +11 -0
- data/lib/contrast/agent/reporting/details/bot_blocker_details.rb +29 -0
- data/lib/contrast/agent/reporting/details/cmd_injection_details.rb +30 -0
- data/lib/contrast/agent/reporting/details/details.rb +18 -0
- data/lib/contrast/agent/reporting/details/http_method_tempering_details.rb +27 -0
- data/lib/contrast/agent/reporting/details/ip_denylist_details.rb +27 -0
- data/lib/contrast/agent/reporting/details/no_sqli_details.rb +36 -0
- data/lib/contrast/agent/reporting/details/path_traversal_details.rb +24 -0
- data/lib/contrast/agent/reporting/details/path_traversal_semantic_analysis_details.rb +32 -0
- data/lib/contrast/agent/reporting/details/protect_rule_details.rb +17 -0
- data/lib/contrast/agent/reporting/details/sqli_dangerous_functions.rb +22 -0
- data/lib/contrast/agent/reporting/details/sqli_details.rb +36 -0
- data/lib/contrast/agent/reporting/details/untrusted_deserialization_details.rb +27 -0
- data/lib/contrast/agent/reporting/details/virtual_patch_details.rb +24 -0
- data/lib/contrast/agent/reporting/details/xss_details.rb +33 -0
- data/lib/contrast/agent/reporting/details/xss_match.rb +30 -0
- data/lib/contrast/agent/reporting/details/xxe_details.rb +36 -0
- data/lib/contrast/agent/reporting/details/xxe_match.rb +25 -0
- data/lib/contrast/agent/reporting/details/xxe_wrapper.rb +25 -0
- data/lib/contrast/agent/reporting/input_analysis/input_analysis_result.rb +1 -1
- data/lib/contrast/agent/reporting/masker/masker.rb +78 -65
- data/lib/contrast/agent/reporting/masker/masker_utils.rb +1 -30
- data/lib/contrast/agent/reporting/reporter.rb +1 -2
- data/lib/contrast/agent/reporting/reporting_events/agent_startup.rb +2 -2
- data/lib/contrast/agent/reporting/reporting_events/application_activity.rb +81 -15
- data/lib/contrast/agent/reporting/reporting_events/application_defend_activity.rb +13 -25
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_activity.rb +17 -22
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample.rb +46 -125
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample_activity.rb +5 -16
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attacker_activity.rb +10 -18
- data/lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb +6 -14
- data/lib/contrast/agent/reporting/reporting_events/application_startup.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_events/architecture_component.rb +7 -21
- data/lib/contrast/agent/reporting/reporting_events/finding.rb +19 -49
- data/lib/contrast/agent/reporting/reporting_events/finding_event.rb +12 -9
- data/lib/contrast/agent/reporting/reporting_events/finding_event_signature.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_events/finding_event_source.rb +23 -21
- data/lib/contrast/agent/reporting/reporting_events/finding_event_stack.rb +5 -18
- data/lib/contrast/agent/reporting/reporting_events/finding_event_taint_range.rb +1 -0
- data/lib/contrast/{api/decorators/trace_taint_range_tags.rb → agent/reporting/reporting_events/finding_event_taint_range_tags.rb} +7 -6
- data/lib/contrast/agent/reporting/reporting_events/finding_request.rb +45 -10
- data/lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +2 -2
- data/lib/contrast/agent/reporting/reporting_events/preflight_message.rb +10 -14
- data/lib/contrast/agent/reporting/reporting_events/reporting_event.rb +11 -0
- data/lib/contrast/agent/reporting/reporting_events/route_coverage.rb +3 -1
- data/lib/contrast/agent/reporting/reporting_events/route_discovery.rb +11 -23
- data/lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb +8 -26
- data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_utilities/build_preflight.rb +4 -7
- data/lib/contrast/agent/reporting/reporting_utilities/headers.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +2 -1
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +3 -3
- data/lib/contrast/agent/request.rb +4 -2
- data/lib/contrast/agent/request_context.rb +12 -15
- data/lib/contrast/agent/request_context_extend.rb +67 -69
- data/lib/contrast/agent/request_handler.rb +1 -11
- data/lib/contrast/agent/response.rb +0 -18
- data/lib/contrast/agent/service_heartbeat.rb +1 -1
- data/lib/contrast/agent/telemetry/events/event.rb +1 -1
- data/lib/contrast/agent/telemetry/events/metric_event.rb +1 -1
- data/lib/contrast/agent/telemetry/events/startup_metrics_event.rb +3 -3
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/api/communication/messaging_queue.rb +2 -3
- data/lib/contrast/api/communication/socket_client.rb +4 -4
- data/lib/contrast/api/communication/speedracer.rb +4 -8
- data/lib/contrast/api/decorators/agent_startup.rb +5 -6
- data/lib/contrast/api/decorators/application_settings.rb +2 -1
- data/lib/contrast/api/decorators/application_startup.rb +6 -6
- data/lib/contrast/api/decorators/message.rb +0 -4
- data/lib/contrast/api/decorators/rasp_rule_sample.rb +0 -6
- data/lib/contrast/api/decorators.rb +0 -6
- data/lib/contrast/api/dtm.pb.rb +0 -489
- data/lib/contrast/components/agent.rb +16 -12
- data/lib/contrast/components/api.rb +10 -10
- data/lib/contrast/components/app_context.rb +9 -9
- data/lib/contrast/components/app_context_extend.rb +1 -1
- data/lib/contrast/components/assess.rb +92 -38
- data/lib/contrast/components/assess_rules.rb +36 -0
- data/lib/contrast/components/config.rb +54 -12
- data/lib/contrast/components/contrast_service.rb +8 -8
- data/lib/contrast/components/heap_dump.rb +1 -1
- data/lib/contrast/components/protect.rb +5 -5
- data/lib/contrast/components/ruby_component.rb +81 -0
- data/lib/contrast/components/sampling.rb +1 -1
- data/lib/contrast/components/security_logger.rb +23 -0
- data/lib/contrast/components/service.rb +55 -0
- data/lib/contrast/components/settings.rb +12 -4
- data/lib/contrast/config/base_configuration.rb +1 -1
- data/lib/contrast/config/protect_rules_configuration.rb +17 -3
- data/lib/contrast/config/server_configuration.rb +1 -1
- data/lib/contrast/config.rb +0 -6
- data/lib/contrast/configuration.rb +81 -17
- data/lib/contrast/extension/assess/exec_trigger.rb +3 -1
- data/lib/contrast/extension/assess/marshal.rb +3 -2
- data/lib/contrast/extension/assess/string.rb +0 -1
- data/lib/contrast/extension/extension.rb +1 -1
- data/lib/contrast/framework/base_support.rb +0 -5
- data/lib/contrast/framework/grape/support.rb +1 -23
- data/lib/contrast/framework/manager.rb +0 -10
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +1 -6
- data/lib/contrast/framework/rails/support.rb +5 -58
- data/lib/contrast/framework/sinatra/support.rb +2 -21
- data/lib/contrast/logger/cef_log.rb +21 -3
- data/lib/contrast/logger/log.rb +1 -11
- data/lib/contrast/tasks/config.rb +4 -2
- data/lib/contrast/utils/assess/event_limit_utils.rb +28 -12
- data/lib/contrast/utils/assess/trigger_method_utils.rb +10 -18
- data/lib/contrast/utils/findings.rb +6 -5
- data/lib/contrast/utils/hash_digest.rb +9 -24
- data/lib/contrast/utils/hash_digest_extend.rb +6 -6
- data/lib/contrast/utils/invalid_configuration_util.rb +21 -58
- data/lib/contrast/utils/log_utils.rb +47 -17
- data/lib/contrast/utils/net_http_base.rb +7 -8
- data/lib/contrast/utils/patching/policy/patch_utils.rb +3 -2
- data/lib/contrast/utils/stack_trace_utils.rb +0 -25
- data/lib/contrast/utils/string_utils.rb +9 -0
- data/lib/contrast/utils/telemetry_client.rb +13 -7
- data/lib/contrast.rb +5 -10
- metadata +39 -28
- data/lib/contrast/agent/reporting/reporting_events/trace_event_source.rb +0 -30
- data/lib/contrast/agent/reporting/reporting_utilities/dtm_message.rb +0 -43
- data/lib/contrast/api/decorators/activity.rb +0 -33
- data/lib/contrast/api/decorators/architecture_component.rb +0 -36
- data/lib/contrast/api/decorators/finding.rb +0 -29
- data/lib/contrast/api/decorators/route_coverage.rb +0 -91
- data/lib/contrast/api/decorators/trace_event.rb +0 -120
- data/lib/contrast/api/decorators/trace_event_object.rb +0 -63
- data/lib/contrast/api/decorators/trace_event_signature.rb +0 -69
- data/lib/contrast/api/decorators/trace_taint_range.rb +0 -52
- data/lib/contrast/config/assess_configuration.rb +0 -93
- data/lib/contrast/config/assess_rules_configuration.rb +0 -32
- data/lib/contrast/config/root_configuration.rb +0 -90
- data/lib/contrast/config/ruby_configuration.rb +0 -81
- data/lib/contrast/config/service_configuration.rb +0 -49
- data/lib/contrast/utils/preflight_util.rb +0 -13
@@ -28,25 +28,12 @@ module Contrast
|
|
28
28
|
|
29
29
|
AGENT_CLASS_MARKER = '/lib/contrast/'
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
# @return [Contrast::Agent::Reporting::FindingEventStack,nil]
|
34
|
-
def convert stack
|
35
|
-
return unless stack
|
36
|
-
return if stack.include?(AGENT_CLASS_MARKER)
|
37
|
-
|
38
|
-
report = new
|
39
|
-
report.attach_data(stack)
|
40
|
-
report
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
# Parse the data from a Contrast::Agent::Assess::Tag to attach what is required for reporting to TeamServer to
|
45
|
-
# this Contrast::Agent::Reporting::FindingEventTaintRange
|
31
|
+
# To play nice with the way that TeamServer is rendering these values, we only populate the file_name field with
|
32
|
+
# exactly what we want them to display.
|
46
33
|
#
|
47
|
-
# @param
|
48
|
-
def
|
49
|
-
@file =
|
34
|
+
# @param file_name [String] the caller location this stack frame represents.
|
35
|
+
def initialize file_name
|
36
|
+
@file = file_name
|
50
37
|
end
|
51
38
|
|
52
39
|
# Convert the instance variables on the class, and other information, into the identifiers required for
|
@@ -2,13 +2,13 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
module Contrast
|
5
|
-
module
|
6
|
-
module
|
7
|
-
# A holder for the valid tags that can be sent to
|
8
|
-
#
|
9
|
-
|
10
|
-
module TraceTaintRangeTags
|
5
|
+
module Agent
|
6
|
+
module Reporting
|
7
|
+
# A holder for the valid tags that can be sent to TeamServer that we have to honor. Placed here so as not to
|
8
|
+
# clutter other code.
|
9
|
+
module FindingEventTaintRangeTags
|
11
10
|
# EventTagTypeDTM
|
11
|
+
# @return [Array<Symbol>]
|
12
12
|
VALID_TAGS = %w[
|
13
13
|
XML_ENCODED
|
14
14
|
XML_DECODED
|
@@ -97,6 +97,7 @@ module Contrast
|
|
97
97
|
DATABASE_WRITE
|
98
98
|
].cs__freeze
|
99
99
|
|
100
|
+
# @return [Array<Symbol>]
|
100
101
|
VALID_SOURCE_TAGS = %w[NO_NEWLINES UNTRUSTED CROSS_SITE LIMITED_CHARS].cs__freeze
|
101
102
|
end
|
102
103
|
end
|
@@ -13,10 +13,12 @@ module Contrast
|
|
13
13
|
class FindingRequest
|
14
14
|
include Contrast::Components::Logger::InstanceMethods
|
15
15
|
|
16
|
+
OMITTED_BODY = '{{body-omitted-by-contrast}}'
|
17
|
+
|
16
18
|
# @return [String] the body of this request
|
17
|
-
|
19
|
+
attr_accessor :body
|
18
20
|
# @return [Hash<String,Array<String>>] the headers of this request
|
19
|
-
|
21
|
+
attr_accessor :headers
|
20
22
|
# @return [String] the HTTP verb of this request
|
21
23
|
attr_reader :method
|
22
24
|
# @return [Hash<String,Array<String>>] the parameters of this request
|
@@ -26,16 +28,27 @@ module Contrast
|
|
26
28
|
# @return [String] the HTTP(S) protocol of this request
|
27
29
|
attr_reader :protocol
|
28
30
|
# @return [String] the query string of this request
|
29
|
-
|
31
|
+
attr_accessor :query_string
|
30
32
|
# @return [String] the url, including path and script, of this request
|
31
33
|
attr_reader :uri
|
32
34
|
# @return [String] the HTTP version of this request
|
33
35
|
attr_reader :version
|
36
|
+
# @return [Integer]
|
37
|
+
attr_reader :ip
|
38
|
+
# @return [String] Byte representation of the body
|
39
|
+
attr_accessor :body_binary
|
40
|
+
# @return [Hash]
|
41
|
+
attr_reader :cookies
|
42
|
+
# REMOVE_DTM_REQUEST
|
43
|
+
# @return [Contrast::Api::Dtm::HttpRequest]
|
44
|
+
attr_reader :dtm
|
34
45
|
|
35
46
|
class << self
|
36
47
|
# @param request [Contrast::Agent::Request]
|
37
48
|
# @return [Contrast::Agent::Reporting::FindingRequest]
|
38
49
|
def convert request
|
50
|
+
return unless request
|
51
|
+
|
39
52
|
report = new
|
40
53
|
report.attach_data(request)
|
41
54
|
report
|
@@ -47,15 +60,11 @@ module Contrast
|
|
47
60
|
#
|
48
61
|
# @param request [Contrast::Agent::Request]
|
49
62
|
def attach_data request
|
63
|
+
# REMOVE_DTM_REQUEST
|
64
|
+
@dtm = request.dtm
|
50
65
|
@body = request.body
|
51
66
|
@headers = {}
|
52
|
-
request
|
53
|
-
# We need to change from the uppercase _ format to capitalized - format.
|
54
|
-
header = key.split('_')
|
55
|
-
header.each(&:capitalize!)
|
56
|
-
header = header.join('-')
|
57
|
-
headers[header] = value.split
|
58
|
-
end
|
67
|
+
extract_headers(request)
|
59
68
|
@method = request.request_method
|
60
69
|
@parameters = {}
|
61
70
|
request.parameters.each_pair { |key, value| @parameters[key] = Array(value) }
|
@@ -64,6 +73,14 @@ module Contrast
|
|
64
73
|
@query_string = request.query_string
|
65
74
|
@uri = request.normalized_uri
|
66
75
|
@version = request.version
|
76
|
+
@ip = request.ip || ''
|
77
|
+
@body_binary = if omit_body?(request)
|
78
|
+
OMITTED_BODY
|
79
|
+
else
|
80
|
+
Contrast::Utils::StringUtils.force_utf8(request.body)
|
81
|
+
end
|
82
|
+
@cookies = {}
|
83
|
+
@cookies = request.cookies unless request.cookies.empty?
|
67
84
|
end
|
68
85
|
|
69
86
|
# Convert the instance variables on the class, and other information, into the identifiers required for
|
@@ -92,12 +109,30 @@ module Contrast
|
|
92
109
|
}
|
93
110
|
end
|
94
111
|
|
112
|
+
def omit_body? request
|
113
|
+
return true if ::Contrast::AGENT.omit_body?
|
114
|
+
return false if request.document_type != :NORMAL
|
115
|
+
|
116
|
+
request.media_type&.include?('multipart/form-data')
|
117
|
+
end
|
118
|
+
|
95
119
|
def validate
|
96
120
|
unless method && !method.empty? # rubocop:disable Security/Object/Method
|
97
121
|
raise(ArgumentError, "#{ self } did not have a proper method. Unable to continue.")
|
98
122
|
end
|
99
123
|
raise(ArgumentError, "#{ self } did not have a proper uri. Unable to continue.") unless uri && !uri.empty?
|
100
124
|
end
|
125
|
+
|
126
|
+
# @param request [Contrast::Agent::Request]
|
127
|
+
def extract_headers request
|
128
|
+
request.headers.each_pair do |key, value|
|
129
|
+
# We need to change from the uppercase _ format to capitalized - format.
|
130
|
+
header = key.split('_')
|
131
|
+
header.each(&:capitalize!)
|
132
|
+
header = header.join('-')
|
133
|
+
headers[header] = value.split
|
134
|
+
end
|
135
|
+
end
|
101
136
|
end
|
102
137
|
end
|
103
138
|
end
|
@@ -11,7 +11,7 @@ module Contrast
|
|
11
11
|
include Contrast::Components::Logger::InstanceMethods
|
12
12
|
|
13
13
|
# @param [String] Sha256Sum of library as identified by the agent
|
14
|
-
|
14
|
+
attr_reader :id
|
15
15
|
# @param [Array<String>] List of file paths that have been loaded out of or executed by the library
|
16
16
|
attr_reader :names
|
17
17
|
|
@@ -24,7 +24,7 @@ module Contrast
|
|
24
24
|
attr_accessor :url
|
25
25
|
# @param [String] the HTTP Verb used to access the method in the route.
|
26
26
|
attr_accessor :verb
|
27
|
-
# @param [Array<Contrast::Agent::Reporting::
|
27
|
+
# @param [Array<Contrast::Agent::Reporting::FindingEventSource>] the sources of user input accessed during this
|
28
28
|
# request. Used for remediation determinations in TeamServer.
|
29
29
|
attr_reader :sources
|
30
30
|
|
@@ -56,7 +56,7 @@ module Contrast
|
|
56
56
|
|
57
57
|
{
|
58
58
|
session_id: ::Contrast::ASSESS.session_id,
|
59
|
-
sources: @sources.map(&:
|
59
|
+
sources: @sources.map(&:to_controlled_observation_hash),
|
60
60
|
signature: @signature,
|
61
61
|
verb: @verb,
|
62
62
|
url: @url
|
@@ -1,9 +1,10 @@
|
|
1
1
|
# Copyright (c) 2022 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/reporting/reporting_events/reporting_event'
|
4
5
|
require 'contrast/components/assess'
|
5
6
|
require 'contrast/components/logger'
|
6
|
-
require 'contrast/
|
7
|
+
require 'contrast/utils/string_utils'
|
7
8
|
|
8
9
|
module Contrast
|
9
10
|
module Agent
|
@@ -13,6 +14,8 @@ module Contrast
|
|
13
14
|
# identifying information of a Finding/Trace, which TeamServer will use to determine if it requires the full
|
14
15
|
# information of the Finding/Trace to be reported.
|
15
16
|
class PreflightMessage
|
17
|
+
include Contrast::Components::Logger::InstanceMethods
|
18
|
+
|
16
19
|
# @return [String] the message identifier; rule_id,hash
|
17
20
|
attr_accessor :data
|
18
21
|
# @return [String] CRC checksum of the finding to which this message pertains
|
@@ -26,9 +29,6 @@ module Contrast
|
|
26
29
|
CODE = :TRACE
|
27
30
|
|
28
31
|
def initialize
|
29
|
-
@app_language = Contrast::Utils::ObjectShare::RUBY
|
30
|
-
@app_name = ::Contrast::APP_CONTEXT.name # rubocop:disable Security/Module/Name
|
31
|
-
@app_version = ::Contrast::APP_CONTEXT.version
|
32
32
|
@routes = []
|
33
33
|
end
|
34
34
|
|
@@ -47,24 +47,20 @@ module Contrast
|
|
47
47
|
|
48
48
|
{
|
49
49
|
code: CODE,
|
50
|
-
app_language:
|
51
|
-
app_name:
|
52
|
-
app_version:
|
50
|
+
app_language: Contrast::Utils::ObjectShare::RUBY,
|
51
|
+
app_name: ::Contrast::APP_CONTEXT.name, # rubocop:disable Security/Module/Name
|
52
|
+
app_version: ::Contrast::APP_CONTEXT.version,
|
53
53
|
data: '',
|
54
54
|
key: 0,
|
55
|
-
routes: @routes,
|
55
|
+
routes: @routes.map(&:to_controlled_hash),
|
56
56
|
session_id: ::Contrast::ASSESS.session_id
|
57
57
|
}
|
58
58
|
end
|
59
59
|
|
60
60
|
# @raise [ArgumentError]
|
61
61
|
def validate
|
62
|
-
|
63
|
-
|
64
|
-
raise(ArgumentError, "#{ cs__class } did not have a proper application name. Unable to continue.")
|
65
|
-
end
|
66
|
-
unless @app_language
|
67
|
-
raise(ArgumentError, "#{ cs__class } did not have a proper application language. Unable to continue.")
|
62
|
+
unless Contrast::Utils::StringUtils.present?(data)
|
63
|
+
raise(ArgumentError, "#{ cs__class } did not have a proper data. Unable to continue.")
|
68
64
|
end
|
69
65
|
unless ::Contrast::ASSESS.session_id
|
70
66
|
raise(ArgumentError, "#{ cs__class } did not have a proper session id. Unable to continue.")
|
@@ -49,6 +49,17 @@ module Contrast
|
|
49
49
|
|
50
50
|
# @raise [ArgumentError]
|
51
51
|
def validate; end
|
52
|
+
|
53
|
+
# Helper method to get json representation of event and handle errors
|
54
|
+
#
|
55
|
+
# @return [String] - JSON
|
56
|
+
def event_json
|
57
|
+
hsh = to_controlled_hash
|
58
|
+
hsh.to_json
|
59
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
60
|
+
logger.error('Unable to convert JSON string', e, hsh)
|
61
|
+
raise(e)
|
62
|
+
end
|
52
63
|
end
|
53
64
|
end
|
54
65
|
end
|
@@ -42,7 +42,9 @@ module Contrast
|
|
42
42
|
# @param url [String] the literal url of the route actively being executed
|
43
43
|
# @return [Contrast::Agent::Reporting::RouteCoverage]
|
44
44
|
def attach_rack_based_data final_controller, method, route_pattern, url = nil
|
45
|
-
if
|
45
|
+
if Contrast::Utils::ClassUtil.truly_defined?('Grape::Router::Route') &&
|
46
|
+
route_pattern.cs__is_a?(Grape::Router::Route)
|
47
|
+
|
46
48
|
safe_pattern = route_pattern.pattern&.path&.to_s
|
47
49
|
safe_url = source_or_string(url || safe_pattern)
|
48
50
|
else
|
@@ -14,34 +14,22 @@ module Contrast
|
|
14
14
|
# externally accessible endpoints within the application, as registered to the application framework. They may or
|
15
15
|
# may not have been invoked at the time of reporting.
|
16
16
|
#
|
17
|
-
# @attr_reader observations [observations] the routes and verbs seen that match to this Route
|
18
|
-
# @attr_reader signature [String] the unique identifier for this route; typically the method signature. Required
|
19
|
-
# for reporting.
|
20
17
|
class RouteDiscovery
|
21
18
|
include Contrast::Components::Logger::InstanceMethods
|
22
19
|
|
23
|
-
#
|
24
|
-
|
20
|
+
# @return [Array<Contrast::Agent::Reporting::RouteDiscoveryObservation>] the routes and verbs seen that match
|
21
|
+
# to this Route.
|
22
|
+
attr_reader :observations
|
23
|
+
# @return [String] the unique identifier for this route; typically the method signature. Required for
|
24
|
+
# reporting.
|
25
|
+
attr_accessor :signature
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
# @return [Contrast::Agent::Reporting::RouteDiscovery]
|
31
|
-
def convert route_coverage_dtm
|
32
|
-
report = new
|
33
|
-
report.attach_data(route_coverage_dtm)
|
34
|
-
report
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
# Attach the data from the protobuf models to this reporter so that it can be sent to TeamServer directly
|
39
|
-
#
|
40
|
-
# @param route_coverage_dtm [Contrast::Api::Dtm::RouteCoverage]
|
41
|
-
def attach_data route_coverage_dtm
|
42
|
-
@signature = route_coverage_dtm.route
|
27
|
+
# @param signature [String]
|
28
|
+
# @param observation [Contrast::Agent::Reporting::RouteDiscoveryObservation]
|
29
|
+
def initialize signature, observation
|
30
|
+
@signature = signature
|
43
31
|
@observations = []
|
44
|
-
observations <<
|
32
|
+
observations << observation
|
45
33
|
end
|
46
34
|
|
47
35
|
# Convert the instance variables on the class, and other information, into the identifiers required for
|
@@ -12,36 +12,18 @@ module Contrast
|
|
12
12
|
# reporting system to relay this information in the Application Update messages. These route observations are
|
13
13
|
# used by TeamServer to construct the route coverage information for the assess feature. They represent the
|
14
14
|
# literal URL and HTTP verb used to invoke a method in the application, as routed by the application framework.
|
15
|
-
#
|
16
|
-
# @attr_reader url [String] the URL requested to hit this endpoint. Required for reporting.
|
17
|
-
# @attr_reader verb [String] the HTTP Method requested to his this endpoint. Empty means all, so is allowed.
|
18
|
-
# for reporting.
|
19
15
|
class RouteDiscoveryObservation
|
20
16
|
include Contrast::Components::Logger::InstanceMethods
|
21
17
|
|
22
|
-
# required attributes
|
23
|
-
|
24
|
-
#
|
25
|
-
|
18
|
+
# @return [String] the URL requested to hit this endpoint. Required for reporting; required attributes
|
19
|
+
attr_accessor :url
|
20
|
+
# @return [String] the HTTP Method requested to his this endpoint. Empty means all, so is allowed for
|
21
|
+
# reporting; optional attributes
|
22
|
+
attr_accessor :verb
|
26
23
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
# @param route_coverage_dtm [Contrast::Api::Dtm::RouteCoverage]
|
31
|
-
# @return [Contrast::Agent::Reporting::RouteDiscoveryObservation]
|
32
|
-
def convert route_coverage_dtm
|
33
|
-
report = new
|
34
|
-
report.attach_data(route_coverage_dtm)
|
35
|
-
report
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
# Attach the data from the protobuf models to this reporter so that it can be sent to TeamServer directly
|
40
|
-
#
|
41
|
-
# @param route_coverage_dtm [Contrast::Api::Dtm::RouteCoverage]
|
42
|
-
def attach_data route_coverage_dtm
|
43
|
-
@url = route_coverage_dtm.url
|
44
|
-
@verb = route_coverage_dtm.verb if Contrast::Utils::StringUtils.present?(route_coverage_dtm.verb)
|
24
|
+
def initialize url, verb
|
25
|
+
@url = url
|
26
|
+
@verb = verb if Contrast::Utils::StringUtils.present?(verb)
|
45
27
|
end
|
46
28
|
|
47
29
|
# Convert the instance variables on the class, and other information, into the identifiers required for
|
@@ -29,7 +29,7 @@ module Contrast
|
|
29
29
|
return unless ::Contrast::API.request_audit_requests || ::Contrast::API.request_audit_responses
|
30
30
|
|
31
31
|
file_name = event.cs__respond_to?(:file_name) ? event.file_name : event.cs__class.cs__name.to_s.downcase
|
32
|
-
data = event.
|
32
|
+
data = event.event_json
|
33
33
|
log_data(:request, file_name, data) if data
|
34
34
|
return unless ::Contrast::API.request_audit_responses
|
35
35
|
|
@@ -14,17 +14,14 @@ module Contrast
|
|
14
14
|
module BuildPreflight
|
15
15
|
class << self
|
16
16
|
# @param finding [Contrast::Agent::Reporting::Finding]
|
17
|
-
# @
|
18
|
-
def
|
17
|
+
# @return [Contrast::Agent::Reporting::Preflight, nil]
|
18
|
+
def generate finding
|
19
19
|
return unless finding
|
20
20
|
|
21
|
-
# save the current finding
|
22
|
-
Contrast::Agent::Reporting::ReportingStorage[finding.hash_code] = finding
|
23
|
-
|
24
21
|
new_preflight = Contrast::Agent::Reporting::Preflight.new
|
25
22
|
new_preflight_message = Contrast::Agent::Reporting::PreflightMessage.new
|
26
|
-
|
27
|
-
new_preflight_message.routes <<
|
23
|
+
finding.routes.each do |route|
|
24
|
+
new_preflight_message.routes << route
|
28
25
|
end
|
29
26
|
new_preflight_message.hash_code = finding.hash_code
|
30
27
|
new_preflight_message.data = "#{ finding.rule_id },#{ finding.hash_code }"
|
@@ -43,7 +43,6 @@ module Contrast
|
|
43
43
|
# @param connection [Net::HTTP] open connection
|
44
44
|
def startup! connection
|
45
45
|
return if status.startup_messages_sent?
|
46
|
-
return unless Contrast::Agent::Reporter.enabled?
|
47
46
|
|
48
47
|
send_agent_startup(connection)
|
49
48
|
end
|
@@ -57,6 +56,8 @@ module Contrast
|
|
57
56
|
def send_event event, connection
|
58
57
|
return unless connection
|
59
58
|
|
59
|
+
logger.debug('Preparing to send reporting event', event_class: event.cs__class)
|
60
|
+
|
60
61
|
request = build_request(event)
|
61
62
|
response = connection.request(request)
|
62
63
|
audit&.audit_event(event, response) if ::Contrast::API.request_audit_enable
|
@@ -69,7 +69,7 @@ module Contrast
|
|
69
69
|
# Handles standard error case, logs and set status for failure
|
70
70
|
#
|
71
71
|
# @param event [Contrast::Agent::Reporting::ReportingEvent]
|
72
|
-
#
|
72
|
+
# One of the DTMs valid for the event field of Contrast::Api::Dtm::Message
|
73
73
|
# @param error_msg [StandardError]
|
74
74
|
# @return nil [NilClass] to be passed as response
|
75
75
|
def handle_error event, error_msg
|
@@ -105,7 +105,7 @@ module Contrast
|
|
105
105
|
findings_to_return = response.body.split(',').delete_if { |el| el.include?('*') }
|
106
106
|
findings_to_return.each do |index|
|
107
107
|
preflight_message = event.messages[index.to_i]
|
108
|
-
corresponding_finding = Contrast::Agent::Reporting::ReportingStorage.delete(preflight_message.
|
108
|
+
corresponding_finding = Contrast::Agent::Reporting::ReportingStorage.delete(preflight_message.data)
|
109
109
|
next unless corresponding_finding
|
110
110
|
|
111
111
|
send_event(corresponding_finding, connection)
|
@@ -130,7 +130,7 @@ module Contrast
|
|
130
130
|
end
|
131
131
|
build_headers(request)
|
132
132
|
event.attach_headers(request)
|
133
|
-
request.body = event.
|
133
|
+
request.body = event.event_json
|
134
134
|
request
|
135
135
|
end
|
136
136
|
end
|
@@ -33,10 +33,10 @@ module Contrast
|
|
33
33
|
|
34
34
|
# @return [Rack::Request] The passed to the Agent RackRequest to be wrapped.
|
35
35
|
attr_reader :rack_request
|
36
|
-
# @return [Contrast::Api::Dtm::RouteCoverage] the route, used for findings, of this request
|
37
|
-
attr_accessor :route
|
38
36
|
# @return [Contrast::Agent::Reporting::ObservedRoute] the route, used for coverage, of this request
|
39
37
|
attr_accessor :observed_route
|
38
|
+
# @return [Contrast::Agent::Reporting::RouteDiscovery]
|
39
|
+
attr_accessor :discovered_route
|
40
40
|
|
41
41
|
# Delegate calls to the following methods to the attribute @rack_request
|
42
42
|
def_delegators :@rack_request, :base_url, :cookies, :env, :ip, :media_type, :path, :port, :query_string,
|
@@ -142,6 +142,8 @@ module Contrast
|
|
142
142
|
@_body
|
143
143
|
end
|
144
144
|
|
145
|
+
# REMOVE_DTM_REQUEST
|
146
|
+
#
|
145
147
|
# Unlike most of our translation, which is called where needed for each
|
146
148
|
# message and forgotten, we'll leave this method to call the build as we
|
147
149
|
# don't want to pay to reconstruct the DTM for this Request multiple
|
@@ -12,6 +12,7 @@ require 'contrast/utils/request_utils'
|
|
12
12
|
require 'contrast/agent/request_context_extend'
|
13
13
|
require 'contrast/agent/reporting/reporting_events/observed_route'
|
14
14
|
require 'contrast/agent/reporting/input_analysis/input_analysis'
|
15
|
+
require 'contrast/agent/reporting/reporting_events/application_activity'
|
15
16
|
|
16
17
|
module Contrast
|
17
18
|
module Agent
|
@@ -25,7 +26,7 @@ module Contrast
|
|
25
26
|
|
26
27
|
EMPTY_INPUT_ANALYSIS_PB = Contrast::Api::Settings::InputAnalysis.new
|
27
28
|
|
28
|
-
# @return [Contrast::
|
29
|
+
# @return [Contrast::Agent::Reporting:ApplicationActivity] the application activity found in this request
|
29
30
|
attr_reader :activity
|
30
31
|
# @return [Hash] context used to log the request
|
31
32
|
attr_reader :logging_hash
|
@@ -36,10 +37,12 @@ module Contrast
|
|
36
37
|
# @return [Contrast::Agent::Response] our wrapper around the Rack::Response or Array for this context,
|
37
38
|
# only available after the application has finished its processing
|
38
39
|
attr_reader :response
|
39
|
-
# @return [Contrast::
|
40
|
-
attr_reader :
|
40
|
+
# @return [Contrast::Agent::Reporting::RouteDiscovery] the route, used for findings, of this request
|
41
|
+
attr_reader :discovered_route
|
41
42
|
# @return [Contrast::Api::Settings::InputAnalysis] the protect input analysis of sources on this request
|
42
43
|
attr_reader :speedracer_input_analysis
|
44
|
+
# @return [Array<String>] the hash of findings already reported fro this request
|
45
|
+
attr_reader :reported_findings
|
43
46
|
# @return [Contrast::Utils::Timer] when the context was created
|
44
47
|
attr_reader :timer
|
45
48
|
|
@@ -53,9 +56,7 @@ module Contrast
|
|
53
56
|
|
54
57
|
# instantiate helper for request and response
|
55
58
|
@request = Contrast::Agent::Request.new(rack_request)
|
56
|
-
|
57
|
-
@activity = Contrast::Api::Dtm::Activity.new
|
58
|
-
@activity.http_request = request.dtm
|
59
|
+
@activity = Contrast::Agent::Reporting::ApplicationActivity.new
|
59
60
|
|
60
61
|
# build analyzer
|
61
62
|
@do_not_track = false
|
@@ -80,6 +81,8 @@ module Contrast
|
|
80
81
|
@sample_req, @sample_res = Contrast::Utils::Assess::SamplingUtil.instance.sample?(@request)
|
81
82
|
end
|
82
83
|
|
84
|
+
@reported_findings = []
|
85
|
+
|
83
86
|
handle_routes
|
84
87
|
end
|
85
88
|
end
|
@@ -125,7 +128,7 @@ module Contrast
|
|
125
128
|
end
|
126
129
|
|
127
130
|
def reset_activity
|
128
|
-
@activity = Contrast::
|
131
|
+
@activity = Contrast::Agent::Reporting::ApplicationActivity.new
|
129
132
|
@observed_route = Contrast::Agent::Reporting::ObservedRoute.new
|
130
133
|
end
|
131
134
|
|
@@ -133,14 +136,8 @@ module Contrast
|
|
133
136
|
|
134
137
|
def handle_routes
|
135
138
|
@observed_route = Contrast::Agent::Reporting::ObservedRoute.new
|
136
|
-
|
137
|
-
|
138
|
-
route_dtm = Contrast::Agent.framework_manager.get_route_dtm(@request)
|
139
|
-
# new_route_coverage_dtm = Contrast::Agent.framework_manager.get_route_information(@request)
|
140
|
-
# TODO: RUBY-1705 -- delete append_route_coverage
|
141
|
-
append_route_coverage(route_dtm)
|
142
|
-
# TODO: RUBY-1705 -- change to take [Contrast::Agent::Reporting::ObservedRoute]
|
143
|
-
append_to_observed_route(route_dtm)
|
139
|
+
reporting_route = Contrast::Agent.framework_manager.get_route_information(@request)
|
140
|
+
append_to_observed_route(reporting_route)
|
144
141
|
end
|
145
142
|
end
|
146
143
|
end
|