contrast-agent 5.2.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_array/cs__assess_array.c +7 -0
- data/ext/cs__assess_basic_object/cs__assess_basic_object.c +19 -5
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +1 -1
- data/ext/cs__assess_hash/cs__assess_hash.c +3 -4
- data/ext/cs__assess_kernel/cs__assess_kernel.c +1 -2
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +26 -12
- data/ext/cs__assess_module/cs__assess_module.c +1 -1
- 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 +21 -1
- 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 +113 -11
- data/ext/cs__common/cs__common.h +29 -5
- data/ext/cs__contrast_patch/cs__contrast_patch.c +55 -44
- data/ext/cs__os_information/cs__os_information.c +13 -10
- data/ext/cs__scope/cs__scope.c +146 -97
- 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/finalizers/hash.rb +2 -0
- data/lib/contrast/agent/assess/policy/policy_node.rb +50 -27
- data/lib/contrast/agent/assess/policy/policy_node_utils.rb +51 -0
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +2 -16
- data/lib/contrast/agent/assess/policy/preshift.rb +8 -2
- data/lib/contrast/agent/assess/policy/propagation_method.rb +47 -13
- data/lib/contrast/agent/assess/policy/propagator/buffer.rb +118 -0
- data/lib/contrast/agent/assess/policy/propagator/keep.rb +19 -4
- data/lib/contrast/agent/assess/policy/propagator/remove.rb +18 -2
- data/lib/contrast/agent/assess/policy/propagator/splat.rb +17 -3
- data/lib/contrast/agent/assess/policy/propagator/split.rb +15 -19
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/substitution_utils.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator.rb +1 -0
- data/lib/contrast/agent/assess/policy/source_method.rb +7 -7
- data/lib/contrast/agent/assess/policy/trigger_method.rb +4 -10
- data/lib/contrast/agent/assess/property/tagged.rb +1 -1
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +7 -2
- data/lib/contrast/agent/assess/rule/response/auto_complete_rule.rb +1 -1
- data/lib/contrast/agent/assess/rule/response/base_rule.rb +11 -3
- data/lib/contrast/agent/assess/rule/response/body_rule.rb +3 -3
- data/lib/contrast/agent/assess/rule/response/cache_control_header_rule.rb +60 -36
- data/lib/contrast/agent/assess/rule/response/framework/rails_support.rb +3 -3
- data/lib/contrast/agent/assess/rule/response/parameters_pollution_rule.rb +1 -1
- data/lib/contrast/agent/assess/rule/response/x_xss_protection_header_rule.rb +1 -2
- data/lib/contrast/agent/at_exit_hook.rb +1 -1
- data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +0 -7
- data/lib/contrast/agent/deadzone/policy/policy.rb +0 -6
- data/lib/contrast/agent/exclusion_matcher.rb +3 -3
- data/lib/contrast/agent/inventory/database_config.rb +10 -3
- data/lib/contrast/agent/middleware.rb +5 -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 +4 -4
- data/lib/contrast/agent/patching/policy/policy_node.rb +15 -2
- data/lib/contrast/agent/protect/exploitable_collection.rb +38 -0
- data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +66 -9
- data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -1
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +2 -2
- data/lib/contrast/agent/protect/rule/base.rb +37 -5
- data/lib/contrast/agent/protect/rule/base_service.rb +3 -1
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +13 -0
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_input_classification.rb +83 -0
- data/lib/contrast/agent/protect/rule/cmdi/cmdi_worth_watching.rb +64 -0
- data/lib/contrast/agent/protect/rule/http_method_tampering/http_method_tampering_input_classification.rb +96 -0
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +8 -0
- data/lib/contrast/agent/protect/rule/no_sqli/no_sqli_input_classification.rb +231 -0
- data/lib/contrast/agent/protect/rule/no_sqli.rb +27 -0
- data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +18 -54
- data/lib/contrast/agent/protect/rule/sqli/sqli_worth_watching.rb +1 -4
- data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_input_classification.rb +82 -0
- data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_matcher.rb +45 -0
- data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +42 -0
- data/lib/contrast/agent/reporting/attack_result/attack_result.rb +63 -0
- data/lib/contrast/agent/reporting/attack_result/rasp_rule_sample.rb +52 -0
- data/lib/contrast/agent/reporting/attack_result/response_type.rb +29 -0
- data/lib/contrast/agent/reporting/attack_result/user_input.rb +87 -0
- data/lib/contrast/agent/reporting/masker/masker.rb +243 -0
- data/lib/contrast/agent/reporting/masker/masker_utils.rb +62 -0
- data/lib/contrast/agent/reporting/report.rb +2 -0
- data/lib/contrast/agent/reporting/reporter.rb +29 -22
- data/lib/contrast/agent/reporting/reporter_heartbeat.rb +49 -0
- data/lib/contrast/agent/reporting/reporting_events/agent_startup.rb +34 -0
- 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 +12 -4
- 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 +50 -0
- data/lib/contrast/agent/reporting/reporting_events/application_startup_instrumentation.rb +27 -0
- data/lib/contrast/agent/reporting/reporting_events/application_update.rb +7 -12
- data/lib/contrast/agent/reporting/reporting_events/finding.rb +10 -4
- 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/library_usage_observation.rb +5 -5
- data/lib/contrast/agent/reporting/reporting_events/observed_library_usage.rb +6 -2
- data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +16 -12
- 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 +8 -11
- data/lib/contrast/agent/reporting/reporting_events/reporting_event.rb +2 -1
- data/lib/contrast/agent/reporting/reporting_events/route_coverage.rb +8 -6
- 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 +23 -7
- data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +64 -76
- data/lib/contrast/agent/reporting/reporting_utilities/reporting_storage.rb +1 -1
- data/lib/contrast/agent/reporting/reporting_utilities/response.rb +17 -7
- data/lib/contrast/agent/reporting/reporting_utilities/response_extractor.rb +100 -0
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +75 -13
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler_mode.rb +63 -0
- data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +154 -113
- data/lib/contrast/agent/reporting/settings/application_settings.rb +9 -0
- data/lib/contrast/agent/reporting/settings/assess_server_feature.rb +5 -33
- data/lib/contrast/agent/reporting/settings/protect.rb +1 -1
- data/lib/contrast/agent/reporting/settings/protect_server_feature.rb +2 -2
- data/lib/contrast/agent/reporting/settings/sampling.rb +36 -0
- data/lib/contrast/agent/reporting/settings/sensitive_data_masking.rb +110 -0
- data/lib/contrast/agent/reporting/settings/sensitive_data_masking_rule.rb +58 -0
- data/lib/contrast/agent/request.rb +3 -3
- data/lib/contrast/agent/request_context.rb +1 -1
- data/lib/contrast/agent/request_context_extend.rb +2 -2
- data/lib/contrast/agent/request_handler.rb +7 -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 +59 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_event.rb +44 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message.rb +115 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message_exception.rb +83 -0
- data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_stack_frame.rb +64 -0
- 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 +4 -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/address.rb +1 -1
- data/lib/contrast/api/decorators/http_request.rb +1 -1
- data/lib/contrast/api/decorators/response_type.rb +30 -0
- data/lib/contrast/api/decorators.rb +1 -0
- data/lib/contrast/components/app_context.rb +0 -4
- data/lib/contrast/components/assess.rb +14 -0
- data/lib/contrast/components/config.rb +13 -22
- data/lib/contrast/components/contrast_service.rb +9 -0
- data/lib/contrast/components/protect.rb +2 -2
- data/lib/contrast/components/sampling.rb +7 -11
- data/lib/contrast/components/settings.rb +116 -8
- data/lib/contrast/config/agent_configuration.rb +34 -41
- data/lib/contrast/config/api_configuration.rb +16 -75
- data/lib/contrast/config/api_proxy_configuration.rb +9 -48
- data/lib/contrast/config/application_configuration.rb +24 -95
- data/lib/contrast/config/assess_configuration.rb +21 -76
- data/lib/contrast/config/assess_rules_configuration.rb +13 -38
- data/lib/contrast/config/base_configuration.rb +11 -76
- data/lib/contrast/config/certification_configuration.rb +15 -68
- data/lib/contrast/config/exception_configuration.rb +15 -59
- data/lib/contrast/config/heap_dump_configuration.rb +19 -73
- data/lib/contrast/config/inventory_configuration.rb +11 -55
- data/lib/contrast/config/logger_configuration.rb +8 -41
- data/lib/contrast/config/protect_configuration.rb +23 -10
- data/lib/contrast/config/protect_rule_configuration.rb +23 -37
- data/lib/contrast/config/protect_rules_configuration.rb +39 -43
- data/lib/contrast/config/request_audit_configuration.rb +16 -55
- data/lib/contrast/config/root_configuration.rb +70 -13
- data/lib/contrast/config/ruby_configuration.rb +14 -47
- data/lib/contrast/config/sampling_configuration.rb +12 -65
- data/lib/contrast/config/server_configuration.rb +13 -45
- data/lib/contrast/config/service_configuration.rb +36 -17
- data/lib/contrast/configuration.rb +21 -13
- data/lib/contrast/extension/assess/string.rb +20 -1
- data/lib/contrast/extension/module.rb +0 -1
- data/lib/contrast/framework/manager.rb +2 -2
- 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 +1 -5
- data/lib/contrast/logger/cef_log.rb +1 -1
- data/lib/contrast/tasks/config.rb +100 -4
- data/lib/contrast/utils/assess/object_store.rb +36 -0
- data/lib/contrast/utils/assess/propagation_method_utils.rb +6 -0
- data/lib/contrast/utils/class_util.rb +5 -18
- data/lib/contrast/utils/input_classification.rb +73 -0
- data/lib/contrast/utils/invalid_configuration_util.rb +1 -1
- data/lib/contrast/utils/log_utils.rb +3 -1
- data/lib/contrast/utils/middleware_utils.rb +10 -9
- data/lib/contrast/utils/net_http_base.rb +1 -1
- data/lib/contrast/utils/object_share.rb +2 -1
- data/lib/contrast/utils/os.rb +0 -5
- data/lib/contrast/utils/patching/policy/patch_utils.rb +4 -5
- data/lib/contrast/utils/response_utils.rb +18 -33
- data/lib/contrast/utils/telemetry.rb +20 -2
- data/lib/contrast/utils/telemetry_client.rb +23 -11
- 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/resources/assess/policy.json +98 -0
- data/resources/deadzone/policy.json +0 -86
- data/ruby-agent.gemspec +10 -9
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +98 -30
- data/lib/contrast/agent/metric_telemetry_event.rb +0 -26
- data/lib/contrast/agent/startup_metrics_telemetry_event.rb +0 -121
- data/lib/contrast/agent/telemetry.rb +0 -137
- data/lib/contrast/agent/telemetry_event.rb +0 -33
- data/lib/contrast/utils/exclude_key.rb +0 -20
@@ -4,63 +4,24 @@
|
|
4
4
|
module Contrast
|
5
5
|
module Config
|
6
6
|
# Api Proxy keys configuration
|
7
|
-
class ApiProxyConfiguration
|
7
|
+
class ApiProxyConfiguration
|
8
|
+
include Contrast::Config::BaseConfiguration
|
9
|
+
|
8
10
|
# @return [String] proxy url
|
9
|
-
|
11
|
+
attr_accessor :url
|
12
|
+
attr_writer :enable
|
10
13
|
|
11
14
|
def initialize hsh = {}
|
12
|
-
|
13
|
-
|
14
|
-
@
|
15
|
-
|
15
|
+
return unless hsh
|
16
|
+
|
17
|
+
@enable = hsh[:enable]
|
18
|
+
@url = hsh[:url]
|
16
19
|
end
|
17
20
|
|
18
21
|
# @return [Boolean, false]
|
19
22
|
def enable
|
20
23
|
@enable.nil? ? false : @enable
|
21
24
|
end
|
22
|
-
|
23
|
-
def enable= value
|
24
|
-
self['enable'] = value
|
25
|
-
end
|
26
|
-
|
27
|
-
def url= value
|
28
|
-
self['url'] = value
|
29
|
-
end
|
30
|
-
|
31
|
-
# TODO: RUBY-1493 MOVE TO BASE CONFIG
|
32
|
-
|
33
|
-
def []= key, value
|
34
|
-
instance_variable_set("@#{ key }".to_sym, value)
|
35
|
-
@configuration_map[key] = value
|
36
|
-
end
|
37
|
-
|
38
|
-
def [] key
|
39
|
-
send(key.to_sym)
|
40
|
-
end
|
41
|
-
|
42
|
-
# Traverse the given entity to build out the configuration graph.
|
43
|
-
#
|
44
|
-
# The values will be either a hash, indicating internal nodes to
|
45
|
-
# traverse, or a value to set or the EMPTY_VALUE symbol, indicating a
|
46
|
-
# leaf node.
|
47
|
-
#
|
48
|
-
# The spec_key are the Contrast defined keys based on the instance variables of
|
49
|
-
# a given configuration.
|
50
|
-
def traverse_config values, spec_key
|
51
|
-
internal_nodes = values.cs__respond_to?(:has_key?)
|
52
|
-
val = internal_nodes ? value_from_key_config(spec_key, values) : nil
|
53
|
-
val == EMPTY_VALUE ? nil : val
|
54
|
-
end
|
55
|
-
|
56
|
-
def build_configuration_map
|
57
|
-
instance_variables.each do |key|
|
58
|
-
str_key = key.to_s.tr('@', '')
|
59
|
-
next if str_key == 'configuration_map'
|
60
|
-
|
61
|
-
@configuration_map[str_key] = send(str_key.to_sym)
|
62
|
-
end
|
63
|
-
end
|
64
25
|
end
|
65
26
|
end
|
66
27
|
end
|
@@ -7,37 +7,40 @@ module Contrast
|
|
7
7
|
module Config
|
8
8
|
# Common Configuration settings. Those in this section pertain to the
|
9
9
|
# application identification functionality of the Agent.
|
10
|
-
class ApplicationConfiguration
|
10
|
+
class ApplicationConfiguration
|
11
|
+
include Contrast::Config::BaseConfiguration
|
12
|
+
|
11
13
|
# @return [String]
|
12
|
-
|
14
|
+
attr_accessor :name
|
13
15
|
# @return [String]
|
14
|
-
|
16
|
+
attr_accessor :version
|
15
17
|
# @return [String]
|
16
|
-
|
18
|
+
attr_accessor :language
|
17
19
|
# @return [String]
|
18
|
-
|
20
|
+
attr_accessor :path
|
19
21
|
# @return [String]
|
20
|
-
|
22
|
+
attr_accessor :group
|
21
23
|
# @return [String]
|
22
|
-
|
24
|
+
attr_accessor :tags
|
23
25
|
# @return [String]
|
24
|
-
|
26
|
+
attr_accessor :code
|
25
27
|
# @return [String]
|
26
|
-
|
28
|
+
attr_accessor :metadata
|
29
|
+
attr_writer :session_id, :session_metadata
|
27
30
|
|
28
31
|
def initialize hsh = {}
|
29
|
-
|
30
|
-
|
31
|
-
@
|
32
|
-
@
|
33
|
-
@
|
34
|
-
@
|
35
|
-
@
|
36
|
-
@
|
37
|
-
@
|
38
|
-
@
|
39
|
-
@
|
40
|
-
|
32
|
+
return unless hsh
|
33
|
+
|
34
|
+
@name = hsh[:name]
|
35
|
+
@version = hsh[:version]
|
36
|
+
@language = hsh[:language]
|
37
|
+
@path = hsh[:path]
|
38
|
+
@group = hsh[:group]
|
39
|
+
@tags = hsh[:tags]
|
40
|
+
@code = hsh[:code]
|
41
|
+
@metadata = hsh[:metadata]
|
42
|
+
@session_id = hsh[:session_id]
|
43
|
+
@session_metadata = hsh[:session_metadata]
|
41
44
|
end
|
42
45
|
|
43
46
|
# @return [String, Contrast::Utils::ObjectShare::EMPTY_STRING]
|
@@ -49,80 +52,6 @@ module Contrast
|
|
49
52
|
def session_metadata
|
50
53
|
@session_metadata ||= Contrast::Utils::ObjectShare::EMPTY_STRING
|
51
54
|
end
|
52
|
-
|
53
|
-
def name= value
|
54
|
-
self['name'] = value
|
55
|
-
end
|
56
|
-
|
57
|
-
def version= value
|
58
|
-
self['version'] = value
|
59
|
-
end
|
60
|
-
|
61
|
-
def language= value
|
62
|
-
self['language'] = value
|
63
|
-
end
|
64
|
-
|
65
|
-
def path= value
|
66
|
-
self['path'] = value
|
67
|
-
end
|
68
|
-
|
69
|
-
def group= value
|
70
|
-
self['group'] = value
|
71
|
-
end
|
72
|
-
|
73
|
-
def tags= value
|
74
|
-
self['tags'] = value
|
75
|
-
end
|
76
|
-
|
77
|
-
def code= value
|
78
|
-
self['code'] = value
|
79
|
-
end
|
80
|
-
|
81
|
-
def metadata= value
|
82
|
-
self['metadata'] = value
|
83
|
-
end
|
84
|
-
|
85
|
-
def session_id= value
|
86
|
-
self['session_id'] = value
|
87
|
-
end
|
88
|
-
|
89
|
-
def session_metadata= value
|
90
|
-
self['session_metadata'] = value
|
91
|
-
end
|
92
|
-
|
93
|
-
# TODO: RUBY-1493 MOVE TO BASE CONFIG
|
94
|
-
|
95
|
-
def []= key, value
|
96
|
-
instance_variable_set("@#{ key }".to_sym, value)
|
97
|
-
@configuration_map[key] = value
|
98
|
-
end
|
99
|
-
|
100
|
-
def [] key
|
101
|
-
send(key.to_sym)
|
102
|
-
end
|
103
|
-
|
104
|
-
# Traverse the given entity to build out the configuration graph.
|
105
|
-
#
|
106
|
-
# The values will be either a hash, indicating internal nodes to
|
107
|
-
# traverse, or a value to set or the EMPTY_VALUE symbol, indicating a
|
108
|
-
# leaf node.
|
109
|
-
#
|
110
|
-
# The spec_key are the Contrast defined keys based on the instance variables of
|
111
|
-
# a given configuration.
|
112
|
-
def traverse_config values, spec_key
|
113
|
-
internal_nodes = values.cs__respond_to?(:has_key?)
|
114
|
-
val = internal_nodes ? value_from_key_config(spec_key, values) : nil
|
115
|
-
val == EMPTY_VALUE ? nil : val
|
116
|
-
end
|
117
|
-
|
118
|
-
def build_configuration_map
|
119
|
-
instance_variables.each do |key|
|
120
|
-
str_key = key.to_s.tr('@', '')
|
121
|
-
next if str_key == 'configuration_map'
|
122
|
-
|
123
|
-
@configuration_map[str_key] = send(str_key.to_sym)
|
124
|
-
end
|
125
|
-
end
|
126
55
|
end
|
127
56
|
end
|
128
57
|
end
|
@@ -5,27 +5,28 @@ module Contrast
|
|
5
5
|
module Config
|
6
6
|
# Common Configuration settings. Those in this section pertain to the
|
7
7
|
# assess functionality of the Agent.
|
8
|
-
class AssessConfiguration
|
8
|
+
class AssessConfiguration
|
9
|
+
include Contrast::Config::BaseConfiguration
|
10
|
+
|
9
11
|
# @return [String, nil]
|
10
|
-
|
12
|
+
attr_accessor :tags
|
13
|
+
# @return [Boolean, nil]
|
14
|
+
attr_accessor :enable
|
15
|
+
attr_writer :enable_scan_response, :enable_dynamic_sources, :sampling, :rules, :stacktraces
|
11
16
|
|
12
17
|
DEFAULT_STACKTRACES = 'ALL'
|
13
18
|
|
14
19
|
def initialize hsh = {}
|
15
|
-
|
16
|
-
@tags = traverse_config(hsh, :tags)
|
17
|
-
@enable_scan_response = traverse_config(hsh, :enable_scan_response)
|
18
|
-
@enable_dynamic_sources = traverse_config(hsh, :enable_dynamic_sources)
|
19
|
-
@sampling = Contrast::Config::SamplingConfiguration.new(traverse_config(hsh, :sampling))
|
20
|
-
@rules = Contrast::Config::AssessRulesConfiguration.new(traverse_config(hsh, :rules))
|
21
|
-
@stacktraces = traverse_config(hsh, :stacktraces)
|
22
|
-
@configuration_map = {}
|
23
|
-
build_configuration_map
|
24
|
-
end
|
20
|
+
return unless hsh
|
25
21
|
|
26
|
-
|
27
|
-
|
28
|
-
@
|
22
|
+
@enable = hsh[:enable]
|
23
|
+
@tags = hsh[:tags]
|
24
|
+
@enable_scan_response = hsh[:enable_scan_response]
|
25
|
+
@enable_dynamic_sources = hsh[:enable_dynamic_sources]
|
26
|
+
@enable_original_object = hsh[:enable_original_object]
|
27
|
+
@sampling = Contrast::Config::SamplingConfiguration.new(hsh[:sampling])
|
28
|
+
@rules = Contrast::Config::AssessRulesConfiguration.new(hsh[:rules])
|
29
|
+
@stacktraces = hsh[:stacktraces]
|
29
30
|
end
|
30
31
|
|
31
32
|
# @return [Boolean, true]
|
@@ -38,6 +39,11 @@ module Contrast
|
|
38
39
|
@enable_dynamic_sources.nil? ? true : @enable_dynamic_sources
|
39
40
|
end
|
40
41
|
|
42
|
+
# @return [Boolean, true]
|
43
|
+
def enable_original_object
|
44
|
+
@enable_original_object.nil? ? true : @enable_original_object
|
45
|
+
end
|
46
|
+
|
41
47
|
# @return [Contrast::Config::SamplingConfiguration]
|
42
48
|
def sampling
|
43
49
|
@sampling ||= Contrast::Config::SamplingConfiguration.new
|
@@ -52,67 +58,6 @@ module Contrast
|
|
52
58
|
def stacktraces
|
53
59
|
@stacktraces ||= DEFAULT_STACKTRACES
|
54
60
|
end
|
55
|
-
|
56
|
-
def enable= value
|
57
|
-
self['enable'] = value
|
58
|
-
end
|
59
|
-
|
60
|
-
def tags= value
|
61
|
-
self['tags'] = value
|
62
|
-
end
|
63
|
-
|
64
|
-
def enable_scan_response= value
|
65
|
-
self['enable_scan_response'] = value
|
66
|
-
end
|
67
|
-
|
68
|
-
def enable_dynamic_sources= value
|
69
|
-
self['enable_dynamic_sources'] = value
|
70
|
-
end
|
71
|
-
|
72
|
-
def sampling= value
|
73
|
-
self['sampling'] = value
|
74
|
-
end
|
75
|
-
|
76
|
-
def rules= value
|
77
|
-
self['rules'] = value
|
78
|
-
end
|
79
|
-
|
80
|
-
def stacktraces= value
|
81
|
-
self['stacktraces'] = value
|
82
|
-
end
|
83
|
-
# TODO: RUBY-1493 MOVE TO BASE CONFIG
|
84
|
-
|
85
|
-
def []= key, value
|
86
|
-
instance_variable_set("@#{ key }".to_sym, value)
|
87
|
-
@configuration_map[key] = value
|
88
|
-
end
|
89
|
-
|
90
|
-
def [] key
|
91
|
-
send(key.to_sym)
|
92
|
-
end
|
93
|
-
|
94
|
-
# Traverse the given entity to build out the configuration graph.
|
95
|
-
#
|
96
|
-
# The values will be either a hash, indicating internal nodes to
|
97
|
-
# traverse, or a value to set or the EMPTY_VALUE symbol, indicating a
|
98
|
-
# leaf node.
|
99
|
-
#
|
100
|
-
# The spec_key are the Contrast defined keys based on the instance variables of
|
101
|
-
# a given configuration.
|
102
|
-
def traverse_config values, spec_key
|
103
|
-
internal_nodes = values.cs__respond_to?(:has_key?)
|
104
|
-
val = internal_nodes ? value_from_key_config(spec_key, values) : nil
|
105
|
-
val == EMPTY_VALUE ? nil : val
|
106
|
-
end
|
107
|
-
|
108
|
-
def build_configuration_map
|
109
|
-
instance_variables.each do |key|
|
110
|
-
str_key = key.to_s.tr('@', '')
|
111
|
-
next if str_key == 'configuration_map'
|
112
|
-
|
113
|
-
@configuration_map[str_key] = send(str_key.to_sym)
|
114
|
-
end
|
115
|
-
end
|
116
61
|
end
|
117
62
|
end
|
118
63
|
end
|
@@ -5,52 +5,27 @@ module Contrast
|
|
5
5
|
module Config
|
6
6
|
# Common Configuration settings. Those in this section pertain to the
|
7
7
|
# disabled assess rule functionality of the Agent.
|
8
|
-
class AssessRulesConfiguration
|
8
|
+
class AssessRulesConfiguration
|
9
|
+
include Contrast::Config::BaseConfiguration
|
10
|
+
|
11
|
+
SPEC_KEY = :disabled_rules.cs__freeze
|
9
12
|
# @return [Array, nil] list of disabled assess rules
|
10
|
-
|
13
|
+
attr_accessor :disabled_rules
|
11
14
|
|
12
15
|
def initialize hsh = {}
|
13
|
-
|
14
|
-
@configuration_map = {}
|
15
|
-
build_configuration_map
|
16
|
-
end
|
17
|
-
|
18
|
-
def disabled_rules= value
|
19
|
-
self['disabled_rules'] = value
|
20
|
-
end
|
16
|
+
return unless hsh
|
21
17
|
|
22
|
-
|
23
|
-
|
24
|
-
def []= key, value
|
25
|
-
instance_variable_set("@#{ key }".to_sym, value)
|
26
|
-
@configuration_map[key] = value
|
27
|
-
end
|
28
|
-
|
29
|
-
def [] key
|
30
|
-
send(key.to_sym)
|
18
|
+
@disabled_rules = cast_disabled_rules hsh
|
31
19
|
end
|
32
20
|
|
33
|
-
|
34
|
-
#
|
35
|
-
# The values will be either a hash, indicating internal nodes to
|
36
|
-
# traverse, or a value to set or the EMPTY_VALUE symbol, indicating a
|
37
|
-
# leaf node.
|
38
|
-
#
|
39
|
-
# The spec_key are the Contrast defined keys based on the instance variables of
|
40
|
-
# a given configuration.
|
41
|
-
def traverse_config values, spec_key
|
42
|
-
internal_nodes = values.cs__respond_to?(:has_key?)
|
43
|
-
val = internal_nodes ? value_from_key_config(spec_key, values) : nil
|
44
|
-
val == EMPTY_VALUE ? nil : val
|
45
|
-
end
|
21
|
+
private
|
46
22
|
|
47
|
-
def
|
48
|
-
|
49
|
-
|
50
|
-
|
23
|
+
def cast_disabled_rules hsh
|
24
|
+
return unless hsh
|
25
|
+
return unless hsh.key?(SPEC_KEY)
|
26
|
+
return hsh[SPEC_KEY] if hsh[SPEC_KEY].cs__is_a?(Array)
|
51
27
|
|
52
|
-
|
53
|
-
end
|
28
|
+
hsh[SPEC_KEY].split(',').map(&:strip) if hsh[SPEC_KEY].cs__is_a?(String)
|
54
29
|
end
|
55
30
|
end
|
56
31
|
end
|
@@ -6,25 +6,19 @@ require 'contrast/utils/object_share'
|
|
6
6
|
|
7
7
|
module Contrast
|
8
8
|
module Config
|
9
|
-
# This is the base for our configuration classes. It is intended to
|
10
|
-
#
|
11
|
-
|
12
|
-
class BaseConfiguration
|
9
|
+
# This is the base for our configuration classes. It is intended to facilitate the translation of the Common
|
10
|
+
# Configuration settings to usable Ruby classes.
|
11
|
+
module BaseConfiguration
|
13
12
|
extend Forwardable
|
14
13
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
def initialize hsh = {}, keys = {}
|
24
|
-
# holds configuration key value pairs
|
25
|
-
# each configuration class can contain nested BaseConfigurations
|
26
|
-
@configuration_map = {}
|
27
|
-
traverse_config(hsh, keys)
|
14
|
+
def to_hash
|
15
|
+
hsh = {}
|
16
|
+
instance_variables.each do |iv|
|
17
|
+
# strip the '@' to get the key
|
18
|
+
key = iv.to_s[1..]
|
19
|
+
hsh[key] = send(key.to_sym)
|
20
|
+
end
|
21
|
+
hsh
|
28
22
|
end
|
29
23
|
|
30
24
|
def assign_value_to_path_array dot_path_array, value
|
@@ -39,65 +33,6 @@ module Contrast
|
|
39
33
|
end
|
40
34
|
nil
|
41
35
|
end
|
42
|
-
|
43
|
-
def nil?
|
44
|
-
@configuration_map.empty?
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
# Traverse the given entity to build out the configuration graph.
|
50
|
-
#
|
51
|
-
# The values will be either a hash, indicating internal nodes to
|
52
|
-
# traverse, or a value to set or the EMPTY_VALUE symbol, indicating a
|
53
|
-
# leaf node.
|
54
|
-
#
|
55
|
-
# The spec_keys are the Contrast defined keys used to access a given
|
56
|
-
# configuration. Each child of this class maintains its own set of keys,
|
57
|
-
# as well as Objects to which those keys map.
|
58
|
-
def traverse_config values, spec_keys
|
59
|
-
internal_nodes = values.cs__respond_to?(:has_key?)
|
60
|
-
spec_keys.each_pair do |spec_key, spec_value|
|
61
|
-
user_provided_value = internal_nodes ? value_from_key_config(spec_key, values) : EMPTY_VALUE
|
62
|
-
define_methods(spec_key, spec_value, user_provided_value)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def define_methods spec_key, spec_value, user_provided_value
|
67
|
-
str_key = spec_key.to_s
|
68
|
-
assign_config_value(str_key, spec_value, user_provided_value)
|
69
|
-
define_getter(str_key)
|
70
|
-
define_setter(str_key)
|
71
|
-
end
|
72
|
-
|
73
|
-
def assign_config_value str_key, spec_value, user_provided_value
|
74
|
-
@configuration_map[str_key] = if spec_value.is_a?(Class) && spec_value <= Contrast::Config::BaseConfiguration
|
75
|
-
spec_value.new(user_provided_value)
|
76
|
-
elsif user_provided_value == EMPTY_VALUE
|
77
|
-
spec_value
|
78
|
-
else
|
79
|
-
user_provided_value
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def value_from_key_config key, config_hash
|
84
|
-
return config_hash[key] if config_hash.key?(key)
|
85
|
-
return config_hash.fetch(key.to_sym, EMPTY_VALUE) if key.is_a?(String)
|
86
|
-
|
87
|
-
config_hash.fetch(key.to_s, EMPTY_VALUE)
|
88
|
-
end
|
89
|
-
|
90
|
-
def define_getter str_key
|
91
|
-
define_singleton_method str_key.to_sym do
|
92
|
-
@configuration_map[str_key] == EMPTY_VALUE ? nil : @configuration_map[str_key]
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
def define_setter str_key
|
97
|
-
define_singleton_method "#{ str_key }=".to_sym do |new_value|
|
98
|
-
@configuration_map[str_key] = new_value
|
99
|
-
end
|
100
|
-
end
|
101
36
|
end
|
102
37
|
end
|
103
38
|
end
|
@@ -4,82 +4,29 @@
|
|
4
4
|
module Contrast
|
5
5
|
module Config
|
6
6
|
# Certificate Configuration
|
7
|
-
class CertificationConfiguration
|
7
|
+
class CertificationConfiguration
|
8
|
+
include Contrast::Config::BaseConfiguration
|
9
|
+
|
8
10
|
# @return [String] path to CA Cert file
|
9
|
-
|
11
|
+
attr_accessor :ca_file
|
10
12
|
# @return [String] path to Certification file
|
11
|
-
|
13
|
+
attr_accessor :cert_file
|
12
14
|
# @return [String] path to Certification Key file
|
13
|
-
|
15
|
+
attr_accessor :key_file
|
16
|
+
attr_writer :enable
|
14
17
|
|
15
18
|
def initialize hsh = {}
|
16
|
-
|
17
|
-
@ca_file = traverse_config(hsh, :ca_file)
|
18
|
-
@cert_file = traverse_config(hsh, :cert_file)
|
19
|
-
@key_file = traverse_config(hsh, :key_file)
|
20
|
-
@configuration_map = {}
|
21
|
-
build_configuration_map
|
22
|
-
end
|
23
|
-
|
24
|
-
# GETTERS
|
25
|
-
|
26
|
-
# @return [Boolean]
|
27
|
-
def enable
|
28
|
-
return false if @enable.nil?
|
29
|
-
|
30
|
-
@enable
|
31
|
-
end
|
32
|
-
|
33
|
-
# SETTERS
|
34
|
-
|
35
|
-
def enable= value
|
36
|
-
self['enable'] = value
|
37
|
-
end
|
38
|
-
|
39
|
-
def ca_file= value
|
40
|
-
self['ca_file'] = value
|
41
|
-
end
|
19
|
+
return unless hsh
|
42
20
|
|
43
|
-
|
44
|
-
|
21
|
+
@enable = hsh[:enable]
|
22
|
+
@ca_file = hsh[:ca_file]
|
23
|
+
@cert_file = hsh[:cert_file]
|
24
|
+
@key_file = hsh[:key_file]
|
45
25
|
end
|
46
26
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
# TODO: RUBY-1493 MOVE TO BASE CONFIG
|
52
|
-
|
53
|
-
def []= key, value
|
54
|
-
instance_variable_set("@#{ key }".to_sym, value)
|
55
|
-
@configuration_map[key] = value
|
56
|
-
end
|
57
|
-
|
58
|
-
def [] key
|
59
|
-
send(key.to_sym)
|
60
|
-
end
|
61
|
-
|
62
|
-
# Traverse the given entity to build out the configuration graph.
|
63
|
-
#
|
64
|
-
# The values will be either a hash, indicating internal nodes to
|
65
|
-
# traverse, or a value to set or the EMPTY_VALUE symbol, indicating a
|
66
|
-
# leaf node.
|
67
|
-
#
|
68
|
-
# The spec_key are the Contrast defined keys based on the instance variables of
|
69
|
-
# a given configuration.
|
70
|
-
def traverse_config values, spec_key
|
71
|
-
internal_nodes = values.cs__respond_to?(:has_key?)
|
72
|
-
val = internal_nodes ? value_from_key_config(spec_key, values) : nil
|
73
|
-
val == EMPTY_VALUE ? nil : val
|
74
|
-
end
|
75
|
-
|
76
|
-
def build_configuration_map
|
77
|
-
instance_variables.each do |key|
|
78
|
-
str_key = key.to_s.tr('@', '')
|
79
|
-
next if str_key == 'configuration_map'
|
80
|
-
|
81
|
-
@configuration_map[str_key] = send(str_key.to_sym)
|
82
|
-
end
|
27
|
+
# @return [Boolean, false]
|
28
|
+
def enable
|
29
|
+
@enable.nil? ? false : @enable
|
83
30
|
end
|
84
31
|
end
|
85
32
|
end
|
@@ -3,72 +3,28 @@
|
|
3
3
|
|
4
4
|
module Contrast
|
5
5
|
module Config
|
6
|
-
# Common Configuration settings. Those in this section pertain to the
|
7
|
-
#
|
8
|
-
|
9
|
-
|
6
|
+
# Common Configuration settings. Those in this section pertain to the exception handling in Ruby, allowing for the
|
7
|
+
# override of Response Code and Message when Security Exceptions are raised.
|
8
|
+
class ExceptionConfiguration
|
9
|
+
include Contrast::Config::BaseConfiguration
|
10
|
+
|
10
11
|
# @return [Integer] the HTTP status code override
|
11
|
-
|
12
|
+
attr_accessor :override_status
|
12
13
|
# @return [String] the message text override
|
13
|
-
|
14
|
+
attr_accessor :override_message
|
15
|
+
attr_writer :capture
|
14
16
|
|
15
17
|
def initialize hsh = {}
|
16
|
-
|
17
|
-
@override_status = traverse_config(hsh, :override_status)
|
18
|
-
@override_message = traverse_config(hsh, :override_message)
|
19
|
-
@configuration_map = {}
|
20
|
-
build_configuration_map
|
21
|
-
end
|
22
|
-
|
23
|
-
# @return [Boolean] default: false
|
24
|
-
def capture
|
25
|
-
@capture.nil? ? false : @capture
|
26
|
-
end
|
27
|
-
|
28
|
-
def capture= value
|
29
|
-
self['capture'] = value
|
30
|
-
end
|
31
|
-
|
32
|
-
def override_status= value
|
33
|
-
self['override_status'] = value
|
34
|
-
end
|
18
|
+
return unless hsh
|
35
19
|
|
36
|
-
|
37
|
-
|
20
|
+
@capture = hsh[:capture]
|
21
|
+
@override_status = hsh[:override_status]
|
22
|
+
@override_message = hsh[:override_message]
|
38
23
|
end
|
39
24
|
|
40
|
-
#
|
41
|
-
|
42
|
-
|
43
|
-
instance_variable_set("@#{ key }".to_sym, value)
|
44
|
-
@configuration_map[key] = value
|
45
|
-
end
|
46
|
-
|
47
|
-
def [] key
|
48
|
-
send(key.to_sym)
|
49
|
-
end
|
50
|
-
|
51
|
-
# Traverse the given entity to build out the configuration graph.
|
52
|
-
#
|
53
|
-
# The values will be either a hash, indicating internal nodes to
|
54
|
-
# traverse, or a value to set or the EMPTY_VALUE symbol, indicating a
|
55
|
-
# leaf node.
|
56
|
-
#
|
57
|
-
# The spec_key are the Contrast defined keys based on the instance variables of
|
58
|
-
# a given configuration.
|
59
|
-
def traverse_config values, spec_key
|
60
|
-
internal_nodes = values.cs__respond_to?(:has_key?)
|
61
|
-
val = internal_nodes ? value_from_key_config(spec_key, values) : nil
|
62
|
-
val == EMPTY_VALUE ? nil : val
|
63
|
-
end
|
64
|
-
|
65
|
-
def build_configuration_map
|
66
|
-
instance_variables.each do |key|
|
67
|
-
str_key = key.to_s.tr('@', '')
|
68
|
-
next if str_key == 'configuration_map'
|
69
|
-
|
70
|
-
@configuration_map[str_key] = send(str_key.to_sym)
|
71
|
-
end
|
25
|
+
# @return [Boolean, false]
|
26
|
+
def capture
|
27
|
+
!!@capture
|
72
28
|
end
|
73
29
|
end
|
74
30
|
end
|