contrast-agent 6.0.0 → 6.1.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_regexp/cs__assess_regexp.c +15 -2
- data/ext/cs__assess_regexp/cs__assess_regexp.h +2 -0
- data/ext/cs__assess_string/cs__assess_string.c +8 -0
- data/ext/cs__assess_test/cs__assess_test.h +9 -0
- data/ext/cs__assess_test/cs__assess_tests.c +22 -0
- data/ext/cs__assess_test/extconf.rb +5 -0
- data/ext/cs__common/cs__common.c +101 -0
- data/ext/cs__common/cs__common.h +29 -5
- data/ext/cs__contrast_patch/cs__contrast_patch.c +1 -1
- data/ext/cs__tests/cs__tests.c +12 -0
- data/ext/cs__tests/cs__tests.h +3 -0
- data/ext/cs__tests/extconf.rb +5 -0
- data/lib/contrast/agent/assess/contrast_object.rb +16 -16
- data/lib/contrast/agent/assess/events/source_event.rb +17 -19
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +2 -16
- data/lib/contrast/agent/assess/policy/propagator/split.rb +15 -19
- data/lib/contrast/agent/assess/policy/trigger_method.rb +3 -11
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +7 -2
- data/lib/contrast/agent/assess/rule/response/base_rule.rb +11 -3
- data/lib/contrast/agent/assess/rule/response/cache_control_header_rule.rb +60 -36
- data/lib/contrast/agent/at_exit_hook.rb +1 -1
- data/lib/contrast/agent/inventory/database_config.rb +10 -3
- data/lib/contrast/agent/middleware.rb +3 -3
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +0 -2
- data/lib/contrast/agent/patching/policy/patch.rb +13 -12
- data/lib/contrast/agent/patching/policy/patcher.rb +1 -1
- data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +6 -2
- data/lib/contrast/agent/reporting/masker/masker.rb +8 -11
- data/lib/contrast/agent/reporting/masker/masker_utils.rb +8 -4
- data/lib/contrast/agent/reporting/reporter.rb +11 -16
- data/lib/contrast/agent/reporting/reporter_heartbeat.rb +49 -0
- data/lib/contrast/agent/reporting/reporting_events/agent_startup.rb +6 -2
- data/lib/contrast/agent/reporting/reporting_events/application_activity.rb +53 -0
- data/lib/contrast/agent/reporting/reporting_events/application_defend_activity.rb +48 -0
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_activity.rb +64 -0
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample.rb +70 -0
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample_activity.rb +57 -0
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attacker_activity.rb +56 -0
- data/lib/contrast/agent/reporting/reporting_events/application_inventory.rb +5 -1
- data/lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb +58 -0
- data/lib/contrast/agent/reporting/reporting_events/application_reporting_event.rb +27 -0
- data/lib/contrast/agent/reporting/reporting_events/application_startup.rb +20 -10
- data/lib/contrast/agent/reporting/reporting_events/application_update.rb +7 -12
- data/lib/contrast/agent/reporting/reporting_events/finding.rb +9 -3
- data/lib/contrast/agent/reporting/reporting_events/finding_event.rb +2 -4
- data/lib/contrast/agent/reporting/reporting_events/finding_event_object.rb +3 -3
- data/lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb +6 -2
- data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +7 -3
- data/lib/contrast/agent/reporting/reporting_events/poll.rb +6 -2
- data/lib/contrast/agent/reporting/reporting_events/preflight.rb +10 -8
- data/lib/contrast/agent/reporting/reporting_events/preflight_message.rb +6 -10
- data/lib/contrast/agent/reporting/reporting_events/server_activity.rb +12 -20
- data/lib/contrast/agent/reporting/reporting_events/server_reporting_event.rb +27 -0
- data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +17 -27
- data/lib/contrast/agent/reporting/reporting_utilities/build_preflight.rb +38 -0
- data/lib/contrast/agent/reporting/reporting_utilities/dtm_message.rb +8 -0
- data/lib/contrast/agent/reporting/reporting_utilities/endpoints.rb +6 -0
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +9 -4
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +54 -67
- data/lib/contrast/agent/reporting/reporting_utilities/response.rb +17 -7
- data/lib/contrast/agent/reporting/reporting_utilities/response_extractor.rb +8 -5
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +10 -10
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +32 -17
- data/lib/contrast/agent/reporting/settings/protect.rb +1 -1
- data/lib/contrast/agent/reporting/settings/protect_server_feature.rb +1 -1
- data/lib/contrast/agent/request.rb +3 -3
- data/lib/contrast/agent/request_context_extend.rb +1 -1
- data/lib/contrast/agent/request_handler.rb +3 -3
- data/lib/contrast/agent/response.rb +2 -0
- data/lib/contrast/agent/service_heartbeat.rb +6 -48
- data/lib/contrast/agent/static_analysis.rb +1 -1
- data/lib/contrast/agent/telemetry/base.rb +151 -0
- data/lib/contrast/agent/telemetry/events/event.rb +35 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_base.rb +44 -36
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_event.rb +29 -21
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message.rb +91 -73
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message_exception.rb +62 -44
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_stack_frame.rb +50 -33
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exceptions.rb +20 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exceptions_report.rb +32 -0
- data/lib/contrast/agent/telemetry/events/metric_event.rb +28 -0
- data/lib/contrast/agent/telemetry/events/startup_metrics_event.rb +123 -0
- data/lib/contrast/agent/thread_watcher.rb +52 -68
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/agent/worker_thread.rb +8 -0
- data/lib/contrast/agent.rb +1 -3
- data/lib/contrast/api/communication/messaging_queue.rb +28 -11
- data/lib/contrast/api/communication/response_processor.rb +7 -10
- data/lib/contrast/api/communication/speedracer.rb +1 -1
- data/lib/contrast/api/decorators/activity.rb +33 -0
- data/lib/contrast/api/decorators/http_request.rb +1 -1
- data/lib/contrast/components/config.rb +13 -22
- data/lib/contrast/components/contrast_service.rb +9 -0
- data/lib/contrast/components/settings.rb +10 -0
- data/lib/contrast/config/agent_configuration.rb +21 -11
- data/lib/contrast/config/api_configuration.rb +12 -8
- data/lib/contrast/config/api_proxy_configuration.rb +7 -3
- data/lib/contrast/config/application_configuration.rb +15 -11
- data/lib/contrast/config/assess_configuration.rb +13 -9
- data/lib/contrast/config/assess_rules_configuration.rb +5 -1
- data/lib/contrast/config/base_configuration.rb +3 -35
- data/lib/contrast/config/certification_configuration.rb +9 -5
- data/lib/contrast/config/exception_configuration.rb +10 -7
- data/lib/contrast/config/heap_dump_configuration.rb +13 -9
- data/lib/contrast/config/inventory_configuration.rb +9 -6
- data/lib/contrast/config/logger_configuration.rb +9 -6
- data/lib/contrast/config/protect_configuration.rb +9 -6
- data/lib/contrast/config/protect_rule_configuration.rb +12 -8
- data/lib/contrast/config/protect_rules_configuration.rb +18 -17
- data/lib/contrast/config/request_audit_configuration.rb +10 -7
- data/lib/contrast/config/root_configuration.rb +28 -11
- data/lib/contrast/config/ruby_configuration.rb +14 -11
- data/lib/contrast/config/sampling_configuration.rb +11 -8
- data/lib/contrast/config/server_configuration.rb +13 -9
- data/lib/contrast/config/service_configuration.rb +14 -11
- data/lib/contrast/configuration.rb +19 -10
- data/lib/contrast/framework/rails/patch/support.rb +13 -45
- data/lib/contrast/logger/aliased_logging.rb +87 -0
- data/lib/contrast/logger/application.rb +0 -4
- data/lib/contrast/tasks/config.rb +22 -13
- data/lib/contrast/utils/class_util.rb +2 -6
- data/lib/contrast/utils/invalid_configuration_util.rb +1 -1
- data/lib/contrast/utils/log_utils.rb +2 -0
- data/lib/contrast/utils/middleware_utils.rb +1 -1
- data/lib/contrast/utils/object_share.rb +1 -1
- data/lib/contrast/utils/telemetry.rb +20 -2
- data/lib/contrast/utils/telemetry_client.rb +22 -10
- data/lib/contrast/utils/telemetry_hash.rb +41 -0
- data/lib/contrast/utils/telemetry_identifier.rb +16 -1
- data/lib/contrast.rb +9 -0
- data/ruby-agent.gemspec +1 -1
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +39 -16
- data/lib/contrast/agent/telemetry/events/metric_telemetry_event.rb +0 -26
- data/lib/contrast/agent/telemetry/events/startup_metrics_telemetry_event.rb +0 -121
- data/lib/contrast/agent/telemetry/events/telemetry_event.rb +0 -33
- data/lib/contrast/agent/telemetry/telemetry.rb +0 -150
- data/lib/contrast/utils/exclude_key.rb +0 -20
@@ -3,94 +3,112 @@
|
|
3
3
|
|
4
4
|
require_relative 'telemetry_exception_base'
|
5
5
|
require_relative 'telemetry_exception_message_exception'
|
6
|
+
require 'contrast/utils/telemetry_identifier'
|
6
7
|
|
7
8
|
module Contrast
|
8
9
|
module Agent
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
10
|
+
module Telemetry
|
11
|
+
module TelemetryException
|
12
|
+
# This class will hold the all the information for the specific exceptions
|
13
|
+
# and will be passed in the the event to be sent to TS
|
14
|
+
class Message < Contrast::Agent::Telemetry::TelemetryException::Base
|
15
|
+
VALIDATIONS = {
|
16
|
+
instance: { required: true, range: 12..64 },
|
17
|
+
tags: { required: true, range: 0..512 },
|
18
|
+
logger: { required: false, range: 1..128 },
|
19
|
+
message: { required: false, range: 1..512 },
|
20
|
+
exceptions: {
|
21
|
+
required: true,
|
22
|
+
range: 1..512,
|
23
|
+
class: Contrast::Agent::Telemetry::TelemetryException::MessageException
|
24
|
+
}
|
25
|
+
}.cs__freeze
|
19
26
|
|
20
|
-
|
21
|
-
|
22
|
-
|
27
|
+
# Timestamp of creation in ISO8601 format
|
28
|
+
# @return [Integer]
|
29
|
+
attr_reader :timestamp
|
23
30
|
|
24
|
-
|
25
|
-
|
26
|
-
|
31
|
+
# An Instance ID as defined in Unique Identification // Application ID
|
32
|
+
# @return [String]
|
33
|
+
attr_reader :instance
|
27
34
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
35
|
+
# Tags are key-value string pairs that annotate either metrics
|
36
|
+
# or errors to help provide context, filtering, grouping, and deduplication.
|
37
|
+
# @return [Hash{String => String}]
|
38
|
+
attr_reader :tags
|
32
39
|
|
33
|
-
|
34
|
-
|
40
|
+
# @return [Integer] A number of the occurrences of the exception
|
41
|
+
attr_accessor :occurrences
|
35
42
|
|
36
|
-
|
37
|
-
|
38
|
-
|
43
|
+
# Array of exceptions, but in our case the Array will only include one exception
|
44
|
+
# @return [Array<Contrast::Agent::Telemetry::TelemetryException::MessageException>]
|
45
|
+
attr_reader :exceptions
|
39
46
|
|
40
|
-
|
41
|
-
|
47
|
+
# @return [String,nil] A string denoting the origin of this error.
|
48
|
+
attr_reader :logger
|
42
49
|
|
43
|
-
|
44
|
-
|
50
|
+
# @return [String | nil] A string message to provide additional context to the errors.
|
51
|
+
attr_reader :message
|
45
52
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
53
|
+
def initialize instance, tags, exceptions
|
54
|
+
super()
|
55
|
+
@tags = tags
|
56
|
+
@timestamp = Time.now.iso8601
|
57
|
+
@instance = instance
|
58
|
+
@occurrences = 1
|
59
|
+
@exceptions = exceptions
|
60
|
+
validate(VALIDATIONS)
|
61
|
+
end
|
55
62
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
+
# Optional parameters will be set separately from the required
|
64
|
+
#
|
65
|
+
# @param logger[String]
|
66
|
+
def logger= logger
|
67
|
+
validate_field(VALIDATIONS[:logger], 'logger')
|
68
|
+
@logger = logger
|
69
|
+
end
|
63
70
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
+
# Optional parameters will be set separately from the required
|
72
|
+
#
|
73
|
+
# @param message[String]
|
74
|
+
def message= message
|
75
|
+
validate_field(VALIDATIONS[:message], 'message')
|
76
|
+
@message = message
|
77
|
+
end
|
71
78
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
79
|
+
# Optional parameters will be set separately from the required
|
80
|
+
# This method is different and is regarding the way we proceed
|
81
|
+
# with incrementing occurrences
|
82
|
+
# If we keep track of them in different places and we store that value
|
83
|
+
# in separated variable - we may directly re-assign occurrences=
|
84
|
+
# But if we are not doing that - we may on same message generated
|
85
|
+
# to increment occurrences from here
|
86
|
+
def increment_occurrences
|
87
|
+
@occurrences += 1
|
88
|
+
end
|
89
|
+
|
90
|
+
def to_controlled_hash
|
91
|
+
super()
|
92
|
+
{
|
93
|
+
timestamp: timestamp,
|
94
|
+
instance: instance,
|
95
|
+
occurrences: occurrences,
|
96
|
+
tags: tags,
|
97
|
+
exceptions: exceptions.map(&:to_controlled_hash),
|
98
|
+
logger: logger,
|
99
|
+
message: message
|
100
|
+
}.compact
|
101
|
+
end
|
82
102
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
message: message
|
93
|
-
}.compact
|
103
|
+
class << self
|
104
|
+
def build tags, exceptions, logger = nil, message = nil
|
105
|
+
inst = new(Contrast::Utils::Telemetry::Identifier.instance_id, tags, exceptions)
|
106
|
+
inst.logger = logger unless logger.nil?
|
107
|
+
inst.message = message unless message.nil?
|
108
|
+
inst
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
94
112
|
end
|
95
113
|
end
|
96
114
|
end
|
data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message_exception.rb
CHANGED
@@ -6,59 +6,77 @@ require_relative 'telemetry_exception_stack_frame'
|
|
6
6
|
|
7
7
|
module Contrast
|
8
8
|
module Agent
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
9
|
+
module Telemetry
|
10
|
+
module TelemetryException
|
11
|
+
# This class will hold the all the information for the specific exception
|
12
|
+
# and will be passed in the Exception message itself
|
13
|
+
class MessageException < Contrast::Agent::Telemetry::TelemetryException::Base
|
14
|
+
VALIDATIONS = {
|
15
|
+
type: { required: true, range: 1..256 },
|
16
|
+
module_name: { required: false, range: 1..256 },
|
17
|
+
value: { required: false, range: 1..256 },
|
18
|
+
stack_frames: {
|
19
|
+
required: true,
|
20
|
+
range: 1..128,
|
21
|
+
class: Contrast::Agent::Telemetry::TelemetryException::StackFrame
|
22
|
+
}
|
23
|
+
}.cs__freeze
|
18
24
|
|
19
|
-
|
20
|
-
|
25
|
+
# @return [String] The type of the exception itself
|
26
|
+
attr_reader :type
|
21
27
|
|
22
|
-
|
23
|
-
|
28
|
+
# stack frames for the message exception
|
29
|
+
# @return [Array<Contrast::Agent::Telemetry::TelemetryException::StackFrame>]
|
30
|
+
attr_reader :stack_frames
|
24
31
|
|
25
|
-
|
26
|
-
|
32
|
+
# @return [String]
|
33
|
+
attr_reader :module_name
|
27
34
|
|
28
|
-
|
29
|
-
|
35
|
+
# @return [String]
|
36
|
+
attr_reader :value
|
30
37
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
38
|
+
def initialize type, stack_frame
|
39
|
+
super()
|
40
|
+
@type = type
|
41
|
+
@stack_frames = Array.new(1, stack_frame)
|
42
|
+
validate VALIDATIONS
|
43
|
+
end
|
37
44
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
45
|
+
# @param stack_frame [Contrast::Agent::Telemetry::TelemetryException::StackFrame]
|
46
|
+
def push stack_frame
|
47
|
+
validate_class(stack_frame, Contrast::Agent::Telemetry::TelemetryException::StackFrame, 'stack_frame')
|
48
|
+
@stack_frames << stack_frame
|
49
|
+
end
|
43
50
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
51
|
+
def module_name= module_name
|
52
|
+
@module_name = module_name
|
53
|
+
validate_field(VALIDATIONS[:module_name], 'module_name')
|
54
|
+
end
|
48
55
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
56
|
+
def value= value
|
57
|
+
@value = value
|
58
|
+
validate_field(VALIDATIONS[:value], 'value')
|
59
|
+
end
|
60
|
+
|
61
|
+
def to_controlled_hash
|
62
|
+
super
|
63
|
+
{
|
64
|
+
type: type,
|
65
|
+
module: module_name,
|
66
|
+
stackFrames: stack_frames.map(&:to_controlled_hash),
|
67
|
+
value: value
|
68
|
+
}.compact
|
69
|
+
end
|
53
70
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
71
|
+
class << self
|
72
|
+
def build type, value, module_name, stackframes
|
73
|
+
inst = new(type, stackframes)
|
74
|
+
inst.module_name = module_name if module_name
|
75
|
+
inst.value = value
|
76
|
+
inst
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
62
80
|
end
|
63
81
|
end
|
64
82
|
end
|
@@ -5,42 +5,59 @@ require_relative 'telemetry_exception_base'
|
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Agent
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
attr_reader :type
|
19
|
-
|
20
|
-
# @return [String] the function of the stack trace
|
21
|
-
attr_reader :function
|
22
|
-
|
23
|
-
# @return [Boolean] Is it in contrast
|
24
|
-
attr_accessor :in_contrast
|
25
|
-
|
26
|
-
def initialize function, type
|
27
|
-
super()
|
28
|
-
@function = function
|
29
|
-
@type = type
|
30
|
-
@in_contrast = false
|
31
|
-
validate VALIDATIONS
|
32
|
-
end
|
8
|
+
module Telemetry
|
9
|
+
module TelemetryException
|
10
|
+
# This class will hold the all the information for the specific exception
|
11
|
+
# and will be passed in the Exception message itself
|
12
|
+
class StackFrame < Contrast::Agent::Telemetry::TelemetryException::Base
|
13
|
+
VALIDATIONS = {
|
14
|
+
function: { required: true, range: 1..256 },
|
15
|
+
type: { required: true, range: 1..256 },
|
16
|
+
module_name: { required: false, range: 1..256 }
|
17
|
+
}.cs__freeze
|
33
18
|
|
34
|
-
|
19
|
+
# @return [String] The type of the exception itself
|
20
|
+
attr_reader :type
|
35
21
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
22
|
+
# @return [String] the function of the stack trace
|
23
|
+
attr_reader :function
|
24
|
+
|
25
|
+
# @return [Boolean] Is it in contrast
|
26
|
+
attr_accessor :in_contrast
|
27
|
+
|
28
|
+
# @return [String]
|
29
|
+
attr_reader :module_name
|
30
|
+
|
31
|
+
def initialize function, type
|
32
|
+
super()
|
33
|
+
@function = function
|
34
|
+
@type = type
|
35
|
+
@in_contrast = false
|
36
|
+
validate VALIDATIONS
|
37
|
+
end
|
38
|
+
|
39
|
+
def module_name= module_name
|
40
|
+
@module_name = module_name
|
41
|
+
validate_field(VALIDATIONS[:module_name], 'module_name')
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_controlled_hash
|
45
|
+
super
|
46
|
+
{ function: function, type: type, module: module_name, inContrast: in_contrast }.compact
|
47
|
+
end
|
40
48
|
|
41
|
-
|
42
|
-
|
43
|
-
|
49
|
+
class << self
|
50
|
+
# @param method [String] method, triggered the logger on warn/error/fatal
|
51
|
+
# @param type [String] the type ( where it occurred )
|
52
|
+
# @param module_name [String, nil] Name of the module if any.
|
53
|
+
def build method, type, module_name = nil
|
54
|
+
inst = new(method, type)
|
55
|
+
inst.module_name = module_name if module_name
|
56
|
+
inst.in_contrast = type.include?('lib/contrast')
|
57
|
+
inst
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
44
61
|
end
|
45
62
|
end
|
46
63
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Contrast
|
5
|
+
module Agent
|
6
|
+
module Telemetry
|
7
|
+
# This is the module that will include every information created and stored for the
|
8
|
+
# Telemetry Exceptions
|
9
|
+
module TelemetryException
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
require 'contrast/agent/telemetry/events/exceptions/telemetry_exception_base'
|
16
|
+
require 'contrast/agent/telemetry/events/exceptions/telemetry_exception_stack_frame'
|
17
|
+
require 'contrast/agent/telemetry/events/exceptions/telemetry_exception_message_exception'
|
18
|
+
require 'contrast/agent/telemetry/events/exceptions/telemetry_exception_message'
|
19
|
+
require 'contrast/agent/telemetry/events/exceptions/telemetry_exception_event'
|
20
|
+
require 'contrast/agent/telemetry/events/exceptions/telemetry_exceptions_report'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
module Contrast
|
5
|
+
module Agent
|
6
|
+
module Telemetry
|
7
|
+
# This module will handle the reporting of the TelemetryExceptionHash
|
8
|
+
module TelemetryExceptionReport
|
9
|
+
class << self
|
10
|
+
# Here we will send any exceptions gathered. The telemetry_hash is split into batches of 256
|
11
|
+
# and then added to the telemetry queue. Since this method is called before entering the
|
12
|
+
# until queue loop any updates after clearing the Contrast::TELEMETRY_EXCEPTIONS would have
|
13
|
+
# to wait for the sending process to be completed, so accumulating new batches.
|
14
|
+
# This methods expects queue and error_messages methods from Contrast::Agent::Telemetry::Base
|
15
|
+
def push_exceptions
|
16
|
+
return unless Contrast::TELEMETRY_EXCEPTIONS&.any?
|
17
|
+
|
18
|
+
Contrast::TELEMETRY_EXCEPTIONS.values.each_slice(256) { |tuple| error_messages.push tuple }
|
19
|
+
# Clear the hash. All exceptions now live in @_error_messages instance variable. and we will
|
20
|
+
# add them to the queue. Clearing would make the hash available to be populated again while the
|
21
|
+
# sending is proceeding.
|
22
|
+
Contrast::TELEMETRY_EXCEPTIONS.clear
|
23
|
+
# Add batch to queue. We need to shift here, because we want to report from the oldest batch to
|
24
|
+
# the newest. And even if somehow the array is filled during sending the new messages would stay
|
25
|
+
# and wait their turn.
|
26
|
+
queue << error_messages.shift until error_messages.empty?
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'contrast/utils/metrics_hash'
|
5
|
+
require 'contrast/agent/telemetry/events/event'
|
6
|
+
|
7
|
+
module Contrast
|
8
|
+
module Agent
|
9
|
+
module Telemetry
|
10
|
+
# This class will hold the basic information for a Telemetry Event
|
11
|
+
class MetricEvent < Contrast::Agent::Telemetry::Event
|
12
|
+
include Contrast::Utils
|
13
|
+
|
14
|
+
attr_reader :fields
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
super
|
18
|
+
@fields = MetricsHash.new(Numeric)
|
19
|
+
@fields['_filler'] = 0
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_hash **_args
|
23
|
+
super.merge!({ fields: @fields })
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'contrast/utils/metrics_hash'
|
5
|
+
require 'contrast/agent/telemetry/events/metric_event'
|
6
|
+
require 'contrast/agent/version'
|
7
|
+
require 'contrast/utils/os'
|
8
|
+
|
9
|
+
module Contrast
|
10
|
+
module Agent
|
11
|
+
module Telemetry
|
12
|
+
# This class will hold the Startup Metrics Telemetry Event
|
13
|
+
# The class will include initialization of the agent version, language version
|
14
|
+
# os type, arch and version
|
15
|
+
# application framework and version and server framework
|
16
|
+
# It will be initialized and send in Middleware#agent_startup_routine
|
17
|
+
class StartupMetricsEvent < Contrast::Agent::Telemetry::MetricEvent
|
18
|
+
include Contrast::Utils::OS
|
19
|
+
|
20
|
+
APP_AND_SERVER_DATA = ::Contrast::APP_CONTEXT.app_and_server_information.cs__freeze
|
21
|
+
# Multi-tenant Production Environments
|
22
|
+
SAAS_DEFAULT = { addr: 'app.contrastsecurity.com', type: 'SAAS_DEFAULT' }.cs__freeze
|
23
|
+
SAAS_CS = { addr: /cs[[:digit:]]+\.contrastsecurity\.com/, type: 'SAAS_DEFAULT' }.cs__freeze
|
24
|
+
SAAS_JP = { addr: 'app.contrastsecurity.jp', type: 'SAAS_DEFAULT' }.cs__freeze
|
25
|
+
SAAS_CE = { addr: 'ce.contrastsecurity.com', type: 'SAAS_CE' }.cs__freeze
|
26
|
+
# Multi-tenant Demo Environments
|
27
|
+
SAAS_DEMO = { addr: 'apptwo.contrastsecurity.com', type: 'SAAS_DEMO' }.cs__freeze
|
28
|
+
SAAS_POV = { addr: 'eval.contrastsecurity.com', type: 'SAAS_POV' }.cs__freeze
|
29
|
+
# Multi-tenant Testing Environment
|
30
|
+
SAAS_RESEARCH = { addr: 'security-research.contrastsecurity.com', type: 'SAAS_RESEARCH' }.cs__freeze
|
31
|
+
SAAS_ALPHA = { addr: 'alpha.contrastsecurity.com', type: 'SAAS_ALPHA' }.cs__freeze
|
32
|
+
SAAS_STAGING = { addr: 'teamserver-staging.contsec.com', type: 'SAAS_TESTING' }.cs__freeze
|
33
|
+
SAAS_STAGING_TOKYO = { addr: 'teamserver-staging.contsec.jp', type: 'SAAS_TESTING' }.cs__freeze
|
34
|
+
SAAS_TESTING = { addr: 'teamserver-darpa.contsec.com', type: 'SAAS_TESTING' }.cs__freeze
|
35
|
+
SAAS_OPS_TESTING = { addr: 'teamserver-ops.contsec.com', type: 'SAAS_TESTING' }.cs__freeze
|
36
|
+
# Fallback for Single-tenant Production Environments
|
37
|
+
SAAS_CUSTOM = { addr: 'contrastsecurity.com', type: 'SAAS_CUSTOM' }.cs__freeze
|
38
|
+
SAAS_CUSTOM_JP = { addr: 'contrastsecurity.jp', type: 'SAAS_CUSTOM' }.cs__freeze
|
39
|
+
|
40
|
+
SINGLE_MAP_TENANTS = [
|
41
|
+
SAAS_DEFAULT, SAAS_JP, SAAS_CE, SAAS_DEMO, SAAS_POV, SAAS_RESEARCH, SAAS_ALPHA,
|
42
|
+
SAAS_STAGING, SAAS_STAGING_TOKYO, SAAS_TESTING, SAAS_OPS_TESTING
|
43
|
+
].cs__freeze
|
44
|
+
REGEXP_MAP_TENANTS = [SAAS_CS].cs__freeze
|
45
|
+
FALLBACK_TENANTS = [SAAS_CUSTOM, SAAS_CUSTOM_JP].cs__freeze
|
46
|
+
# Fallback for Custom, most likely self-hosted, Environments
|
47
|
+
EOP = 'EOP'
|
48
|
+
REJECTED_VALUES = [nil, 'NEEDS_TO_BE_SET', Contrast::Utils::ObjectShare::EMPTY_STRING].cs__freeze
|
49
|
+
|
50
|
+
def initialize
|
51
|
+
super
|
52
|
+
@settings = []
|
53
|
+
add_config_keys ::Contrast::CONFIG.root, 'root'
|
54
|
+
@settings << ENV.keys.select { |v| v.starts_with?('CONTRAST') }
|
55
|
+
@settings.flatten
|
56
|
+
add_tags
|
57
|
+
end
|
58
|
+
|
59
|
+
def path
|
60
|
+
'/startup'
|
61
|
+
end
|
62
|
+
|
63
|
+
def add_tags
|
64
|
+
add_system_tags
|
65
|
+
@tags['app_framework_and_version'] = APP_AND_SERVER_DATA[:application_info].to_s
|
66
|
+
@tags['server_framework_and_version'] = APP_AND_SERVER_DATA[:server_info].to_s
|
67
|
+
@tags['ASSESS'] = Contrast::ASSESS.enabled?.to_s
|
68
|
+
@tags['PROTECT'] = Contrast::PROTECT.enabled?.to_s
|
69
|
+
@tags['settings'] = @settings.join(',')
|
70
|
+
end
|
71
|
+
|
72
|
+
def add_config_keys config, nested_key
|
73
|
+
config.to_hash.reject! { |_k, v| REJECTED_VALUES.include?(v) }
|
74
|
+
|
75
|
+
config.to_hash.each do |k, v|
|
76
|
+
unless v.cs__class <= Contrast::Config::BaseConfiguration
|
77
|
+
@settings << "#{ nested_key }.#{ k }"
|
78
|
+
next
|
79
|
+
end
|
80
|
+
|
81
|
+
add_config_keys v, "#{ nested_key }.#{ k }"
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def sys_info
|
86
|
+
@sys_info ||= get_system_information if @sys_info.nil?
|
87
|
+
@sys_info
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
# Here we extract the TeamServer url type
|
93
|
+
#
|
94
|
+
# @return [String] the type of TeamServer environment to which we're connecting
|
95
|
+
def teamserver_type
|
96
|
+
@_teamserver_type ||= begin
|
97
|
+
url = Contrast::API.api_url
|
98
|
+
if (single = SINGLE_MAP_TENANTS.find { |tenant| url.include?(tenant[:addr]) })
|
99
|
+
single[:type]
|
100
|
+
elsif (regexp = REGEXP_MAP_TENANTS.find { |tenant| tenant[:addr].match?(url) })
|
101
|
+
regexp[:type]
|
102
|
+
elsif (fallback = FALLBACK_TENANTS.find { |tenant| url.include?(tenant[:addr]) })
|
103
|
+
fallback[:type]
|
104
|
+
else
|
105
|
+
EOP
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
# Here we attach the key-value pairs of the system
|
111
|
+
#
|
112
|
+
def add_system_tags
|
113
|
+
@tags['teamserver'] = teamserver_type
|
114
|
+
@tags['agent_version'] = VERSION
|
115
|
+
@tags['ruby_version'] = RUBY_VERSION
|
116
|
+
@tags['os_type'] = sys_info['os_type'] == 'Darwin' ? 'MacOS' : 'Linux'
|
117
|
+
@tags['os_arch'] = sys_info['os_arch']
|
118
|
+
@tags['os_version'] = sys_info['os_version']
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|