contrast-agent 6.7.0 → 6.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -2
- data/.simplecov +0 -1
- data/Rakefile +0 -1
- data/ext/cs__assess_array/cs__assess_array.c +41 -10
- data/ext/cs__assess_array/cs__assess_array.h +4 -1
- data/lib/contrast/agent/assess/policy/trigger_method.rb +2 -2
- data/lib/contrast/agent/assess/policy/trigger_validation/redos_validator.rb +1 -1
- data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +1 -1
- data/lib/contrast/agent/assess/policy/trigger_validation/xss_validator.rb +1 -1
- data/lib/contrast/agent/excluder.rb +52 -34
- data/lib/contrast/agent/exclusion_matcher.rb +21 -9
- data/lib/contrast/agent/middleware.rb +4 -4
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +6 -0
- data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +146 -127
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +20 -0
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +1 -1
- data/lib/contrast/agent/protect/rule/base.rb +45 -53
- data/lib/contrast/agent/protect/rule/base_service.rb +48 -24
- data/lib/contrast/agent/protect/rule/bot_blocker/bot_blocker_input_classification.rb +98 -0
- data/lib/contrast/agent/protect/rule/bot_blocker.rb +81 -0
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +18 -1
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_backdoors.rb +8 -5
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_base_rule.rb +22 -22
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_chained_command.rb +69 -0
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_dangerous_path.rb +68 -0
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_input_classification.rb +2 -58
- data/lib/contrast/agent/protect/rule/default_scanner.rb +1 -1
- data/lib/contrast/agent/protect/rule/deserialization.rb +3 -14
- data/lib/contrast/agent/protect/rule/http_method_tampering/http_method_tampering_input_classification.rb +2 -2
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +0 -11
- data/lib/contrast/agent/protect/rule/no_sqli/no_sqli_input_classification.rb +29 -34
- data/lib/contrast/agent/protect/rule/no_sqli.rb +25 -18
- data/lib/contrast/agent/protect/rule/path_traversal/path_traversal_input_classification.rb +61 -0
- data/lib/contrast/agent/protect/rule/path_traversal/path_traversal_semantic_security_bypass.rb +114 -0
- data/lib/contrast/agent/protect/rule/path_traversal.rb +38 -12
- data/lib/contrast/agent/protect/rule/sql_sample_builder.rb +33 -15
- data/lib/contrast/agent/protect/rule/sqli/sqli_base_rule.rb +0 -14
- data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +2 -62
- data/lib/contrast/agent/protect/rule/sqli.rb +70 -0
- data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_input_classification.rb +39 -63
- data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +6 -33
- data/lib/contrast/agent/protect/rule/xss/reflected_xss_input_classification.rb +58 -0
- data/lib/contrast/agent/protect/rule/xss.rb +14 -20
- data/lib/contrast/agent/protect/rule/xxe.rb +4 -24
- data/lib/contrast/agent/reporting/attack_result/rasp_rule_sample.rb +18 -39
- data/lib/contrast/agent/reporting/attack_result/response_type.rb +9 -9
- data/lib/contrast/agent/reporting/details/ip_denylist_details.rb +10 -2
- data/lib/contrast/agent/reporting/details/virtual_patch_details.rb +8 -2
- data/lib/contrast/agent/reporting/input_analysis/details/bot_blocker_details.rb +27 -0
- data/lib/contrast/agent/reporting/input_analysis/details/protect_rule_details.rb +15 -0
- data/lib/contrast/agent/reporting/input_analysis/input_analysis.rb +1 -2
- data/lib/contrast/agent/reporting/input_analysis/input_analysis_result.rb +16 -2
- data/lib/contrast/agent/reporting/masker/masker.rb +2 -0
- data/lib/contrast/agent/reporting/reporter.rb +1 -14
- data/lib/contrast/agent/reporting/reporting_events/application_activity.rb +15 -12
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_activity.rb +3 -3
- data/lib/contrast/agent/reporting/reporting_events/application_defend_attack_sample.rb +1 -2
- data/lib/contrast/agent/reporting/reporting_events/application_update.rb +0 -2
- data/lib/contrast/agent/reporting/reporting_events/architecture_component.rb +0 -1
- data/lib/contrast/agent/reporting/reporting_events/finding.rb +4 -4
- data/lib/contrast/agent/reporting/reporting_events/finding_request.rb +0 -5
- data/lib/contrast/agent/reporting/reporting_events/library_discovery.rb +0 -1
- data/lib/contrast/agent/reporting/reporting_events/poll.rb +1 -11
- data/lib/contrast/agent/reporting/reporting_events/route_discovery.rb +0 -1
- data/lib/contrast/agent/reporting/reporting_events/route_discovery_observation.rb +0 -1
- data/lib/contrast/agent/reporting/reporting_utilities/audit.rb +2 -2
- data/lib/contrast/agent/reporting/reporting_utilities/response.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +0 -3
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +1 -0
- data/lib/contrast/agent/reporting/settings/code_exclusion.rb +6 -1
- data/lib/contrast/agent/reporting/settings/exclusion_base.rb +18 -0
- data/lib/contrast/agent/reporting/settings/exclusions.rb +2 -1
- data/lib/contrast/agent/reporting/settings/input_exclusion.rb +9 -3
- data/lib/contrast/agent/reporting/settings/protect.rb +15 -15
- data/lib/contrast/agent/request.rb +2 -14
- data/lib/contrast/agent/request_context.rb +6 -9
- data/lib/contrast/agent/request_context_extend.rb +9 -148
- data/lib/contrast/agent/thread_watcher.rb +3 -18
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/agent.rb +0 -11
- data/lib/contrast/agent_lib/api/command_injection.rb +46 -0
- data/lib/contrast/agent_lib/api/init.rb +101 -0
- data/lib/contrast/agent_lib/api/input_tracing.rb +267 -0
- data/lib/contrast/agent_lib/api/method_tempering.rb +29 -0
- data/lib/contrast/agent_lib/api/panic.rb +87 -0
- data/lib/contrast/agent_lib/api/path_semantic_file_security_bypass.rb +40 -0
- data/lib/contrast/agent_lib/interface.rb +260 -0
- data/lib/contrast/agent_lib/interface_base.rb +118 -0
- data/lib/contrast/agent_lib/return_types/eval_result.rb +44 -0
- data/lib/contrast/agent_lib/test.rb +29 -0
- data/lib/contrast/api/communication/connection_status.rb +5 -5
- data/lib/contrast/components/agent.rb +0 -14
- data/lib/contrast/components/app_context.rb +0 -2
- data/lib/contrast/components/app_context_extend.rb +0 -25
- data/lib/contrast/components/config.rb +1 -18
- data/lib/contrast/components/protect.rb +4 -1
- data/lib/contrast/components/ruby_component.rb +1 -1
- data/lib/contrast/components/settings.rb +37 -89
- data/lib/contrast/config/protect_rule_configuration.rb +7 -7
- data/lib/contrast/config/protect_rules_configuration.rb +20 -58
- data/lib/contrast/configuration.rb +1 -10
- data/lib/contrast/extension/assess/array.rb +9 -0
- data/lib/contrast/extension/delegator.rb +2 -0
- data/lib/contrast/framework/manager.rb +3 -1
- data/lib/contrast/framework/rails/railtie.rb +0 -1
- data/lib/contrast/framework/rails/support.rb +0 -1
- data/lib/contrast/tasks/config.rb +1 -8
- data/lib/contrast/utils/duck_utils.rb +1 -0
- data/lib/contrast/utils/input_classification_base.rb +156 -0
- data/lib/contrast/utils/os.rb +0 -20
- data/lib/contrast/utils/response_utils.rb +0 -16
- data/lib/contrast/utils/stack_trace_utils.rb +3 -15
- data/lib/contrast/utils/string_utils.rb +10 -7
- data/lib/contrast.rb +2 -3
- data/resources/protect/policy.json +1 -2
- data/ruby-agent.gemspec +2 -5
- metadata +42 -112
- data/exe/contrast_service +0 -23
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_worth_watching.rb +0 -64
- data/lib/contrast/agent/protect/rule/sqli/sqli_worth_watching.rb +0 -118
- data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_matcher.rb +0 -45
- data/lib/contrast/agent/reaction_processor.rb +0 -47
- data/lib/contrast/agent/service_heartbeat.rb +0 -35
- data/lib/contrast/api/communication/messaging_queue.rb +0 -128
- data/lib/contrast/api/communication/response_processor.rb +0 -90
- data/lib/contrast/api/communication/service_lifecycle.rb +0 -77
- data/lib/contrast/api/communication/socket.rb +0 -44
- data/lib/contrast/api/communication/socket_client.rb +0 -130
- data/lib/contrast/api/communication/speedracer.rb +0 -138
- data/lib/contrast/api/communication/tcp_socket.rb +0 -32
- data/lib/contrast/api/communication/unix_socket.rb +0 -28
- data/lib/contrast/api/communication.rb +0 -20
- data/lib/contrast/api/decorators/address.rb +0 -59
- data/lib/contrast/api/decorators/agent_startup.rb +0 -56
- data/lib/contrast/api/decorators/application_settings.rb +0 -43
- data/lib/contrast/api/decorators/application_startup.rb +0 -56
- data/lib/contrast/api/decorators/bot_blocker.rb +0 -37
- data/lib/contrast/api/decorators/http_request.rb +0 -137
- data/lib/contrast/api/decorators/input_analysis.rb +0 -18
- data/lib/contrast/api/decorators/instrumentation_mode.rb +0 -35
- data/lib/contrast/api/decorators/ip_denylist.rb +0 -37
- data/lib/contrast/api/decorators/message.rb +0 -67
- data/lib/contrast/api/decorators/rasp_rule_sample.rb +0 -52
- data/lib/contrast/api/decorators/response_type.rb +0 -17
- data/lib/contrast/api/decorators/server_features.rb +0 -25
- data/lib/contrast/api/decorators/user_input.rb +0 -51
- data/lib/contrast/api/decorators/virtual_patch.rb +0 -34
- data/lib/contrast/api/decorators.rb +0 -22
- data/lib/contrast/api/dtm.pb.rb +0 -363
- data/lib/contrast/api/settings.pb.rb +0 -500
- data/lib/contrast/api.rb +0 -16
- data/lib/contrast/components/contrast_service.rb +0 -88
- data/lib/contrast/components/service.rb +0 -55
- data/lib/contrast/tasks/service.rb +0 -84
- data/lib/contrast/utils/input_classification.rb +0 -73
- data/lib/protobuf/code_generator.rb +0 -129
- data/lib/protobuf/decoder.rb +0 -28
- data/lib/protobuf/deprecation.rb +0 -117
- data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +0 -79
- data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +0 -360
- data/lib/protobuf/descriptors.rb +0 -3
- data/lib/protobuf/encoder.rb +0 -11
- data/lib/protobuf/enum.rb +0 -365
- data/lib/protobuf/exceptions.rb +0 -9
- data/lib/protobuf/field/base_field.rb +0 -380
- data/lib/protobuf/field/base_field_object_definitions.rb +0 -504
- data/lib/protobuf/field/bool_field.rb +0 -64
- data/lib/protobuf/field/bytes_field.rb +0 -67
- data/lib/protobuf/field/double_field.rb +0 -25
- data/lib/protobuf/field/enum_field.rb +0 -56
- data/lib/protobuf/field/field_array.rb +0 -102
- data/lib/protobuf/field/field_hash.rb +0 -122
- data/lib/protobuf/field/fixed32_field.rb +0 -25
- data/lib/protobuf/field/fixed64_field.rb +0 -28
- data/lib/protobuf/field/float_field.rb +0 -43
- data/lib/protobuf/field/int32_field.rb +0 -21
- data/lib/protobuf/field/int64_field.rb +0 -34
- data/lib/protobuf/field/integer_field.rb +0 -23
- data/lib/protobuf/field/message_field.rb +0 -51
- data/lib/protobuf/field/sfixed32_field.rb +0 -27
- data/lib/protobuf/field/sfixed64_field.rb +0 -28
- data/lib/protobuf/field/signed_integer_field.rb +0 -29
- data/lib/protobuf/field/sint32_field.rb +0 -21
- data/lib/protobuf/field/sint64_field.rb +0 -21
- data/lib/protobuf/field/string_field.rb +0 -51
- data/lib/protobuf/field/uint32_field.rb +0 -21
- data/lib/protobuf/field/uint64_field.rb +0 -21
- data/lib/protobuf/field/varint_field.rb +0 -77
- data/lib/protobuf/field.rb +0 -74
- data/lib/protobuf/generators/base.rb +0 -85
- data/lib/protobuf/generators/enum_generator.rb +0 -39
- data/lib/protobuf/generators/extension_generator.rb +0 -27
- data/lib/protobuf/generators/field_generator.rb +0 -193
- data/lib/protobuf/generators/file_generator.rb +0 -262
- data/lib/protobuf/generators/group_generator.rb +0 -122
- data/lib/protobuf/generators/message_generator.rb +0 -104
- data/lib/protobuf/generators/option_generator.rb +0 -17
- data/lib/protobuf/generators/printable.rb +0 -160
- data/lib/protobuf/generators/service_generator.rb +0 -50
- data/lib/protobuf/lifecycle.rb +0 -33
- data/lib/protobuf/logging.rb +0 -39
- data/lib/protobuf/message/fields.rb +0 -233
- data/lib/protobuf/message/serialization.rb +0 -85
- data/lib/protobuf/message.rb +0 -241
- data/lib/protobuf/optionable.rb +0 -72
- data/lib/protobuf/tasks/compile.rake +0 -80
- data/lib/protobuf/tasks.rb +0 -1
- data/lib/protobuf/varint.rb +0 -20
- data/lib/protobuf/varint_pure.rb +0 -31
- data/lib/protobuf/version.rb +0 -3
- data/lib/protobuf/wire_type.rb +0 -10
- data/lib/protobuf.rb +0 -91
- data/proto/dynamic_discovery.proto +0 -46
- data/proto/google/protobuf/compiler/plugin.proto +0 -183
- data/proto/google/protobuf/descriptor.proto +0 -911
- data/proto/rpc.proto +0 -71
- data/service_executables/.gitkeep +0 -0
- data/service_executables/VERSION +0 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
@@ -10,9 +10,18 @@ module Contrast
|
|
10
10
|
include Contrast::Config::BaseConfiguration
|
11
11
|
|
12
12
|
attr_accessor :disabled_rules
|
13
|
-
|
14
|
-
:
|
15
|
-
:
|
13
|
+
attr_reader :bot_blocker,
|
14
|
+
:cmd_injection, :cmdi_command_backdoors,
|
15
|
+
:cmd_injection_semantic_chained_commands, :cmd_injection_semantic_dangerous_paths,
|
16
|
+
:method_tampering,
|
17
|
+
:nosql_injection,
|
18
|
+
:path_traversal, :path_traversal_semantic_file_security_bypass,
|
19
|
+
:reflected_xss,
|
20
|
+
:sql_injection, :sqli_dangerous_function,
|
21
|
+
:unsafe_file_upload,
|
22
|
+
:untrusted_deserialization,
|
23
|
+
:xxe,
|
24
|
+
:rule_base
|
16
25
|
|
17
26
|
BASE_RULE = 'Contrast::Agent::Protect::Rule::Base'.cs__freeze
|
18
27
|
|
@@ -23,73 +32,26 @@ module Contrast
|
|
23
32
|
@rule_base = Contrast::Config::ProtectRuleConfiguration.new(hsh[BASE_RULE.to_sym])
|
24
33
|
@bot_blocker = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'bot-blocker'])
|
25
34
|
@cmd_injection = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'cmd-injection'])
|
35
|
+
@cmdi_command_backdoors =
|
36
|
+
Contrast::Config::ProtectRuleConfiguration.new(hsh[:'cmd-injection-command-backdoors'])
|
37
|
+
@cmdi_chained_command =
|
38
|
+
Contrast::Config::ProtectRuleConfiguration.new(hsh[:'cmd-injection-semantic-chained-commands'])
|
39
|
+
@cmdi_dangerous_path =
|
40
|
+
Contrast::Config::ProtectRuleConfiguration.new(hsh[:'cmd-injection-semantic-dangerous-paths'])
|
26
41
|
@method_tampering = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'method-tampering'])
|
27
42
|
@nosql_injection = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'nosql-injection'])
|
28
43
|
@path_traversal = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'path-traversal'])
|
44
|
+
@path_traversal_semantic_file_security_bypass =
|
45
|
+
Contrast::Config::ProtectRuleConfiguration.new(hsh[:'path-traversal-semantic-file-security-bypass'])
|
29
46
|
@reflected_xss = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'reflected-xss'])
|
30
47
|
@sql_injection = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'sql-injection'])
|
31
48
|
@sqli_dangerous_function =
|
32
49
|
Contrast::Config::ProtectRuleConfiguration.new(hsh[:'sql-injection-semantic-dangerous-functions'])
|
33
50
|
@unsafe_file_upload = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'unsafe-file-upload'])
|
34
51
|
@untrusted_deserialization = Contrast::Config::ProtectRuleConfiguration.new(hsh[:'untrusted-deserialization'])
|
35
|
-
@cmdi_command_backdoors = Contrast::Config::ProtectRuleConfiguration.new(hsh[
|
36
|
-
:'cmd-injection-command-backdoors'
|
37
|
-
])
|
38
52
|
@xxe = Contrast::Config::ProtectRuleConfiguration.new(hsh[:xxe])
|
39
53
|
end
|
40
54
|
|
41
|
-
def bot_blocker
|
42
|
-
@bot_blocker ||= Contrast::Config::ProtectRuleConfiguration.new
|
43
|
-
end
|
44
|
-
|
45
|
-
def cmd_injection
|
46
|
-
@cmd_injection ||= Contrast::Config::ProtectRuleConfiguration.new
|
47
|
-
end
|
48
|
-
|
49
|
-
def sql_injection
|
50
|
-
@sql_injection ||= Contrast::Config::ProtectRuleConfiguration.new
|
51
|
-
end
|
52
|
-
|
53
|
-
def nosql_injection
|
54
|
-
@nosql_injection ||= Contrast::Config::ProtectRuleConfiguration.new
|
55
|
-
end
|
56
|
-
|
57
|
-
def untrusted_deserialization
|
58
|
-
@untrusted_deserialization ||= Contrast::Config::ProtectRuleConfiguration.new
|
59
|
-
end
|
60
|
-
|
61
|
-
def method_tampering
|
62
|
-
@method_tampering ||= Contrast::Config::ProtectRuleConfiguration.new
|
63
|
-
end
|
64
|
-
|
65
|
-
def xxe
|
66
|
-
@xxe ||= Contrast::Config::ProtectRuleConfiguration.new
|
67
|
-
end
|
68
|
-
|
69
|
-
def path_traversal
|
70
|
-
@path_traversal ||= Contrast::Config::ProtectRuleConfiguration.new
|
71
|
-
end
|
72
|
-
|
73
|
-
def reflected_xss
|
74
|
-
@reflected_xss ||= Contrast::Config::ProtectRuleConfiguration.new
|
75
|
-
end
|
76
|
-
|
77
|
-
def unsafe_file_upload
|
78
|
-
@unsafe_file_upload ||= Contrast::Config::ProtectRuleConfiguration.new
|
79
|
-
end
|
80
|
-
|
81
|
-
def cmdi_command_backdoors
|
82
|
-
@cmdi_command_backdoors ||= Contrast::Config::ProtectRuleConfiguration.new
|
83
|
-
end
|
84
|
-
|
85
|
-
def rule_base
|
86
|
-
@rule_base ||= Contrast::Config::ProtectRuleConfiguration.new
|
87
|
-
end
|
88
|
-
|
89
|
-
def sqli_dangerous_function
|
90
|
-
@sqli_dangerous_function = Contrast::Config::ProtectRuleConfiguration.new
|
91
|
-
end
|
92
|
-
|
93
55
|
def []= key, value
|
94
56
|
instance_variable_set("@#{ convert_key(key) }".to_sym, value)
|
95
57
|
end
|
@@ -13,7 +13,6 @@ require 'contrast/components/scope'
|
|
13
13
|
require 'contrast/components/inventory'
|
14
14
|
require 'contrast/components/protect'
|
15
15
|
require 'contrast/components/assess'
|
16
|
-
require 'contrast/components/service'
|
17
16
|
require 'contrast/config/server_configuration'
|
18
17
|
|
19
18
|
module Contrast
|
@@ -44,14 +43,12 @@ module Contrast
|
|
44
43
|
attr_writer :inventory
|
45
44
|
# @return [Contrast::Components::Protect::Interface]
|
46
45
|
attr_writer :protect
|
47
|
-
# @return [Contrast::Components::Service::Interface]
|
48
|
-
attr_writer :service
|
49
46
|
# @return [Boolean, nil]
|
50
47
|
attr_accessor :enable
|
51
48
|
|
52
49
|
DEFAULT_YAML_PATH = 'contrast_security.yaml'
|
53
50
|
MILLISECOND_MARKER = '_ms'
|
54
|
-
CONVERSION = {
|
51
|
+
CONVERSION = {}.cs__freeze
|
55
52
|
CONFIG_BASE_PATHS = ['', 'config/', '/etc/contrast/ruby/', '/etc/contrast/', '/etc/'].cs__freeze
|
56
53
|
KEYS_TO_REDACT = %i[api_key url service_key user_name].cs__freeze
|
57
54
|
REDACTED = '**REDACTED**'
|
@@ -77,7 +74,6 @@ module Contrast
|
|
77
74
|
@assess = Contrast::Components::Assess::Interface.new(config_kv[:assess])
|
78
75
|
@inventory = Contrast::Components::Inventory::Interface.new(config_kv[:inventory])
|
79
76
|
@protect = Contrast::Components::Protect::Interface.new(config_kv[:protect])
|
80
|
-
@service = Contrast::Components::Service::Interface.new(config_kv[:service])
|
81
77
|
end
|
82
78
|
|
83
79
|
# Get a loggable YAML format of this configuration
|
@@ -122,11 +118,6 @@ module Contrast
|
|
122
118
|
@protect ||= Contrast::Components::Protect::Interface.new # rubocop:disable Naming/MemoizedInstanceVariableName
|
123
119
|
end
|
124
120
|
|
125
|
-
# @return [Contrast::Components::Service::Interface]
|
126
|
-
def service
|
127
|
-
@service ||= Contrast::Components::Service::Interface.new # rubocop:disable Naming/MemoizedInstanceVariableName
|
128
|
-
end
|
129
|
-
|
130
121
|
protected
|
131
122
|
|
132
123
|
# TODO: RUBY-546 move utility methods to auxiliary classes
|
@@ -5,6 +5,7 @@ require 'contrast/agent/patching/policy/patch'
|
|
5
5
|
require 'contrast/agent/patching/policy/patcher'
|
6
6
|
require 'contrast/components/scope'
|
7
7
|
require 'contrast/agent/assess/events/event_data'
|
8
|
+
require 'cs__assess_array/cs__assess_array'
|
8
9
|
|
9
10
|
module Contrast
|
10
11
|
module Extension
|
@@ -61,6 +62,14 @@ module Contrast
|
|
61
62
|
end
|
62
63
|
end
|
63
64
|
end
|
65
|
+
|
66
|
+
# Helper module to call cs__join
|
67
|
+
module ContrastArray
|
68
|
+
def join *args
|
69
|
+
cs__join(*args)
|
70
|
+
super(*args)
|
71
|
+
end
|
72
|
+
end
|
64
73
|
end
|
65
74
|
end
|
66
75
|
end
|
@@ -1,6 +1,8 @@
|
|
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 'delegate'
|
5
|
+
|
4
6
|
# Some developers override various methods on Delegator, which can often
|
5
7
|
# involve changing expected method parity/behavior which in turn prevents us
|
6
8
|
# from being able to reliably use affected methods. Let's alias these methods
|
@@ -71,9 +71,11 @@ module Contrast
|
|
71
71
|
first_framework_result(:application_name, 'root')
|
72
72
|
end
|
73
73
|
|
74
|
+
# @return app_root [String] path
|
74
75
|
def app_root
|
75
76
|
found = first_framework_result(:application_root, nil)
|
76
|
-
found
|
77
|
+
found ||= ::Rack::Directory.new('').root
|
78
|
+
found.to_s
|
77
79
|
end
|
78
80
|
|
79
81
|
# Build a request from the provided env, based on the framework(s) we're currently supporting.
|
@@ -1,7 +1,6 @@
|
|
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/api/dtm.pb'
|
5
4
|
require 'contrast/framework/base_support'
|
6
5
|
require 'contrast/framework/rails/patch/support'
|
7
6
|
require 'contrast/utils/string_utils'
|
@@ -7,7 +7,7 @@ require 'contrast/agent/reporting/reporter'
|
|
7
7
|
|
8
8
|
module Contrast
|
9
9
|
# A Rake task to generate a contrast_security.yaml file with some basic settings
|
10
|
-
module Config
|
10
|
+
module Config
|
11
11
|
extend Rake::DSL
|
12
12
|
DEFAULT_CONFIG = {
|
13
13
|
'api' => {
|
@@ -17,13 +17,6 @@ module Contrast
|
|
17
17
|
'user_name' => 'Enter your Contrast user name'
|
18
18
|
},
|
19
19
|
'agent' => {
|
20
|
-
'service' => {
|
21
|
-
'logger' => {
|
22
|
-
'path' => 'contrast_service.log',
|
23
|
-
'level' => 'ERROR' # DEBUG | INFO | WARN | ERROR
|
24
|
-
},
|
25
|
-
'socket' => '/tmp/contrast_service.sock'
|
26
|
-
},
|
27
20
|
'logger' => {
|
28
21
|
'level' => 'ERROR',
|
29
22
|
'path' => 'contrast_agent.log'
|
@@ -0,0 +1,156 @@
|
|
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/object_share'
|
5
|
+
require 'contrast/agent/reporting/input_analysis/input_type'
|
6
|
+
require 'contrast/agent/reporting/input_analysis/score_level'
|
7
|
+
require 'contrast/agent/protect/input_analyzer/input_analyzer'
|
8
|
+
require 'contrast/components/logger'
|
9
|
+
|
10
|
+
module Contrast
|
11
|
+
module Agent
|
12
|
+
module Protect
|
13
|
+
module Rule
|
14
|
+
# This module will include all the similar information for all input classifications
|
15
|
+
# between different rules
|
16
|
+
module InputClassificationBase
|
17
|
+
UNKNOWN_KEY = 'unknown'
|
18
|
+
THRESHOLD = 90.cs__freeze
|
19
|
+
WORTHWATCHING_THRESHOLD = 10.cs__freeze
|
20
|
+
include Contrast::Agent::Reporting::InputType
|
21
|
+
include Contrast::Agent::Reporting::ScoreLevel
|
22
|
+
include Contrast::Components::Logger::InstanceMethods
|
23
|
+
|
24
|
+
KEYS_NEEDED = [COOKIE_VALUE, PARAMETER_VALUE, JSON_VALUE, MULTIPART_VALUE, XML_VALUE, DWR_VALUE].cs__freeze
|
25
|
+
|
26
|
+
# Input Classification stage is done to determine if an user input is
|
27
|
+
# DEFINITEATTACK or to be ignored.
|
28
|
+
#
|
29
|
+
# @param rule_id [String] Name of the protect rule.
|
30
|
+
# @param input_type [Symbol, Contrast::Agent::Reporting::InputType] The type of the user input.
|
31
|
+
# @param value [String, Array<String>] the value of the input.
|
32
|
+
# @param input_analysis [Contrast::Agent::Reporting::InputAnalysis] Holds all the results from the
|
33
|
+
# agent analysis from the current
|
34
|
+
# Request.
|
35
|
+
# @return ia [Contrast::Agent::Reporting::InputAnalysis, nil] with updated results.
|
36
|
+
def classify rule_id, input_type, value, input_analysis
|
37
|
+
return unless (rule = Contrast::PROTECT.rule(rule_id))
|
38
|
+
return unless rule.applicable_user_inputs.include?(input_type)
|
39
|
+
return unless input_analysis.request
|
40
|
+
|
41
|
+
Array(value).each do |val|
|
42
|
+
Array(val).each do |v|
|
43
|
+
next unless v
|
44
|
+
|
45
|
+
result = create_new_input_result(input_analysis.request, rule.rule_name, input_type, v)
|
46
|
+
input_analysis.results << result unless result.nil?
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
input_analysis
|
51
|
+
rescue StandardError => e
|
52
|
+
logger.debug("An Error was recorded in the input classification of the #{ rule_id }")
|
53
|
+
logger.debug(e)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Creates new isntance of InputAnalysisResult with basic info.
|
57
|
+
#
|
58
|
+
# @param rule_id [String] The name of the Protect Rule.
|
59
|
+
# @param input_type [Contrast::Agent::Reporting::InputType] The type of the user input.
|
60
|
+
# @param value [String, Array<String>] the value of the input.
|
61
|
+
# @param path [String] the path of the current request context.
|
62
|
+
#
|
63
|
+
# @return res [Contrast::Agent::Reporting::InputAnalysisResult]
|
64
|
+
def new_ia_result rule_id, input_type, path, value = nil
|
65
|
+
res = Contrast::Agent::Reporting::InputAnalysisResult.new
|
66
|
+
res.rule_id = rule_id
|
67
|
+
res.input_type = input_type
|
68
|
+
res.path = path
|
69
|
+
res.value = value
|
70
|
+
res
|
71
|
+
end
|
72
|
+
|
73
|
+
# This methods checks if input is value that matches a key in the input.
|
74
|
+
#
|
75
|
+
# @param request [Contrast::Agent::Request] the current request context.
|
76
|
+
# @param result [Contrast::Agent::Reporting::InputAnalysisResult] result to be updated.
|
77
|
+
# @param input_type [Contrast::Agent::Reporting::InputType] The type of the user input.
|
78
|
+
# @param value [String, Array<String>] the value of the input.
|
79
|
+
#
|
80
|
+
# @return result [Contrast::Agent::Reporting::InputAnalysisResult] updated with key result.
|
81
|
+
def add_needed_key request, result, input_type, value
|
82
|
+
case input_type
|
83
|
+
when COOKIE_VALUE
|
84
|
+
result.key = request.cookies.key(value)
|
85
|
+
when PARAMETER_VALUE, URL_PARAMETER
|
86
|
+
result.key = request.parameters.key(value)
|
87
|
+
when HEADER
|
88
|
+
result.key = request.headers.key(value)
|
89
|
+
when UNKNOWN
|
90
|
+
result.key = UNKNOWN_KEY
|
91
|
+
else
|
92
|
+
result.key
|
93
|
+
end
|
94
|
+
rescue StandardError => e
|
95
|
+
logger.warn('Could not find proper key for input traced value', message: e)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Some input types are not yet supported from the AgentLib.
|
99
|
+
# This will convert the type to the closet possible if viable,
|
100
|
+
# so that the input tracing could be done.
|
101
|
+
#
|
102
|
+
# @param input_type [Contrast::Agent::Reporting::InputType] The type of the user input.
|
103
|
+
# @return [Integer<Contrast::AgentLib::Interface::INPUT_SET>]
|
104
|
+
def convert_input_type input_type
|
105
|
+
case input_type
|
106
|
+
when BODY, DWR_VALUE
|
107
|
+
Contrast::AGENT_LIB.input_set[:PARAMETER_VALUE]
|
108
|
+
when HEADER
|
109
|
+
Contrast::AGENT_LIB.input_set[:HEADER_VALUE]
|
110
|
+
when MULTIPART_VALUE, MULTIPART_FIELD_NAME
|
111
|
+
Contrast::AGENT_LIB.input_set[:MULTIPART_NAME]
|
112
|
+
else
|
113
|
+
Contrast::AGENT_LIB.input_set[input_type]
|
114
|
+
end
|
115
|
+
rescue StandardError
|
116
|
+
Contrast::AGENT_LIB.input_set[:PARAMETER_VALUE]
|
117
|
+
end
|
118
|
+
|
119
|
+
private
|
120
|
+
|
121
|
+
# This methods checks if input is tagged WORTHWATCHING or IGNORE matches value with it's
|
122
|
+
# key if needed and Creates new instance of InputAnalysisResult.
|
123
|
+
#
|
124
|
+
# @param request [Contrast::Agent::Request] the current request context.
|
125
|
+
# @param rule_id [String] The name of the Protect Rule.
|
126
|
+
# @param input_type [Contrast::Agent::Reporting::InputType] The type of the user input.
|
127
|
+
# @param value [String, Array<String>] the value of the input.
|
128
|
+
#
|
129
|
+
# @return res [Contrast::Agent::Reporting::InputAnalysisResult, nil]
|
130
|
+
def create_new_input_result request, rule_id, input_type, value
|
131
|
+
return unless Contrast::AGENT_LIB
|
132
|
+
|
133
|
+
input_eval = Contrast::AGENT_LIB.eval_input(value,
|
134
|
+
convert_input_type(input_type),
|
135
|
+
Contrast::AGENT_LIB.rule_set[rule_id],
|
136
|
+
Contrast::AGENT_LIB.
|
137
|
+
eval_option[:WORTHWATCHING])
|
138
|
+
|
139
|
+
ia_result = new_ia_result(rule_id, input_type, request.path, value)
|
140
|
+
score = input_eval&.score || 0
|
141
|
+
if score >= WORTHWATCHING_THRESHOLD
|
142
|
+
ia_result.score_level = WORTHWATCHING
|
143
|
+
ia_result.ids << self::WORTHWATCHING_MATCH
|
144
|
+
else
|
145
|
+
ia_result.score_level = IGNORE
|
146
|
+
return
|
147
|
+
end
|
148
|
+
|
149
|
+
add_needed_key(request, ia_result, input_type, value) if KEYS_NEEDED.include?(input_type)
|
150
|
+
ia_result
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
data/lib/contrast/utils/os.rb
CHANGED
@@ -13,26 +13,6 @@ module Contrast
|
|
13
13
|
extend Contrast::Components::Scope::InstanceMethods
|
14
14
|
|
15
15
|
class << self
|
16
|
-
def running?
|
17
|
-
result = false
|
18
|
-
with_contrast_scope do
|
19
|
-
process = `ps aux | grep contrast-servic[e]`
|
20
|
-
processes = process.split("\n")
|
21
|
-
result = !processes.empty? && processes.any? { |process_descriptor| !process_descriptor.include?('grep') }
|
22
|
-
end
|
23
|
-
result
|
24
|
-
end
|
25
|
-
|
26
|
-
# check if service was killed and is a zombie process
|
27
|
-
# returns an array of zombie process PIDs as strings; empty array if there are none
|
28
|
-
def zombie_pids
|
29
|
-
with_contrast_scope do
|
30
|
-
# retrieve pid of service processes
|
31
|
-
zombie_pid_list = `ps aux | grep contrast-servic[e] | grep Z | awk '{print $2}'`
|
32
|
-
zombie_pid_list.split("\n")
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
16
|
# Check current OS type
|
37
17
|
# returns true if check is correct or false if not
|
38
18
|
def windows?
|
@@ -7,22 +7,6 @@ module Contrast
|
|
7
7
|
module ResponseUtils
|
8
8
|
private
|
9
9
|
|
10
|
-
# From the dtm for normalized_response_headers:
|
11
|
-
# Key is UPPERCASE_UNDERSCORE
|
12
|
-
#
|
13
|
-
# Example: Content-Type: text/html; charset=utf-8
|
14
|
-
# "CONTENT_TYPE" => Content-Type,["text/html; charset=utf8"]
|
15
|
-
def append_pair map, key, value
|
16
|
-
return unless key && value
|
17
|
-
return if value.is_a?(Hash)
|
18
|
-
|
19
|
-
safe_key = Contrast::Utils::StringUtils.force_utf8(key)
|
20
|
-
hash_key = Contrast::Utils::StringUtils.normalized_key(safe_key)
|
21
|
-
map[hash_key] ||= Contrast::Api::Dtm::Pair.new
|
22
|
-
map[hash_key].key = safe_key
|
23
|
-
map[hash_key].values << Contrast::Utils::StringUtils.force_utf8(value)
|
24
|
-
end
|
25
|
-
|
26
10
|
HTTP_PREFIX = /^[Hh][Tt][Tt][Pp][_-]/i.cs__freeze
|
27
11
|
|
28
12
|
# Given some holder of the content of the response's body, extract that
|
@@ -3,7 +3,6 @@
|
|
3
3
|
|
4
4
|
require 'contrast/utils/object_share'
|
5
5
|
require 'contrast/agent/reporting/reporting_events/application_defend_attack_sample_stack'
|
6
|
-
require 'contrast/api'
|
7
6
|
|
8
7
|
module Contrast
|
9
8
|
module Utils
|
@@ -33,16 +32,7 @@ module Contrast
|
|
33
32
|
end
|
34
33
|
|
35
34
|
# Call and translate a caller_locations array to an array of
|
36
|
-
#
|
37
|
-
# code found.
|
38
|
-
#
|
39
|
-
# @return [Array<Contrast::Api::Dtm::StackTraceElement>]
|
40
|
-
def build_protect_stack_array
|
41
|
-
build_protect_stack(Contrast::Api::Dtm::StackTraceElement)
|
42
|
-
end
|
43
|
-
|
44
|
-
# Call and translate a caller_locations array to an array of
|
45
|
-
# StackTraceElement for TeamServer to display, excluding any Contrast
|
35
|
+
# ApplicationDefendAttackSampleStack for TeamServer to display, excluding any Contrast
|
46
36
|
# code found.
|
47
37
|
#
|
48
38
|
# @return [Array<Contrast::Agent::Reporting::ApplicationDefendAttackSampleStack>]
|
@@ -59,10 +49,8 @@ module Contrast
|
|
59
49
|
end
|
60
50
|
end
|
61
51
|
|
62
|
-
# @param clazz [Class] Contrast::
|
63
|
-
#
|
64
|
-
# @return [Array<Contrast::Agent::Reporting::ApplicationDefendAttackSampleStack|
|
65
|
-
# Contrast::Api::Dtm::StackTraceElement>]
|
52
|
+
# @param clazz [Class] Contrast::Agent::Reporting::ApplicationDefendAttackSampleStack
|
53
|
+
# @return [Array<Contrast::Agent::Reporting::ApplicationDefendAttackSampleStack>]
|
66
54
|
def build_protect_stack clazz
|
67
55
|
stack = caller(3, 21)
|
68
56
|
return [] unless stack
|
@@ -22,13 +22,6 @@ module Contrast
|
|
22
22
|
!str.nil? && !str.to_s.empty?
|
23
23
|
end
|
24
24
|
|
25
|
-
def protobuf_format data, truncate: true
|
26
|
-
data = data&.to_s
|
27
|
-
data = Contrast::Utils::StringUtils.force_utf8(data)
|
28
|
-
data = Contrast::Utils::StringUtils.truncate(data) if truncate
|
29
|
-
data
|
30
|
-
end
|
31
|
-
|
32
25
|
# Protobuf has a very strict typing. Nil is not a String and will throw
|
33
26
|
# an exception if you try to set it. Use this to be safe.
|
34
27
|
# Uses the object share to avoid creating several new strings per request
|
@@ -93,6 +86,16 @@ module Contrast
|
|
93
86
|
@_normalized_keys[str] = cut
|
94
87
|
end
|
95
88
|
end
|
89
|
+
|
90
|
+
# transform string from snake_case to Capitalized Text
|
91
|
+
#
|
92
|
+
# @param str[String] string to transform
|
93
|
+
# @return [String]
|
94
|
+
def transform_string str
|
95
|
+
return unless str
|
96
|
+
|
97
|
+
str.split('-').map(&:capitalize).join(' ')
|
98
|
+
end
|
96
99
|
end
|
97
100
|
end
|
98
101
|
end
|
data/lib/contrast.rb
CHANGED
@@ -55,7 +55,6 @@ end
|
|
55
55
|
|
56
56
|
require 'contrast/components/assess'
|
57
57
|
require 'contrast/components/config'
|
58
|
-
require 'contrast/components/contrast_service'
|
59
58
|
require 'contrast/components/logger'
|
60
59
|
require 'contrast/components/protect'
|
61
60
|
require 'contrast/components/sampling'
|
@@ -64,7 +63,7 @@ require 'contrast/components/settings'
|
|
64
63
|
require 'contrast/utils/telemetry_hash'
|
65
64
|
require 'contrast/utils/telemetry'
|
66
65
|
require 'contrast/agent/telemetry/events/exceptions/telemetry_exception_event'
|
67
|
-
require '
|
66
|
+
require 'contrast/agent_lib/interface'
|
68
67
|
|
69
68
|
module Contrast
|
70
69
|
CONFIG = Contrast::Components::Config::Interface.new
|
@@ -76,7 +75,7 @@ module Contrast
|
|
76
75
|
INVENTORY = CONFIG.inventory
|
77
76
|
AGENT = CONFIG.agent
|
78
77
|
LOGGER = AGENT.logger
|
79
|
-
|
78
|
+
AGENT_LIB = Contrast::AgentLib::Interface.new
|
80
79
|
APP_CONTEXT = CONFIG.application
|
81
80
|
end
|
82
81
|
|
data/ruby-agent.gemspec
CHANGED
@@ -117,7 +117,8 @@ end
|
|
117
117
|
def self.add_dependencies spec
|
118
118
|
spec.add_dependency 'ougai', '>= 1.8', '< 3.0.0'
|
119
119
|
spec.add_dependency 'rack', '~> 2.0'
|
120
|
-
spec.add_dependency '
|
120
|
+
spec.add_dependency 'contrast-agent-lib', '~> 0.1.0'
|
121
|
+
spec.add_dependency 'ffi', '~> 1.0'
|
121
122
|
end
|
122
123
|
|
123
124
|
# Enumerate the files required to build the Agent.
|
@@ -136,9 +137,6 @@ def self.add_files spec
|
|
136
137
|
f.match(/(.*\.ya?ml)/)
|
137
138
|
end
|
138
139
|
|
139
|
-
spec.files << 'lib/contrast/api/dtm.pb.rb'
|
140
|
-
spec.files << 'lib/contrast/api/settings.pb.rb'
|
141
|
-
spec.files += Dir['service_executables/**/*']
|
142
140
|
spec.files += Dir['funchook/**/*']
|
143
141
|
spec.files += Dir['shared_libraries/**/*']
|
144
142
|
|
@@ -179,7 +177,6 @@ Gem::Specification.new do |spec|
|
|
179
177
|
spec.required_ruby_version = ['>= 2.7.0', '< 3.2.0']
|
180
178
|
|
181
179
|
spec.bindir = 'exe'
|
182
|
-
spec.executables = ['contrast_service']
|
183
180
|
# Keep cs__common first, it handles funchook.h right now.
|
184
181
|
spec.extensions = Dir['ext/cs__common/extconf.rb', 'ext/**/extconf.rb']
|
185
182
|
spec.require_paths = ['lib']
|