contrast-agent 3.13.0 → 3.16.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (241) hide show
  1. checksums.yaml +4 -4
  2. data/exe/contrast_service +1 -7
  3. data/ext/cs__assess_active_record_named/cs__active_record_named.c +8 -7
  4. data/ext/cs__assess_array/cs__assess_array.c +6 -5
  5. data/ext/cs__assess_basic_object/cs__assess_basic_object.c +5 -5
  6. data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +2 -1
  7. data/ext/cs__assess_hash/cs__assess_hash.c +18 -17
  8. data/ext/cs__assess_hash/cs__assess_hash.h +2 -1
  9. data/ext/cs__assess_kernel/cs__assess_kernel.c +7 -8
  10. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +18 -16
  11. data/ext/cs__assess_marshal_module/cs__assess_marshal_module.h +1 -0
  12. data/ext/cs__assess_module/cs__assess_module.c +6 -6
  13. data/ext/cs__assess_regexp/cs__assess_regexp.c +4 -4
  14. data/ext/cs__assess_string/cs__assess_string.c +31 -16
  15. data/ext/cs__assess_string/cs__assess_string.h +6 -1
  16. data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +4 -2
  17. data/ext/cs__assess_yield_track/cs__assess_yield_track.c +2 -2
  18. data/ext/cs__common/cs__common.c +48 -39
  19. data/ext/cs__common/cs__common.h +16 -21
  20. data/ext/cs__contrast_patch/cs__contrast_patch.c +27 -25
  21. data/ext/cs__contrast_patch/cs__contrast_patch.h +5 -7
  22. data/ext/cs__protect_kernel/cs__protect_kernel.c +11 -12
  23. data/ext/cs__protect_kernel/cs__protect_kernel.h +2 -2
  24. data/lib/contrast-agent.rb +1 -1
  25. data/lib/contrast.rb +13 -23
  26. data/lib/contrast/agent.rb +39 -46
  27. data/lib/contrast/agent/assess.rb +12 -12
  28. data/lib/contrast/agent/assess/contrast_event.rb +151 -85
  29. data/lib/contrast/agent/assess/events/event_factory.rb +2 -2
  30. data/lib/contrast/agent/assess/events/source_event.rb +3 -3
  31. data/lib/contrast/agent/assess/finalizers/freeze.rb +15 -0
  32. data/lib/contrast/agent/assess/finalizers/hash.rb +97 -0
  33. data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +11 -4
  34. data/lib/contrast/agent/assess/policy/patcher.rb +6 -6
  35. data/lib/contrast/agent/assess/policy/policy.rb +9 -11
  36. data/lib/contrast/agent/assess/policy/policy_node.rb +17 -12
  37. data/lib/contrast/agent/assess/policy/policy_scanner.rb +9 -4
  38. data/lib/contrast/agent/assess/policy/preshift.rb +13 -7
  39. data/lib/contrast/agent/assess/policy/propagation_method.rb +64 -44
  40. data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -2
  41. data/lib/contrast/agent/assess/policy/propagator.rb +18 -18
  42. data/lib/contrast/agent/assess/policy/propagator/append.rb +8 -5
  43. data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
  44. data/lib/contrast/agent/assess/policy/propagator/center.rb +9 -5
  45. data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
  46. data/lib/contrast/agent/assess/policy/propagator/database_write.rb +6 -4
  47. data/lib/contrast/agent/assess/policy/propagator/insert.rb +7 -4
  48. data/lib/contrast/agent/assess/policy/propagator/keep.rb +4 -1
  49. data/lib/contrast/agent/assess/policy/propagator/match_data.rb +7 -9
  50. data/lib/contrast/agent/assess/policy/propagator/next.rb +7 -5
  51. data/lib/contrast/agent/assess/policy/propagator/prepend.rb +13 -5
  52. data/lib/contrast/agent/assess/policy/propagator/remove.rb +8 -4
  53. data/lib/contrast/agent/assess/policy/propagator/replace.rb +5 -2
  54. data/lib/contrast/agent/assess/policy/propagator/reverse.rb +7 -5
  55. data/lib/contrast/agent/assess/policy/propagator/select.rb +13 -7
  56. data/lib/contrast/agent/assess/policy/propagator/splat.rb +10 -9
  57. data/lib/contrast/agent/assess/policy/propagator/split.rb +27 -22
  58. data/lib/contrast/agent/assess/policy/propagator/substitution.rb +52 -35
  59. data/lib/contrast/agent/assess/policy/propagator/trim.rb +11 -5
  60. data/lib/contrast/agent/assess/policy/rewriter_patch.rb +5 -5
  61. data/lib/contrast/agent/assess/policy/source_method.rb +90 -72
  62. data/lib/contrast/agent/assess/policy/source_validation/cross_site_validator.rb +1 -1
  63. data/lib/contrast/agent/assess/policy/source_validation/source_validation.rb +1 -1
  64. data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +16 -12
  65. data/lib/contrast/agent/assess/policy/trigger/xpath.rb +2 -2
  66. data/lib/contrast/agent/assess/policy/trigger_method.rb +81 -33
  67. data/lib/contrast/agent/assess/policy/trigger_node.rb +41 -46
  68. data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -1
  69. data/lib/contrast/agent/assess/policy/trigger_validation/trigger_validation.rb +2 -2
  70. data/lib/contrast/agent/assess/properties.rb +15 -5
  71. data/lib/contrast/agent/assess/property/evented.rb +7 -20
  72. data/lib/contrast/agent/assess/property/tagged.rb +13 -7
  73. data/lib/contrast/agent/assess/property/updated.rb +131 -0
  74. data/lib/contrast/agent/assess/rule.rb +2 -2
  75. data/lib/contrast/agent/assess/rule/base.rb +3 -4
  76. data/lib/contrast/agent/assess/rule/provider.rb +3 -3
  77. data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +58 -5
  78. data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +24 -9
  79. data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +84 -16
  80. data/lib/contrast/agent/assess/tag.rb +1 -1
  81. data/lib/contrast/agent/assess/tracker.rb +66 -0
  82. data/lib/contrast/agent/at_exit_hook.rb +6 -6
  83. data/lib/contrast/agent/class_reopener.rb +14 -11
  84. data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +1 -1
  85. data/lib/contrast/agent/deadzone/policy/policy.rb +2 -2
  86. data/lib/contrast/agent/disable_reaction.rb +1 -1
  87. data/lib/contrast/agent/exclusion_matcher.rb +1 -1
  88. data/lib/contrast/agent/inventory/policy/datastores.rb +2 -2
  89. data/lib/contrast/agent/inventory/policy/policy.rb +3 -3
  90. data/lib/contrast/agent/inventory/policy/trigger_node.rb +1 -1
  91. data/lib/contrast/agent/middleware.rb +32 -32
  92. data/lib/contrast/agent/patching/policy/after_load_patch.rb +9 -9
  93. data/lib/contrast/agent/patching/policy/after_load_patcher.rb +23 -22
  94. data/lib/contrast/agent/patching/policy/module_policy.rb +11 -11
  95. data/lib/contrast/agent/patching/policy/patch.rb +15 -15
  96. data/lib/contrast/agent/patching/policy/patcher.rb +43 -44
  97. data/lib/contrast/agent/patching/policy/policy.rb +23 -12
  98. data/lib/contrast/agent/patching/policy/policy_node.rb +1 -1
  99. data/lib/contrast/agent/patching/policy/trigger_node.rb +2 -2
  100. data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +6 -8
  101. data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +2 -2
  102. data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -2
  103. data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +3 -3
  104. data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +2 -2
  105. data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +4 -4
  106. data/lib/contrast/agent/protect/policy/policy.rb +8 -8
  107. data/lib/contrast/agent/protect/policy/rule_applicator.rb +1 -1
  108. data/lib/contrast/agent/protect/policy/trigger_node.rb +1 -1
  109. data/lib/contrast/agent/protect/rule.rb +18 -18
  110. data/lib/contrast/agent/protect/rule/base.rb +4 -3
  111. data/lib/contrast/agent/protect/rule/base_service.rb +1 -1
  112. data/lib/contrast/agent/protect/rule/cmd_injection.rb +5 -5
  113. data/lib/contrast/agent/protect/rule/deserialization.rb +1 -1
  114. data/lib/contrast/agent/protect/rule/http_method_tampering.rb +1 -1
  115. data/lib/contrast/agent/protect/rule/no_sqli.rb +1 -1
  116. data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +1 -0
  117. data/lib/contrast/agent/protect/rule/path_traversal.rb +4 -5
  118. data/lib/contrast/agent/protect/rule/sqli.rb +2 -2
  119. data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +1 -1
  120. data/lib/contrast/agent/protect/rule/xss.rb +1 -1
  121. data/lib/contrast/agent/protect/rule/xxe.rb +3 -5
  122. data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +2 -2
  123. data/lib/contrast/agent/railtie.rb +1 -1
  124. data/lib/contrast/agent/reaction_processor.rb +2 -2
  125. data/lib/contrast/agent/request.rb +45 -43
  126. data/lib/contrast/agent/request_context.rb +10 -6
  127. data/lib/contrast/agent/response.rb +23 -12
  128. data/lib/contrast/agent/rewriter.rb +6 -9
  129. data/lib/contrast/agent/service_heartbeat.rb +2 -2
  130. data/lib/contrast/agent/static_analysis.rb +9 -9
  131. data/lib/contrast/agent/thread.rb +1 -1
  132. data/lib/contrast/agent/thread_watcher.rb +2 -2
  133. data/lib/contrast/agent/tracepoint_hook.rb +1 -1
  134. data/lib/contrast/agent/version.rb +1 -1
  135. data/lib/contrast/api.rb +4 -4
  136. data/lib/contrast/api/communication.rb +9 -9
  137. data/lib/contrast/api/communication/messaging_queue.rb +3 -6
  138. data/lib/contrast/api/communication/response_processor.rb +1 -1
  139. data/lib/contrast/api/communication/socket_client.rb +41 -6
  140. data/lib/contrast/api/communication/speedracer.rb +1 -1
  141. data/lib/contrast/api/communication/tcp_socket.rb +1 -1
  142. data/lib/contrast/api/communication/unix_socket.rb +1 -1
  143. data/lib/contrast/api/decorators.rb +14 -14
  144. data/lib/contrast/api/decorators/address.rb +20 -19
  145. data/lib/contrast/api/decorators/application_settings.rb +3 -2
  146. data/lib/contrast/api/decorators/application_update.rb +7 -8
  147. data/lib/contrast/api/decorators/http_request.rb +13 -12
  148. data/lib/contrast/api/decorators/input_analysis.rb +3 -2
  149. data/lib/contrast/api/decorators/message.rb +4 -2
  150. data/lib/contrast/api/decorators/rasp_rule_sample.rb +2 -1
  151. data/lib/contrast/api/decorators/route_coverage.rb +3 -2
  152. data/lib/contrast/api/decorators/server_features.rb +3 -2
  153. data/lib/contrast/api/decorators/trace_event.rb +28 -25
  154. data/lib/contrast/api/decorators/trace_event_object.rb +6 -5
  155. data/lib/contrast/api/decorators/trace_event_signature.rb +5 -4
  156. data/lib/contrast/api/decorators/trace_taint_range.rb +4 -3
  157. data/lib/contrast/api/decorators/user_input.rb +4 -4
  158. data/lib/contrast/common_agent_configuration.rb +2 -2
  159. data/lib/contrast/components/agent.rb +2 -2
  160. data/lib/contrast/components/app_context.rb +50 -39
  161. data/lib/contrast/components/config.rb +7 -17
  162. data/lib/contrast/components/contrast_service.rb +10 -10
  163. data/lib/contrast/components/interface.rb +15 -15
  164. data/lib/contrast/components/logger.rb +1 -1
  165. data/lib/contrast/components/scope.rb +3 -3
  166. data/lib/contrast/components/settings.rb +20 -23
  167. data/lib/contrast/config.rb +18 -18
  168. data/lib/contrast/config/application_configuration.rb +5 -2
  169. data/lib/contrast/config/base_configuration.rb +2 -2
  170. data/lib/contrast/config/protect_rule_configuration.rb +1 -1
  171. data/lib/contrast/config/service_configuration.rb +8 -0
  172. data/lib/contrast/configuration.rb +93 -52
  173. data/lib/contrast/extension/assess.rb +21 -22
  174. data/lib/contrast/extension/assess/array.rb +18 -11
  175. data/lib/contrast/extension/assess/erb.rb +11 -3
  176. data/lib/contrast/extension/assess/eval_trigger.rb +7 -7
  177. data/lib/contrast/extension/assess/exec_trigger.rb +2 -2
  178. data/lib/contrast/extension/assess/fiber.rb +14 -14
  179. data/lib/contrast/extension/assess/hash.rb +7 -6
  180. data/lib/contrast/extension/assess/kernel.rb +34 -28
  181. data/lib/contrast/extension/assess/marshal.rb +67 -0
  182. data/lib/contrast/extension/assess/regexp.rb +10 -9
  183. data/lib/contrast/extension/assess/string.rb +23 -23
  184. data/lib/contrast/extension/inventory.rb +4 -4
  185. data/lib/contrast/extension/kernel.rb +1 -1
  186. data/lib/contrast/extension/module.rb +1 -1
  187. data/lib/contrast/extension/protect.rb +3 -3
  188. data/lib/contrast/extension/protect/kernel.rb +4 -4
  189. data/lib/contrast/extension/protect/psych.rb +2 -2
  190. data/lib/contrast/framework/base_support.rb +1 -1
  191. data/lib/contrast/framework/manager.rb +10 -11
  192. data/lib/contrast/framework/rack/patch/session_cookie.rb +22 -28
  193. data/lib/contrast/framework/rack/patch/support.rb +1 -1
  194. data/lib/contrast/framework/rack/support.rb +2 -2
  195. data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +13 -13
  196. data/lib/contrast/framework/rails/patch/assess_configuration.rb +6 -12
  197. data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +11 -11
  198. data/lib/contrast/framework/rails/patch/support.rb +4 -4
  199. data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +11 -11
  200. data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +12 -12
  201. data/lib/contrast/framework/rails/rewrite/active_record_named.rb +4 -4
  202. data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +12 -12
  203. data/lib/contrast/framework/rails/support.rb +64 -14
  204. data/lib/contrast/framework/sinatra/patch/base.rb +12 -12
  205. data/lib/contrast/framework/sinatra/patch/support.rb +1 -1
  206. data/lib/contrast/framework/sinatra/support.rb +6 -6
  207. data/lib/contrast/funchook/funchook.rb +1 -1
  208. data/lib/contrast/logger/application.rb +13 -5
  209. data/lib/contrast/logger/format.rb +22 -9
  210. data/lib/contrast/logger/log.rb +17 -10
  211. data/lib/contrast/logger/request.rb +30 -0
  212. data/lib/contrast/tasks/config.rb +1 -1
  213. data/lib/contrast/tasks/service.rb +2 -2
  214. data/lib/contrast/utils/assess/sampling_util.rb +2 -2
  215. data/lib/contrast/utils/assess/tracking_util.rb +49 -4
  216. data/lib/contrast/utils/boolean_util.rb +1 -1
  217. data/lib/contrast/utils/class_util.rb +2 -2
  218. data/lib/contrast/utils/duck_utils.rb +0 -10
  219. data/lib/contrast/utils/env_configuration_item.rb +2 -1
  220. data/lib/contrast/utils/gemfile_reader.rb +5 -5
  221. data/lib/contrast/utils/hash_digest.rb +2 -1
  222. data/lib/contrast/utils/heap_dump_util.rb +2 -2
  223. data/lib/contrast/utils/invalid_configuration_util.rb +21 -22
  224. data/lib/contrast/utils/inventory_util.rb +4 -4
  225. data/lib/contrast/utils/io_util.rb +1 -1
  226. data/lib/contrast/utils/os.rb +1 -1
  227. data/lib/contrast/utils/ruby_ast_rewriter.rb +1 -1
  228. data/lib/contrast/utils/sha256_builder.rb +2 -2
  229. data/lib/contrast/utils/stack_trace_utils.rb +2 -2
  230. data/lib/contrast/utils/string_utils.rb +11 -6
  231. data/resources/assess/policy.json +31 -22
  232. data/resources/deadzone/policy.json +5 -0
  233. data/ruby-agent.gemspec +21 -19
  234. data/service_executables/VERSION +1 -1
  235. data/service_executables/linux/contrast-service +0 -0
  236. data/service_executables/mac/contrast-service +0 -0
  237. metadata +67 -29
  238. data/lib/contrast/agent/assess/insulator.rb +0 -49
  239. data/lib/contrast/agent/require_state.rb +0 -61
  240. data/lib/contrast/extension/assess/assess_extension.rb +0 -147
  241. data/lib/contrast/utils/freeze_util.rb +0 -32
@@ -1,8 +1,8 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/agent/assess/policy/propagation_node'
5
- cs__scoped_require 'contrast/components/interface'
4
+ require 'contrast/agent/assess/policy/propagation_node'
5
+ require 'contrast/components/interface'
6
6
 
7
7
  module Contrast
8
8
  module Extension
@@ -47,8 +47,6 @@ module Contrast
47
47
  return if scope_for_current_ec.instance_variable_get(:@contrast_scope) > 1
48
48
 
49
49
  target = info_hash[:back_ref]
50
- return unless Contrast::Utils::DuckUtils.trackable?(target)
51
-
52
50
  with_contrast_scope do
53
51
  result = info_hash[:result]
54
52
  return unless result
@@ -56,8 +54,11 @@ module Contrast
56
54
  string = info_hash[:string]
57
55
  return unless string
58
56
 
59
- string.cs__splat_tags(target)
60
- target.cs__properties.build_event(
57
+ properties = Contrast::Agent::Assess::Tracker.properties(target)
58
+ return unless properties
59
+
60
+ properties.splat_from(string, target)
61
+ properties.build_event(
61
62
  REGEXP_EQUAL_SQUIGGLE_NODE,
62
63
  target,
63
64
  self,
@@ -70,9 +71,9 @@ module Contrast
70
71
 
71
72
  def instrument_regexp_track
72
73
  @_instrument_regexp_track ||= begin
73
- cs__scoped_require 'cs__assess_regexp/cs__assess_regexp'
74
- true
75
- end
74
+ require 'cs__assess_regexp/cs__assess_regexp'
75
+ true
76
+ end
76
77
  rescue StandardError, LoadError => e
77
78
  logger.error('Error loading regexp track patch', e)
78
79
  false
@@ -1,15 +1,8 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/agent/assess/policy/propagation_node'
5
- cs__scoped_require 'contrast/components/interface'
6
- cs__scoped_require 'contrast/extension/assess/assess_extension'
7
-
8
- # This patch installs our extension as early as possible. The alternative is to
9
- # litter our code with Contrast::Utils::DuckUtils.trackable? checks.
10
- class String
11
- include Contrast::Extension::Assess::AssessExtension
12
- end
4
+ require 'contrast/agent/assess/policy/propagation_node'
5
+ require 'contrast/components/interface'
13
6
 
14
7
  module Contrast
15
8
  module Extension
@@ -40,23 +33,32 @@ module Contrast
40
33
  def track_interpolation inputs, result
41
34
  return unless AGENT.interpolation_enabled?
42
35
  return if in_contrast_scope?
43
- return unless inputs.any?(&:cs__tracked?)
36
+ return unless inputs.any? { |input| Contrast::Agent::Assess::Tracker.tracked?(input) }
44
37
 
45
38
  with_contrast_scope do
39
+ properties = Contrast::Agent::Assess::Tracker.properties(result)
40
+ return unless properties
41
+
42
+ parent_events = []
46
43
  offset = 0
47
44
  inputs.each do |input|
48
- result.cs__copy_from(input, offset)
45
+ properties.copy_from(input, result, offset)
49
46
  offset += input.length
47
+ parent_event = Contrast::Agent::Assess::Tracker.properties(input)&.event
48
+ parent_events << parent_event if parent_event
50
49
  end
51
- result.cs__properties.build_event(INTERPOLATION_NODE, result, inputs, result, inputs)
50
+ properties.build_event(INTERPOLATION_NODE, result, inputs, result, inputs)
51
+ properties.event.instance_variable_set(:@_parent_events, parent_events)
52
52
  end
53
+ rescue StandardError => e
54
+ logger.error('Unable to track interpolation', e)
53
55
  end
54
56
 
55
57
  def instrument_string
56
58
  @_instrument_string ||= begin
57
- cs__scoped_require 'cs__assess_string/cs__assess_string'
58
- true
59
- end
59
+ require 'cs__assess_string/cs__assess_string'
60
+ true
61
+ end
60
62
  rescue StandardError, LoadError => e
61
63
  logger.error('Error loading hash track patch', e)
62
64
  false
@@ -65,14 +67,12 @@ module Contrast
65
67
  def instrument_string_interpolation
66
68
  if @_instrument_string_interpolation.nil?
67
69
  @_instrument_string_interpolation = begin
68
- if AGENT.patch_interpolation? && Funchook.available?
69
- cs__scoped_require 'cs__assess_string_interpolation26/cs__assess_string_interpolation26'
70
- end
71
- true
72
- rescue StandardError, LoadError => e
73
- logger.error('Error loading interpolation patch', e)
74
- false
75
- end
70
+ require 'cs__assess_string_interpolation26/cs__assess_string_interpolation26' if AGENT.patch_interpolation? && Funchook.available?
71
+ true
72
+ rescue StandardError, LoadError => e
73
+ logger.error('Error loading interpolation patch', e)
74
+ false
75
+ end
76
76
  end
77
77
  @_instrument_string_interpolation
78
78
  end
@@ -11,11 +11,11 @@ module Contrast
11
11
  # relevant given the move to C based patching and the lessons learned
12
12
  # therein.
13
13
  module Inventory
14
- cs__scoped_require 'contrast/security_exception'
14
+ require 'contrast/security_exception'
15
15
  # patching
16
- cs__scoped_require 'contrast/agent/inventory/policy/trigger_node'
17
- cs__scoped_require 'contrast/agent/inventory/policy/policy'
18
- cs__scoped_require 'contrast/agent/patching/policy/patcher'
16
+ require 'contrast/agent/inventory/policy/trigger_node'
17
+ require 'contrast/agent/inventory/policy/policy'
18
+ require 'contrast/agent/patching/policy/patcher'
19
19
  end
20
20
  end
21
21
  end
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/components/scope'
4
+ require 'contrast/components/scope'
5
5
 
6
6
  # This is a reasonable place for the Kernel#catch hook to live.
7
7
  # No current plans for component re-design, but if we had some kind of
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/utils/object_share'
4
+ require 'contrast/utils/object_share'
5
5
 
6
6
  # Some developers override various methods on Module, which can often involve
7
7
  # changing expected method parity/behavior which in turn prevents us from being
@@ -11,10 +11,10 @@ module Contrast
11
11
  # relevant given the move to C based patching and the lessons learned
12
12
  # therein.
13
13
  module Protect
14
- cs__scoped_require 'contrast/security_exception'
14
+ require 'contrast/security_exception'
15
15
  # patching
16
- cs__scoped_require 'contrast/agent/protect/policy/trigger_node'
17
- cs__scoped_require 'contrast/agent/protect/policy/policy'
16
+ require 'contrast/agent/protect/policy/trigger_node'
17
+ require 'contrast/agent/protect/policy/policy'
18
18
  end
19
19
  end
20
20
  end
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/components/interface'
4
+ require 'contrast/components/interface'
5
5
 
6
6
  module Contrast
7
7
  module Extension
@@ -30,9 +30,9 @@ module Contrast
30
30
 
31
31
  def instrument
32
32
  @_instrument ||= begin
33
- cs__scoped_require 'cs__protect_kernel/cs__protect_kernel'
34
- true
35
- end
33
+ require 'cs__protect_kernel/cs__protect_kernel'
34
+ true
35
+ end
36
36
  rescue StandardError, LoadError => e
37
37
  logger.error('Error loading kernel protect patch', e)
38
38
  false
@@ -2,6 +2,6 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  if defined?(Psych)
5
- cs__scoped_require 'contrast/agent/protect/policy/applies_deserialization_rule'
6
- cs__scoped_require 'cs__patched_psych/cs__patched_psych'
5
+ require 'contrast/agent/protect/policy/applies_deserialization_rule'
6
+ require 'cs__patched_psych/cs__patched_psych'
7
7
  end
@@ -46,7 +46,7 @@ module Contrast
46
46
  #
47
47
  # By default, and hopefully in all cases, we won't need these patches,
48
48
  # so we're allowing nil here rather than raising an exception.
49
- def before_load_patches; end
49
+ def before_load_patches!; end
50
50
 
51
51
  # Some Frameworks require specific patching for their classes to handle
52
52
  # functionality like routing. To accommodate this, this method provides
@@ -1,12 +1,12 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/framework/platform_version'
5
- cs__scoped_require 'contrast/framework/rack/support'
6
- cs__scoped_require 'contrast/framework/rails/support'
7
- cs__scoped_require 'contrast/framework/sinatra/support'
8
- cs__scoped_require 'contrast/components/interface'
9
- cs__scoped_require 'contrast/utils/class_util'
4
+ require 'contrast/framework/platform_version'
5
+ require 'contrast/framework/rack/support'
6
+ require 'contrast/framework/rails/support'
7
+ require 'contrast/framework/sinatra/support'
8
+ require 'contrast/components/interface'
9
+ require 'contrast/utils/class_util'
10
10
 
11
11
  module Contrast
12
12
  module Framework
@@ -39,9 +39,9 @@ module Contrast
39
39
  # configuration.
40
40
  def before_load_patches!
41
41
  @_before_load_patches ||= begin
42
- SUPPORTED_FRAMEWORKS.each(&:before_load_patches)
43
- true
44
- end
42
+ SUPPORTED_FRAMEWORKS.each(&:before_load_patches!)
43
+ true
44
+ end
45
45
  end
46
46
 
47
47
  # Return all the After Load Patches for all the Frameworks we know, even
@@ -128,10 +128,9 @@ module Contrast
128
128
  # @param method_name [Symbol] the method to call on each FrameworkSupport class
129
129
  # @return [Array]
130
130
  def data_for_all_frameworks method_name
131
- data = @_frameworks.flat_map do |framework|
131
+ @_frameworks.flat_map do |framework|
132
132
  framework.send(method_name)
133
133
  end.compact
134
- data
135
134
  end
136
135
 
137
136
  # This returns a single object from the first framework to successfully respond
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/components/interface'
4
+ require 'contrast/components/interface'
5
5
 
6
6
  module Contrast
7
7
  module Framework
@@ -24,15 +24,15 @@ module Contrast
24
24
 
25
25
  def instrument
26
26
  @_instrument ||= begin
27
- ::Rack::Session::Cookie.class_eval do
28
- alias_method :cs__patched_initialize, :initialize
29
- def initialize app, options = {}
30
- Contrast::Framework::Rack::Patch::SessionCookie.analyze(options)
31
- cs__patched_initialize(app, options)
32
- end
33
- end
34
- true
35
- end
27
+ ::Rack::Session::Cookie.class_eval do
28
+ alias_method :cs__patched_initialize, :initialize
29
+ def initialize app, options = {}
30
+ Contrast::Framework::Rack::Patch::SessionCookie.analyze(options)
31
+ cs__patched_initialize(app, options)
32
+ end
33
+ end
34
+ true
35
+ end
36
36
  end
37
37
 
38
38
  def analyze options
@@ -67,12 +67,10 @@ module Contrast
67
67
  options,
68
68
  safe_default: false)
69
69
 
70
- with_contrast_scope do
71
- cs__report_finding(
72
- CS__SECURE_RULE_NAME,
73
- options,
74
- caller_locations(10, 9)[0])
75
- end
70
+ cs__report_finding(
71
+ CS__SECURE_RULE_NAME,
72
+ options,
73
+ caller_locations(10, 9)[0])
76
74
  rescue StandardError => e
77
75
  begin
78
76
  logger.error('Unable to track call to secure session', e)
@@ -88,12 +86,10 @@ module Contrast
88
86
  safe_default: false,
89
87
  comparison_type: :greater_than)
90
88
 
91
- with_contrast_scope do
92
- cs__report_finding(
93
- CS__SESSION_TIMEOUT_NAME,
94
- options,
95
- caller_locations(10, 9)[0])
96
- end
89
+ cs__report_finding(
90
+ CS__SESSION_TIMEOUT_NAME,
91
+ options,
92
+ caller_locations(10, 9)[0])
97
93
  rescue StandardError => e
98
94
  begin
99
95
  logger.error('Unable to track call to set session timeout', e)
@@ -105,12 +101,10 @@ module Contrast
105
101
  def apply_httponly options
106
102
  return unless vulnerable_setting?(:httponly, true, options)
107
103
 
108
- with_contrast_scope do
109
- cs__report_finding(
110
- CS__HTTPONLY_NAME,
111
- options,
112
- caller_locations(10, 9)[0])
113
- end
104
+ cs__report_finding(
105
+ CS__HTTPONLY_NAME,
106
+ options,
107
+ caller_locations(10, 9)[0])
114
108
  rescue StandardError => e
115
109
  begin
116
110
  logger.error('Unable to track call to httponly', e)
@@ -1,7 +1,7 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/agent/patching/policy/after_load_patch'
4
+ require 'contrast/agent/patching/policy/after_load_patch'
5
5
 
6
6
  module Contrast
7
7
  module Framework
@@ -1,8 +1,8 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/framework/base_support'
5
- cs__scoped_require 'contrast/framework/rack/patch/support'
4
+ require 'contrast/framework/base_support'
5
+ require 'contrast/framework/rack/patch/support'
6
6
 
7
7
  module Contrast
8
8
  module Framework
@@ -19,19 +19,19 @@ module Contrast
19
19
 
20
20
  def instrument
21
21
  @_instrument ||= begin
22
- ::ActionController::Live::Buffer.class_eval do
23
- # normally pre->in->post filters are applied however, in a streamed response
24
- # we can run into a case where it's pre -> in -> post -> more infilters
25
- # in order to submit anything found during the infilters after the response has
26
- # been written we need to explicitly send them
27
- alias_method :cs__close, :close
28
- def close
29
- Contrast::Framework::Rails::Patch::ActionControllerLiveBuffer.send_messages
30
- cs__close
31
- end
32
- end
33
- true
34
- end
22
+ ::ActionController::Live::Buffer.class_eval do
23
+ # normally pre->in->post filters are applied however, in a streamed response
24
+ # we can run into a case where it's pre -> in -> post -> more infilters
25
+ # in order to submit anything found during the infilters after the response has
26
+ # been written we need to explicitly send them
27
+ alias_method :cs__close, :close
28
+ def close
29
+ Contrast::Framework::Rails::Patch::ActionControllerLiveBuffer.send_messages
30
+ cs__close
31
+ end
32
+ end
33
+ true
34
+ end
35
35
  end
36
36
  end
37
37
  end
@@ -1,8 +1,8 @@
1
1
  # Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
2
2
  # frozen_string_literal: true
3
3
 
4
- cs__scoped_require 'contrast/components/interface'
5
- cs__scoped_require 'contrast/utils/invalid_configuration_util'
4
+ require 'contrast/components/interface'
5
+ require 'contrast/utils/invalid_configuration_util'
6
6
 
7
7
  module Contrast
8
8
  module Framework
@@ -12,7 +12,7 @@ module Contrast
12
12
  module AssessConfiguration
13
13
  include Contrast::Components::Interface
14
14
 
15
- access_component :agent, :analysis, :logging, :scope
15
+ access_component :agent, :analysis, :logging
16
16
 
17
17
  CS__SESSION_TIMEOUT_NAME = 'session-timeout'
18
18
  SAFE_SESSION_TIMEOUT = (30 * 60 * 1000)
@@ -52,9 +52,7 @@ module Contrast
52
52
  return unless vulnerable_setting?(:expire_after, SAFE_SESSION_TIMEOUT, args, comparison_type: :greater_than, safe_default: false)
53
53
 
54
54
  rails_session_settings = args[1]
55
- with_contrast_scope do
56
- cs__report_finding(CS__SESSION_TIMEOUT_NAME, rails_session_settings, caller_locations(6, 5)[0])
57
- end
55
+ cs__report_finding(CS__SESSION_TIMEOUT_NAME, rails_session_settings, caller_locations(3, 2)[0])
58
56
  rescue StandardError => e
59
57
  begin
60
58
  logger.error('Unable to track call to set session timeout', e)
@@ -68,9 +66,7 @@ module Contrast
68
66
  return unless vulnerable_setting?(:secure, true, args)
69
67
 
70
68
  rails_session_settings = args[1]
71
- with_contrast_scope do
72
- cs__report_finding(CS__SECURE_RULE_NAME, rails_session_settings, caller_locations(6, 5)[0])
73
- end
69
+ cs__report_finding(CS__SECURE_RULE_NAME, rails_session_settings, caller_locations(3, 2)[0])
74
70
  rescue StandardError => e
75
71
  begin
76
72
  logger.error('Unable to track call to disable secure cookies', e)
@@ -84,9 +80,7 @@ module Contrast
84
80
  return unless vulnerable_setting?(:httponly, true, args)
85
81
 
86
82
  rails_session_settings = args[1]
87
- with_contrast_scope do
88
- cs__report_finding(CS__HTTPONLY_RULE_NAME, rails_session_settings, caller_locations(6, 5)[0])
89
- end
83
+ cs__report_finding(CS__HTTPONLY_RULE_NAME, rails_session_settings, caller_locations(3, 2)[0])
90
84
  rescue StandardError => e
91
85
  begin
92
86
  logger.error('Unable to track call to disable httponly in session cookie', e)