contrast-agent 5.3.0 → 6.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/ext/cs__assess_array/cs__assess_array.c +7 -0
  3. data/ext/cs__assess_basic_object/cs__assess_basic_object.c +19 -5
  4. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +1 -1
  5. data/ext/cs__assess_hash/cs__assess_hash.c +3 -4
  6. data/ext/cs__assess_kernel/cs__assess_kernel.c +1 -2
  7. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +26 -12
  8. data/ext/cs__assess_module/cs__assess_module.c +1 -1
  9. data/ext/cs__assess_string/cs__assess_string.c +13 -1
  10. data/ext/cs__common/cs__common.c +12 -11
  11. data/ext/cs__contrast_patch/cs__contrast_patch.c +54 -43
  12. data/ext/cs__os_information/cs__os_information.c +13 -10
  13. data/ext/cs__scope/cs__scope.c +146 -97
  14. data/lib/contrast/agent/assess/finalizers/hash.rb +2 -0
  15. data/lib/contrast/agent/assess/policy/policy_node.rb +50 -27
  16. data/lib/contrast/agent/assess/policy/policy_node_utils.rb +51 -0
  17. data/lib/contrast/agent/assess/policy/preshift.rb +8 -2
  18. data/lib/contrast/agent/assess/policy/propagation_method.rb +47 -13
  19. data/lib/contrast/agent/assess/policy/propagator/buffer.rb +118 -0
  20. data/lib/contrast/agent/assess/policy/propagator/keep.rb +19 -4
  21. data/lib/contrast/agent/assess/policy/propagator/remove.rb +18 -2
  22. data/lib/contrast/agent/assess/policy/propagator/splat.rb +17 -3
  23. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +1 -1
  24. data/lib/contrast/agent/assess/policy/propagator/substitution_utils.rb +1 -1
  25. data/lib/contrast/agent/assess/policy/propagator/trim.rb +1 -1
  26. data/lib/contrast/agent/assess/policy/propagator.rb +1 -0
  27. data/lib/contrast/agent/assess/policy/source_method.rb +7 -7
  28. data/lib/contrast/agent/assess/policy/trigger_method.rb +3 -1
  29. data/lib/contrast/agent/assess/property/tagged.rb +1 -1
  30. data/lib/contrast/agent/assess/rule/response/auto_complete_rule.rb +1 -1
  31. data/lib/contrast/agent/assess/rule/response/body_rule.rb +3 -3
  32. data/lib/contrast/agent/assess/rule/response/cache_control_header_rule.rb +1 -1
  33. data/lib/contrast/agent/assess/rule/response/parameters_pollution_rule.rb +1 -1
  34. data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +0 -7
  35. data/lib/contrast/agent/deadzone/policy/policy.rb +0 -6
  36. data/lib/contrast/agent/exclusion_matcher.rb +3 -3
  37. data/lib/contrast/agent/middleware.rb +3 -1
  38. data/lib/contrast/agent/patching/policy/patcher.rb +3 -3
  39. data/lib/contrast/agent/patching/policy/policy_node.rb +15 -2
  40. data/lib/contrast/agent/protect/exploitable_collection.rb +38 -0
  41. data/lib/contrast/agent/protect/input_analyzer/input_analyzer.rb +61 -8
  42. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -1
  43. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +2 -2
  44. data/lib/contrast/agent/protect/rule/base.rb +37 -5
  45. data/lib/contrast/agent/protect/rule/base_service.rb +3 -1
  46. data/lib/contrast/agent/protect/rule/cmd_injection.rb +13 -0
  47. data/lib/contrast/agent/protect/rule/cmdi/cmdi_input_classification.rb +83 -0
  48. data/lib/contrast/agent/protect/rule/cmdi/cmdi_worth_watching.rb +64 -0
  49. data/lib/contrast/agent/protect/rule/http_method_tampering/http_method_tampering_input_classification.rb +96 -0
  50. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +8 -0
  51. data/lib/contrast/agent/protect/rule/no_sqli/no_sqli_input_classification.rb +231 -0
  52. data/lib/contrast/agent/protect/rule/no_sqli.rb +27 -0
  53. data/lib/contrast/agent/protect/rule/sqli/sqli_input_classification.rb +18 -54
  54. data/lib/contrast/agent/protect/rule/sqli/sqli_worth_watching.rb +1 -4
  55. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_input_classification.rb +82 -0
  56. data/lib/contrast/agent/protect/rule/unsafe_file_upload/unsafe_file_upload_matcher.rb +45 -0
  57. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +42 -0
  58. data/lib/contrast/agent/reporting/attack_result/attack_result.rb +63 -0
  59. data/lib/contrast/agent/reporting/attack_result/rasp_rule_sample.rb +52 -0
  60. data/lib/contrast/agent/reporting/attack_result/response_type.rb +29 -0
  61. data/lib/contrast/agent/reporting/attack_result/user_input.rb +87 -0
  62. data/lib/contrast/agent/reporting/masker/masker.rb +246 -0
  63. data/lib/contrast/agent/reporting/masker/masker_utils.rb +58 -0
  64. data/lib/contrast/agent/reporting/report.rb +2 -0
  65. data/lib/contrast/agent/reporting/reporter.rb +23 -11
  66. data/lib/contrast/agent/reporting/reporting_events/agent_startup.rb +30 -0
  67. data/lib/contrast/agent/reporting/reporting_events/application_inventory.rb +7 -3
  68. data/lib/contrast/agent/reporting/reporting_events/application_startup.rb +40 -0
  69. data/lib/contrast/agent/reporting/reporting_events/application_startup_instrumentation.rb +27 -0
  70. data/lib/contrast/agent/reporting/reporting_events/finding.rb +1 -1
  71. data/lib/contrast/agent/reporting/reporting_events/library_usage_observation.rb +5 -5
  72. data/lib/contrast/agent/reporting/reporting_events/observed_route.rb +9 -9
  73. data/lib/contrast/agent/reporting/reporting_events/preflight_message.rb +2 -1
  74. data/lib/contrast/agent/reporting/reporting_events/reporting_event.rb +2 -1
  75. data/lib/contrast/agent/reporting/reporting_events/route_coverage.rb +8 -6
  76. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client.rb +16 -5
  77. data/lib/contrast/agent/reporting/reporting_utilities/reporter_client_utils.rb +27 -26
  78. data/lib/contrast/agent/reporting/reporting_utilities/reporting_storage.rb +1 -1
  79. data/lib/contrast/agent/reporting/reporting_utilities/response_extractor.rb +97 -0
  80. data/lib/contrast/agent/reporting/reporting_utilities/response_handler.rb +68 -6
  81. data/lib/contrast/agent/reporting/reporting_utilities/response_handler_mode.rb +63 -0
  82. data/lib/contrast/agent/reporting/reporting_utilities/response_handler_utils.rb +122 -96
  83. data/lib/contrast/agent/reporting/settings/application_settings.rb +9 -0
  84. data/lib/contrast/agent/reporting/settings/assess_server_feature.rb +5 -33
  85. data/lib/contrast/agent/reporting/settings/protect_server_feature.rb +1 -1
  86. data/lib/contrast/agent/reporting/settings/sampling.rb +36 -0
  87. data/lib/contrast/agent/reporting/settings/sensitive_data_masking.rb +110 -0
  88. data/lib/contrast/agent/reporting/settings/sensitive_data_masking_rule.rb +58 -0
  89. data/lib/contrast/agent/request_context.rb +1 -1
  90. data/lib/contrast/agent/request_context_extend.rb +1 -1
  91. data/lib/contrast/agent/request_handler.rb +4 -0
  92. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_base.rb +51 -0
  93. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_event.rb +36 -0
  94. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message.rb +97 -0
  95. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_message_exception.rb +65 -0
  96. data/lib/contrast/agent/telemetry/events/exceptions/telemetry_exception_stack_frame.rb +47 -0
  97. data/lib/contrast/agent/{metric_telemetry_event.rb → telemetry/events/metric_telemetry_event.rb} +1 -1
  98. data/lib/contrast/agent/{startup_metrics_telemetry_event.rb → telemetry/events/startup_metrics_telemetry_event.rb} +3 -3
  99. data/lib/contrast/agent/{telemetry_event.rb → telemetry/events/telemetry_event.rb} +1 -1
  100. data/lib/contrast/agent/{telemetry.rb → telemetry/telemetry.rb} +32 -19
  101. data/lib/contrast/agent/thread_watcher.rb +1 -1
  102. data/lib/contrast/agent/version.rb +1 -1
  103. data/lib/contrast/agent.rb +3 -0
  104. data/lib/contrast/api/communication/speedracer.rb +1 -1
  105. data/lib/contrast/api/decorators/address.rb +1 -1
  106. data/lib/contrast/api/decorators/response_type.rb +30 -0
  107. data/lib/contrast/api/decorators.rb +1 -0
  108. data/lib/contrast/components/app_context.rb +0 -4
  109. data/lib/contrast/components/assess.rb +14 -0
  110. data/lib/contrast/components/protect.rb +2 -2
  111. data/lib/contrast/components/sampling.rb +7 -11
  112. data/lib/contrast/components/settings.rb +106 -8
  113. data/lib/contrast/config/agent_configuration.rb +13 -30
  114. data/lib/contrast/config/api_configuration.rb +4 -67
  115. data/lib/contrast/config/api_proxy_configuration.rb +2 -45
  116. data/lib/contrast/config/application_configuration.rb +9 -84
  117. data/lib/contrast/config/assess_configuration.rb +10 -69
  118. data/lib/contrast/config/assess_rules_configuration.rb +9 -38
  119. data/lib/contrast/config/base_configuration.rb +17 -50
  120. data/lib/contrast/config/certification_configuration.rb +6 -63
  121. data/lib/contrast/config/exception_configuration.rb +5 -52
  122. data/lib/contrast/config/heap_dump_configuration.rb +6 -64
  123. data/lib/contrast/config/inventory_configuration.rb +2 -49
  124. data/lib/contrast/config/logger_configuration.rb +0 -36
  125. data/lib/contrast/config/protect_configuration.rb +17 -7
  126. data/lib/contrast/config/protect_rule_configuration.rb +12 -30
  127. data/lib/contrast/config/protect_rules_configuration.rb +21 -26
  128. data/lib/contrast/config/request_audit_configuration.rb +6 -48
  129. data/lib/contrast/config/root_configuration.rb +52 -12
  130. data/lib/contrast/config/ruby_configuration.rb +0 -36
  131. data/lib/contrast/config/sampling_configuration.rb +1 -57
  132. data/lib/contrast/config/server_configuration.rb +0 -36
  133. data/lib/contrast/config/service_configuration.rb +5 -44
  134. data/lib/contrast/configuration.rb +2 -3
  135. data/lib/contrast/extension/assess/string.rb +20 -1
  136. data/lib/contrast/extension/module.rb +0 -1
  137. data/lib/contrast/framework/manager.rb +2 -2
  138. data/lib/contrast/logger/application.rb +1 -1
  139. data/lib/contrast/logger/cef_log.rb +1 -1
  140. data/lib/contrast/tasks/config.rb +90 -3
  141. data/lib/contrast/utils/assess/object_store.rb +36 -0
  142. data/lib/contrast/utils/assess/propagation_method_utils.rb +6 -0
  143. data/lib/contrast/utils/class_util.rb +3 -12
  144. data/lib/contrast/utils/input_classification.rb +73 -0
  145. data/lib/contrast/utils/log_utils.rb +1 -1
  146. data/lib/contrast/utils/middleware_utils.rb +9 -8
  147. data/lib/contrast/utils/net_http_base.rb +1 -1
  148. data/lib/contrast/utils/object_share.rb +2 -1
  149. data/lib/contrast/utils/os.rb +0 -5
  150. data/lib/contrast/utils/patching/policy/patch_utils.rb +4 -5
  151. data/lib/contrast/utils/response_utils.rb +18 -33
  152. data/lib/contrast/utils/telemetry.rb +1 -1
  153. data/lib/contrast/utils/telemetry_client.rb +1 -1
  154. data/lib/contrast/utils/telemetry_identifier.rb +1 -1
  155. data/resources/assess/policy.json +98 -0
  156. data/resources/deadzone/policy.json +0 -86
  157. data/ruby-agent.gemspec +9 -8
  158. data/service_executables/VERSION +1 -1
  159. data/service_executables/linux/contrast-service +0 -0
  160. data/service_executables/mac/contrast-service +0 -0
  161. metadata +73 -28
@@ -8,76 +8,34 @@ module Contrast
8
8
  class RequestAuditConfiguration < BaseConfiguration
9
9
  DEFAULT_PATH = './messages'
10
10
 
11
+ attr_writer :enable, :requests, :responses, :path
12
+
11
13
  def initialize hsh = {}
12
14
  @enable = traverse_config(hsh, :enable)
13
15
  @requests = traverse_config(hsh, :requests)
14
16
  @responses = traverse_config(hsh, :responses)
15
17
  @path = traverse_config(hsh, :path)
16
- @configuration_map = {}
17
- build_configuration_map
18
18
  end
19
19
 
20
+ # @return [Boolean, false]
20
21
  def enable
21
22
  @enable.nil? ? false : @enable
22
23
  end
23
24
 
25
+ # @return [Boolean, false]
24
26
  def requests
25
27
  @requests.nil? ? false : @requests
26
28
  end
27
29
 
30
+ # @return [Boolean, false]
28
31
  def responses
29
32
  @responses.nil? ? false : @responses
30
33
  end
31
34
 
35
+ # @return [String, ::DEFAULT_PATH]
32
36
  def path
33
37
  @path.nil? ? DEFAULT_PATH : @path
34
38
  end
35
-
36
- def enable= value
37
- self['enable'] = value
38
- end
39
-
40
- def requests= value
41
- self['requests'] = value
42
- end
43
-
44
- def responses= value
45
- self['responses'] = value
46
- end
47
-
48
- def path= value
49
- self['path'] = value
50
- end
51
-
52
- # TODO: RUBY-1493 MOVE TO BASE CONFIG
53
-
54
- def []= key, value
55
- instance_variable_set("@#{ key }".to_sym, value)
56
- @configuration_map[key] = value
57
- end
58
-
59
- # Traverse the given entity to build out the configuration graph.
60
- #
61
- # The values will be either a hash, indicating internal nodes to
62
- # traverse, or a value to set or the EMPTY_VALUE symbol, indicating a
63
- # leaf node.
64
- #
65
- # The spec_key are the Contrast defined keys based on the instance variables of
66
- # a given configuration.
67
- def traverse_config values, spec_key
68
- internal_nodes = values.cs__respond_to?(:has_key?)
69
- val = internal_nodes ? value_from_key_config(spec_key, values) : nil
70
- val == EMPTY_VALUE ? nil : val
71
- end
72
-
73
- def build_configuration_map
74
- instance_variables.each do |key|
75
- str_key = key.to_s.tr('@', '')
76
- next if str_key == 'configuration_map'
77
-
78
- @configuration_map[str_key] = send(str_key.to_sym)
79
- end
80
- end
81
39
  end
82
40
  end
83
41
  end
@@ -5,22 +5,62 @@ module Contrast
5
5
  module Config
6
6
  # The base of the Common Configuration settings.
7
7
  class RootConfiguration < BaseConfiguration
8
- KEYS = {
9
- api: Contrast::Config::ApiConfiguration,
10
- enable: BaseConfiguration::EMPTY_VALUE,
11
- agent: Contrast::Config::AgentConfiguration,
12
- application: Contrast::Config::ApplicationConfiguration,
13
- server: Contrast::Config::ServerConfiguration,
14
- assess: Contrast::Config::AssessConfiguration,
15
- inventory: Contrast::Config::InventoryConfiguration,
16
- protect: Contrast::Config::ProtectConfiguration,
17
- service: Contrast::Config::ServiceConfiguration
18
- }.cs__freeze
8
+ attr_writer :api, :agent, :application, :server, :assess, :inventory, :protect, :service
9
+ # @return [Boolean, nil]
10
+ attr_accessor :enable
19
11
 
20
12
  def initialize hsh = {}
21
13
  raise ArgumentError, 'Expected a hash' unless hsh.is_a?(Hash)
22
14
 
23
- super(hsh, KEYS)
15
+ @api = Contrast::Config::ApiConfiguration.new(traverse_config(hsh, :api))
16
+ @enable = traverse_config(hsh, :enable)
17
+ @agent = Contrast::Config::AgentConfiguration.new(traverse_config(hsh, :agent))
18
+ @application = Contrast::Config::ApplicationConfiguration.new(traverse_config(hsh, :application))
19
+ @server = Contrast::Config::ServerConfiguration.new(traverse_config(hsh, :server))
20
+ @assess = Contrast::Config::AssessConfiguration.new(traverse_config(hsh, :assess))
21
+ @inventory = Contrast::Config::InventoryConfiguration.new(traverse_config(hsh, :inventory))
22
+ @protect = Contrast::Config::ProtectConfiguration.new(traverse_config(hsh, :protect))
23
+ @service = Contrast::Config::ServiceConfiguration.new(traverse_config(hsh, :service))
24
+ end
25
+
26
+ # @return [Contrast::Config::ApiConfiguration]
27
+ def api
28
+ @api ||= Contrast::Config::ApiConfiguration.new
29
+ end
30
+
31
+ # @return [Contrast::Config::AgentConfiguration]
32
+ def agent
33
+ @agent ||= Contrast::Config::AgentConfiguration.new
34
+ end
35
+
36
+ # @return [Contrast::Config::ApplicationConfiguration]
37
+ def application
38
+ @application ||= Contrast::Config::ApplicationConfiguration.new
39
+ end
40
+
41
+ # @return [Contrast::Config::ServerConfiguration]
42
+ def server
43
+ @server ||= Contrast::Config::ServerConfiguration.new
44
+ end
45
+
46
+ # @return [Contrast::Config::AssessConfiguration]
47
+ def assess
48
+ @assess ||= Contrast::Config::AssessConfiguration.new
49
+ end
50
+
51
+ # @return [Contrast::Config::InventoryConfiguration]
52
+ def inventory
53
+ @inventory ||= Contrast::Config::InventoryConfiguration.new
54
+ end
55
+
56
+ # @return [Contrast::Config::ProtectConfiguration]
57
+ def protect
58
+ @protect ||= Contrast::Config::ProtectConfiguration.new
59
+ end
60
+
61
+ # @return [Contrast::Config::ServiceConfiguration]
62
+ def service
63
+ @service ||= Contrast::Config::ServiceConfiguration.new
24
64
  end
25
65
  end
26
66
  end
@@ -31,8 +31,6 @@ module Contrast
31
31
  @track_frozen_sources = traverse_config(hsh, :track_frozen_sources)
32
32
  @non_request_tracking = traverse_config(hsh, :non_request_tracking)
33
33
  @uninstrument_namespace = traverse_config(hsh, :uninstrument_namespace)
34
- @configuration_map = {}
35
- build_configuration_map
36
34
  end
37
35
 
38
36
  # These commands being detected will result the agent disabling instrumentation, generally any command
@@ -82,40 +80,6 @@ module Contrast
82
80
  def uninstrument_namespace
83
81
  @uninstrument_namespace.nil? ? DEFAULT_UNINSTRUMENTED_NAMESPACES : @uninstrument_namespace
84
82
  end
85
-
86
- # TODO: RUBY-1493 MOVE TO BASE CONFIG
87
-
88
- def []= key, value
89
- instance_variable_set("@#{ key }".to_sym, value)
90
- @configuration_map[key] = value
91
- end
92
-
93
- def [] key
94
- send(key.to_sym)
95
- end
96
-
97
- # Traverse the given entity to build out the configuration graph.
98
- #
99
- # The values will be either a hash, indicating internal nodes to
100
- # traverse, or a value to set or the EMPTY_VALUE symbol, indicating a
101
- # leaf node.
102
- #
103
- # The spec_key are the Contrast defined keys based on the instance variables of
104
- # a given configuration.
105
- def traverse_config values, spec_key
106
- internal_nodes = values.cs__respond_to?(:has_key?)
107
- val = internal_nodes ? value_from_key_config(spec_key, values) : nil
108
- val == EMPTY_VALUE ? nil : val
109
- end
110
-
111
- def build_configuration_map
112
- instance_variables.each do |key|
113
- str_key = key.to_s.tr('@', '')
114
- next if str_key == 'configuration_map'
115
-
116
- @configuration_map[str_key] = send(str_key.to_sym)
117
- end
118
- end
119
83
  end
120
84
  end
121
85
  end
@@ -21,67 +21,11 @@ module Contrast
21
21
  @request_frequency = traverse_config(hsh, :request_frequency)
22
22
  @response_frequency = traverse_config(hsh, :response_frequency)
23
23
  @window_ms = traverse_config(hsh, :window_ms)
24
- @configuration_map = {}
25
- build_configuration_map
26
24
  end
27
25
 
28
26
  # @return [Boolean, false]
29
27
  def enable
30
- @enable.nil? ? false : @enable
31
- end
32
-
33
- def enable= value
34
- self['enable'] = value
35
- end
36
-
37
- def baseline= value
38
- self['baseline'] = value
39
- end
40
-
41
- def request_frequency= value
42
- self['request_frequency'] = value
43
- end
44
-
45
- def response_frequency= value
46
- self['response_frequency'] = value
47
- end
48
-
49
- def window_ms= value
50
- self['window_ms'] = value
51
- end
52
-
53
- # TODO: RUBY-1493 MOVE TO BASE CONFIG
54
-
55
- def []= key, value
56
- instance_variable_set("@#{ key }".to_sym, value)
57
- @configuration_map[key] = value
58
- end
59
-
60
- def [] key
61
- send(key.to_sym)
62
- end
63
-
64
- # Traverse the given entity to build out the configuration graph.
65
- #
66
- # The values will be either a hash, indicating internal nodes to
67
- # traverse, or a value to set or the EMPTY_VALUE symbol, indicating a
68
- # leaf node.
69
- #
70
- # The spec_key are the Contrast defined keys based on the instance variables of
71
- # a given configuration.
72
- def traverse_config values, spec_key
73
- internal_nodes = values.cs__respond_to?(:has_key?)
74
- val = internal_nodes ? value_from_key_config(spec_key, values) : nil
75
- val == EMPTY_VALUE ? nil : val
76
- end
77
-
78
- def build_configuration_map
79
- instance_variables.each do |key|
80
- str_key = key.to_s.tr('@', '')
81
- next if str_key == 'configuration_map'
82
-
83
- @configuration_map[str_key] = send(str_key.to_sym)
84
- end
28
+ !!@enable
85
29
  end
86
30
  end
87
31
  end
@@ -26,42 +26,6 @@ module Contrast
26
26
  @tags = traverse_config(hsh, :tags)
27
27
  @environment = traverse_config(hsh, :environment)
28
28
  @version = traverse_config(hsh, :version)
29
- @configuration_map = {}
30
- build_configuration_map
31
- end
32
-
33
- # TODO: RUBY-1493 MOVE TO BASE CONFIG
34
-
35
- def []= key, value
36
- instance_variable_set("@#{ key }".to_sym, value)
37
- @configuration_map[key] = value
38
- end
39
-
40
- def [] key
41
- send(key.to_sym)
42
- end
43
-
44
- # Traverse the given entity to build out the configuration graph.
45
- #
46
- # The values will be either a hash, indicating internal nodes to
47
- # traverse, or a value to set or the EMPTY_VALUE symbol, indicating a
48
- # leaf node.
49
- #
50
- # The spec_key are the Contrast defined keys based on the instance variables of
51
- # a given configuration.
52
- def traverse_config values, spec_key
53
- internal_nodes = values.cs__respond_to?(:has_key?)
54
- val = internal_nodes ? value_from_key_config(spec_key, values) : nil
55
- val == EMPTY_VALUE ? nil : val
56
- end
57
-
58
- def build_configuration_map
59
- instance_variables.each do |key|
60
- str_key = key.to_s.tr('@', '')
61
- next if str_key == 'configuration_map'
62
-
63
- @configuration_map[str_key] = send(str_key.to_sym)
64
- end
65
29
  end
66
30
  end
67
31
  end
@@ -10,16 +10,18 @@ module Contrast
10
10
  class ServiceConfiguration < BaseConfiguration
11
11
  # We don't set these b/c we've been asked to handle the default values of
12
12
  # these settings differently, logging when we have to use them.
13
- DEFAULT_HOST = '127.0.0.1'
13
+ DEFAULT_HOST = '127.0.0.1' # rubocop:disable Style/IpAddresses
14
14
  DEFAULT_PORT = '30555'
15
15
 
16
- attr_writer :enable, :logger, :bypass
16
+ attr_writer :logger, :bypass
17
17
  # @return [String, nil]
18
18
  attr_accessor :socket
19
19
  # @return [String, nil]
20
20
  attr_accessor :port
21
21
  # @return [String, nil]
22
22
  attr_accessor :host
23
+ # @return [Boolean, nil]
24
+ attr_accessor :enable
23
25
 
24
26
  def initialize hsh = {}
25
27
  @enable = traverse_config(hsh, :enable)
@@ -28,13 +30,6 @@ module Contrast
28
30
  @socket = traverse_config(hsh, :socket)
29
31
  @logger = Contrast::Config::LoggerConfiguration.new(traverse_config(hsh, :logger))
30
32
  @bypass = traverse_config(hsh, :bypass)
31
- @configuration_map = {}
32
- build_configuration_map
33
- end
34
-
35
- # @return [Boolean, false]
36
- def enable
37
- !!@enable
38
33
  end
39
34
 
40
35
  # @return [Contrast::Config::LoggerConfiguration]
@@ -44,41 +39,7 @@ module Contrast
44
39
 
45
40
  # @return [Boolean, false]
46
41
  def bypass
47
- !!@bypass
48
- end
49
-
50
- # TODO: RUBY-1493 MOVE TO BASE CONFIG
51
-
52
- def []= key, value
53
- instance_variable_set("@#{ key }".to_sym, value)
54
- @configuration_map[key] = value
55
- end
56
-
57
- def [] key
58
- send(key.to_sym)
59
- end
60
-
61
- # Traverse the given entity to build out the configuration graph.
62
- #
63
- # The values will be either a hash, indicating internal nodes to
64
- # traverse, or a value to set or the EMPTY_VALUE symbol, indicating a
65
- # leaf node.
66
- #
67
- # The spec_key are the Contrast defined keys based on the instance variables of
68
- # a given configuration.
69
- def traverse_config values, spec_key
70
- internal_nodes = values.cs__respond_to?(:has_key?)
71
- val = internal_nodes ? value_from_key_config(spec_key, values) : nil
72
- val == EMPTY_VALUE ? nil : val
73
- end
74
-
75
- def build_configuration_map
76
- instance_variables.each do |key|
77
- str_key = key.to_s.tr('@', '')
78
- next if str_key == 'configuration_map'
79
-
80
- @configuration_map[str_key] = send(str_key.to_sym)
81
- end
42
+ @bypass.nil? ? false : @bypass
82
43
  end
83
44
  end
84
45
  end
@@ -221,9 +221,8 @@ module Contrast
221
221
  convert.to_hash.each_key do |key|
222
222
  next if Contrast::Utils::ExcludeKey.excludable?(key.to_s)
223
223
 
224
- # keys can contain '-' but methods getters cannot
225
- # clean_key = key.to_s.tr('-', '_')
226
- hash[key] = convert_to_hash(convert.send(key.to_sym), {})
224
+ # change '-' to '_' for ProtectRulesConfiguration
225
+ hash[key] = convert_to_hash(convert.send(key.tr('-', '_').to_sym), {})
227
226
  end
228
227
  hash
229
228
  else
@@ -13,7 +13,7 @@ module Contrast
13
13
  # methods which are too complex to fit into one of the standard
14
14
  # Contrast::Agent::Assess::Policy::Propagator molds without cluttering up the
15
15
  # String Class or exposing our methods there.
16
- class StringPropagator # rubocop:disable Style/StaticClass
16
+ class StringPropagator
17
17
  extend Contrast::Components::Logger::InstanceMethods
18
18
  extend Contrast::Components::Scope::InstanceMethods
19
19
 
@@ -43,6 +43,7 @@ module Contrast
43
43
  offset = 0
44
44
  inputs.each do |input|
45
45
  properties.copy_from(input, result, offset)
46
+ add_dynamic_sources_info input, result
46
47
  offset += input.length
47
48
  parent_event = Contrast::Agent::Assess::Tracker.properties(input)&.event
48
49
  parent_events << parent_event if parent_event
@@ -58,6 +59,24 @@ module Contrast
58
59
  rescue StandardError => e
59
60
  logger.error('Unable to track interpolation', e)
60
61
  end
62
+
63
+ private
64
+
65
+ # When there is a string interpolation on input coming from tainted database,
66
+ # the Contrast::Agent::Assess::Properties::Updated.copy_from method won't copy
67
+ # the dynamic source properties needed in the build findings from TS to display
68
+ # the column and Table information as database source information.
69
+ #
70
+ # @param source [Object] the source object with the required properties.
71
+ # @param target [Object] the result form the interpolation and the object
72
+ # that needs to keep the source properties, in order to be reporter on
73
+ # trigger event.
74
+ # @return updated_properties [Hash<DynamicSourceInfo>, nil]
75
+ def add_dynamic_sources_info source, target
76
+ return unless (dynamic_props = Contrast::Agent::Assess::Tracker.properties(source)&.properties)
77
+
78
+ Contrast::Agent::Assess::Tracker.properties(target)&.add_properties(dynamic_props)
79
+ end
61
80
  end
62
81
  end
63
82
  end
@@ -13,5 +13,4 @@ class Module
13
13
  alias_method :cs__const_defined?, :const_defined?
14
14
  alias_method :cs__const_get, :const_get
15
15
  alias_method :cs__const_set, :const_set
16
- alias_method :cs__autoload?, :autoload?
17
16
  end
@@ -125,7 +125,7 @@ module Contrast
125
125
  # @return [Contrast::Api::Dtm::RouteCoverage] the current route as a Dtm.
126
126
  def get_route_dtm request
127
127
  @_frameworks.lazy.map { |framework_support| framework_support.current_route(request) }.
128
- reject(&:nil?).first
128
+ reject(&:nil?).first # rubocop:disable Style/CollectionCompact
129
129
  end
130
130
 
131
131
  # Iterate through current frameworks and return the current request's route. This will be the first non-nil
@@ -135,7 +135,7 @@ module Contrast
135
135
  # @return [Contrast::Agent::Reporting::RouteCoverage] the current route as a Dtm.
136
136
  def get_route_information request
137
137
  @_frameworks.lazy.map { |framework_support| framework_support.current_route_coverage(request) }.
138
- reject(&:nil?).first
138
+ reject(&:nil?).first # rubocop:disable Style/CollectionCompact
139
139
  end
140
140
 
141
141
  # Sometimes the framework we want to instrument is loaded after our agent code. To catch that case, we'll detect
@@ -19,7 +19,7 @@ module Contrast
19
19
  env_key = env_key.to_s
20
20
  next unless ENV_KEYS.include?(env_key) ||
21
21
  (env_key.start_with?(Contrast::Components::Config::CONTRAST_ENV_MARKER) &&
22
- !env_key.start_with?(Contrast::Components::Config::CONTRAST_ENV_MARKER + 'API'))
22
+ !env_key.start_with?("#{ Contrast::Components::Config::CONTRAST_ENV_MARKER }API"))
23
23
 
24
24
  info('Environment settings', key: env_key, value: env_value)
25
25
  end
@@ -142,7 +142,7 @@ module Contrast
142
142
  "as suspicious using #{ rule_id } - #{ input_value }"
143
143
  log [suspicious_attack_with, rule_id, outcome], ::Logger::WARN
144
144
  elsif input_value.present?
145
- suspicious_attack_without = 'Suspicious activity indicates a potential attack using ' + rule_id.to_s
145
+ suspicious_attack_without = "Suspicious activity indicates a potential attack using #{ rule_id }"
146
146
  log [suspicious_attack_without, rule_id, outcome], ::Logger::WARN
147
147
  end
148
148
  end
@@ -2,6 +2,8 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'yaml'
5
+ require 'contrast/configuration'
6
+ require 'contrast/agent/reporting/reporter'
5
7
 
6
8
  module Contrast
7
9
  # A Rake task to generate a contrast_security.yaml file with some basic settings
@@ -29,6 +31,8 @@ module Contrast
29
31
  }
30
32
  }.cs__freeze
31
33
 
34
+ SKIP_LOG = %w[service_key api_key].cs__freeze
35
+
32
36
  namespace :contrast do
33
37
  namespace :config do
34
38
  desc 'Create a contrast_security.yaml in the applications root directory'
@@ -38,9 +42,7 @@ module Contrast
38
42
  if File.exist?(target_path)
39
43
  puts 'WARNING: contrast_security.yaml already exists'
40
44
  else
41
- File.open(target_path, 'w') do |f|
42
- f.write(YAML.dump(DEFAULT_CONFIG))
43
- end
45
+ File.write(target_path, YAML.dump(DEFAULT_CONFIG))
44
46
 
45
47
  puts "Created contrast_security.yaml at #{ target_path }"
46
48
  puts 'Open the file and enter your Contrast Security api keys or set them via environment variables'
@@ -49,5 +51,90 @@ module Contrast
49
51
  end
50
52
  end
51
53
  end
54
+
55
+ namespace :contrast do
56
+ namespace :config do
57
+ desc 'Validate the provided Contrast configuration and confirm connectivity'
58
+ task validate: :environment do
59
+ puts 'Validating Agent Configuration...'
60
+ Contrast::Config.validate_config
61
+ puts '...done!'
62
+ puts 'Validating Contrast Reporter Headers...'
63
+ reporter = Contrast::Config.validate_headers
64
+ puts '...done!'
65
+ puts 'Testing Client Connection...'
66
+ Contrast::Config.test_connection(reporter) if reporter
67
+ puts '...done!'
68
+ end
69
+ end
70
+ def self.validate_config # rubocop:disable Metrics/PerceivedComplexity
71
+ config = Contrast::Configuration.new
72
+ abort('Unable to Build Config') unless config
73
+
74
+ required = %i[url api_key service_key user_name]
75
+
76
+ missing = []
77
+ config.root.api.each do |key, value|
78
+ puts "#{ key }::#{ value }" unless value.is_a?(Contrast::Config::BaseConfiguration) || SKIP_LOG.includes?(key)
79
+ if value.is_a?(Contrast::Config::ApiProxyConfiguration)
80
+ Contrast::Config.validate_proxy(value)
81
+ elsif value.is_a?(Contrast::Config::CertificationConfiguration)
82
+ Contrast::Config.validate_cert(value)
83
+ next
84
+ elsif value.is_a?(Contrast::Config::RequestAuditConfiguration)
85
+ Contrast::Config.validate_audit(value)
86
+ next
87
+ elsif value == Contrast::Config::BaseConfiguration::EMPTY_VALUE && required.includes?(key.to_sym)
88
+ missing << key
89
+ end
90
+ end
91
+ abort("Missing required API configuration values: #{ missing.join(', ') }") unless missing.empty?
92
+ end
93
+
94
+ def self.validate_proxy config
95
+ puts "Proxy Enabled: #{ config.enable }"
96
+ return unless config.enable
97
+
98
+ puts "Proxy URL: #{ config.url }"
99
+ abort('Proxy Enabled but no Proxy URL given') unless config.url
100
+ end
101
+
102
+ def self.validate_cert config
103
+ puts "Certification Enabled: #{ config.enable }"
104
+ return unless config.enable
105
+
106
+ puts "CA File: #{ config.ca_file }"
107
+ abort('CA file path not provided') unless config.ca_file
108
+ puts "Cert File: #{ config.cert_file }"
109
+ abort('Cert file path not provided') unless config.cert_file
110
+ puts "Key File: #{ config.key_file }"
111
+ abort('Key file path not provided') unless config.key_file
112
+ end
113
+
114
+ def self.validate_audit config
115
+ puts "Request Audit Enabled: #{ config.enable }"
116
+ return unless config.enable
117
+
118
+ config.each do |k, v|
119
+ puts "#{ k }::#{ v }"
120
+ end
121
+ end
122
+
123
+ def self.validate_headers
124
+ missing = []
125
+ reporter = Contrast::Agent::Reporter.new
126
+ reporter.client.headers.to_hash.each_pair do |key, value|
127
+ puts "#{ key }::#{ value }"
128
+ missing << key if value.nil?
129
+ end
130
+ abort("Missing required header values: #{ missing.join(', ') }") unless missing.empty?
131
+ reporter
132
+ end
133
+
134
+ def self.test_connection reporter
135
+ abort('Failed to Initialize Connection please check error logs for details') unless reporter.connection
136
+ abort('Failed to Start Client please check error logs for details') unless reporter.client.startup!
137
+ end
138
+ end
52
139
  end
53
140
  end
@@ -0,0 +1,36 @@
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 Utils
6
+ module Assess
7
+ # keep track of object properties and events data
8
+ class ObjectStore
9
+ def initialize capacity = 500
10
+ @capacity = capacity
11
+ @cache = {}
12
+ end
13
+
14
+ def get
15
+ @cache
16
+ end
17
+
18
+ def [] key
19
+ @cache[key]
20
+ end
21
+
22
+ def delete key
23
+ @cache.delete(key)
24
+ end
25
+
26
+ # We would keep object ids with capacity.
27
+ # If a reference is kept to an object only by it's id,
28
+ # It would be CG-ted safely.
29
+ def []= key, value
30
+ @cache[key] = value
31
+ @cache.shift if @cache.length > @capacity
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -10,6 +10,7 @@ module Contrast
10
10
  APPEND_ACTION = 'APPEND'
11
11
  CENTER_ACTION = 'CENTER'
12
12
  INSERT_ACTION = 'INSERT'
13
+ BUFFER_ACTION = 'BUFFER'
13
14
  KEEP_ACTION = 'KEEP'
14
15
  NEXT_ACTION = 'NEXT'
15
16
  NOOP_ACTION = 'NOOP'
@@ -30,6 +31,7 @@ module Contrast
30
31
  INSERT_ACTION => Contrast::Agent::Assess::Policy::Propagator::Insert,
31
32
  KEEP_ACTION => Contrast::Agent::Assess::Policy::Propagator::Keep,
32
33
  NEXT_ACTION => Contrast::Agent::Assess::Policy::Propagator::Next,
34
+ BUFFER_ACTION => Contrast::Agent::Assess::Policy::Propagator::Buffer,
33
35
  NOOP_ACTION => nil,
34
36
  PREPEND_ACTION => Contrast::Agent::Assess::Policy::Propagator::Prepend,
35
37
  REPLACE_ACTION => Contrast::Agent::Assess::Policy::Propagator::Replace,
@@ -94,6 +96,10 @@ module Contrast
94
96
  def can_propagate? propagation_node, preshift, target
95
97
  return false unless appropriate_target?(propagation_node, target)
96
98
  return true if Contrast::Utils::Assess::TrackingUtil.tracked?(target)
99
+ if propagation_node.use_original_object?
100
+ # return true since we don't have preshift while using the original object.
101
+ return true
102
+ end
97
103
  return false unless preshift
98
104
 
99
105
  propagation_node.sources.each do |source|