contrast-agent 3.10.0 → 3.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.flayignore +1 -0
- data/.simplecov +5 -2
- data/ext/build_funchook.rb +12 -7
- data/ext/cs__assess_active_record_named/cs__active_record_named.c +12 -14
- data/ext/cs__assess_active_record_named/cs__active_record_named.h +1 -0
- data/ext/cs__assess_active_record_named/extconf.rb +3 -0
- data/ext/cs__assess_array/cs__assess_array.c +5 -6
- data/ext/cs__assess_array/cs__assess_array.h +1 -0
- data/ext/cs__assess_array/extconf.rb +3 -0
- data/ext/cs__assess_basic_object/cs__assess_basic_object.c +13 -11
- data/ext/cs__assess_basic_object/cs__assess_basic_object.h +2 -1
- data/ext/cs__assess_basic_object/extconf.rb +3 -0
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +4 -3
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.h +3 -3
- data/ext/cs__assess_fiber_track/extconf.rb +3 -0
- data/ext/cs__assess_hash/cs__assess_hash.c +40 -17
- data/ext/cs__assess_hash/cs__assess_hash.h +4 -6
- data/ext/cs__assess_hash/extconf.rb +3 -0
- data/ext/cs__assess_kernel/cs__assess_kernel.c +11 -9
- data/ext/cs__assess_kernel/cs__assess_kernel.h +1 -0
- data/ext/cs__assess_kernel/extconf.rb +3 -0
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +3 -6
- data/ext/cs__assess_marshal_module/extconf.rb +3 -0
- data/ext/cs__assess_module/cs__assess_module.c +16 -14
- data/ext/cs__assess_module/cs__assess_module.h +3 -0
- data/ext/cs__assess_module/extconf.rb +3 -0
- data/ext/cs__assess_regexp/cs__assess_regexp.c +13 -9
- data/ext/cs__assess_regexp/cs__assess_regexp.h +1 -0
- data/ext/cs__assess_regexp/extconf.rb +3 -0
- data/ext/cs__assess_string/cs__assess_string.c +5 -8
- data/ext/cs__assess_string/cs__assess_string.h +2 -1
- data/ext/cs__assess_string/extconf.rb +3 -0
- data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +2 -2
- data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.h +3 -3
- data/ext/cs__assess_string_interpolation26/extconf.rb +3 -0
- data/ext/cs__assess_yield_track/cs__assess_yield_track.h +1 -1
- data/ext/cs__assess_yield_track/extconf.rb +3 -0
- data/ext/cs__common/cs__common.c +80 -1
- data/ext/cs__common/cs__common.h +34 -0
- data/ext/cs__common/extconf.rb +9 -8
- data/ext/cs__contrast_patch/cs__contrast_patch.h +1 -6
- data/ext/cs__contrast_patch/extconf.rb +3 -0
- data/ext/cs__protect_kernel/cs__protect_kernel.c +23 -12
- data/ext/cs__protect_kernel/cs__protect_kernel.h +1 -0
- data/ext/cs__protect_kernel/extconf.rb +3 -0
- data/ext/extconf_common.rb +10 -8
- data/funchook/autom4te.cache/requests +45 -45
- data/funchook/config.log +4 -4
- data/lib/contrast.rb +1 -1
- data/lib/contrast/agent.rb +32 -29
- data/lib/contrast/agent/assess.rb +1 -11
- data/lib/contrast/agent/assess/adjusted_span.rb +3 -1
- data/lib/contrast/agent/assess/contrast_event.rb +16 -62
- data/lib/contrast/agent/assess/events/event_factory.rb +25 -0
- data/lib/contrast/agent/assess/events/source_event.rb +83 -0
- data/lib/contrast/agent/assess/insulator.rb +0 -4
- data/lib/contrast/agent/assess/policy/patcher.rb +6 -2
- data/lib/contrast/agent/assess/policy/policy_node.rb +1 -8
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +2 -2
- data/lib/contrast/agent/assess/policy/preshift.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagation_method.rb +68 -33
- data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -1
- data/lib/contrast/agent/assess/policy/propagator.rb +1 -0
- data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/database_write.rb +1 -3
- data/lib/contrast/agent/assess/policy/propagator/match_data.rb +80 -0
- data/lib/contrast/agent/assess/policy/propagator/select.rb +35 -22
- data/lib/contrast/agent/assess/policy/propagator/split.rb +26 -6
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +2 -0
- data/lib/contrast/agent/assess/policy/rewriter_patch.rb +37 -26
- data/lib/contrast/agent/assess/policy/source_method.rb +20 -20
- data/lib/contrast/agent/assess/policy/source_node.rb +0 -15
- data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +90 -0
- data/lib/contrast/agent/assess/policy/trigger/xpath.rb +57 -0
- data/lib/contrast/agent/assess/policy/trigger_method.rb +30 -45
- data/lib/contrast/agent/assess/policy/trigger_node.rb +7 -7
- data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -31
- data/lib/contrast/agent/assess/properties.rb +5 -3
- data/lib/contrast/agent/assess/rule/base.rb +1 -20
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +23 -6
- data/lib/contrast/agent/assess/rule/redos.rb +4 -5
- data/lib/contrast/agent/assess/tag.rb +24 -14
- data/lib/contrast/agent/at_exit_hook.rb +16 -13
- data/lib/contrast/agent/class_reopener.rb +23 -8
- data/lib/contrast/agent/deadzone/policy/policy.rb +2 -2
- data/lib/contrast/agent/disable_reaction.rb +3 -4
- data/lib/contrast/agent/exclusion_matcher.rb +7 -48
- data/lib/contrast/agent/inventory/policy/datastores.rb +54 -0
- data/lib/contrast/agent/inventory/policy/policy.rb +1 -1
- data/lib/contrast/agent/middleware.rb +101 -260
- data/lib/contrast/agent/module_data.rb +2 -1
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +13 -3
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +59 -47
- data/lib/contrast/agent/patching/policy/method_policy.rb +3 -3
- data/lib/contrast/agent/patching/policy/module_policy.rb +0 -25
- data/lib/contrast/agent/patching/policy/patch.rb +97 -23
- data/lib/contrast/agent/patching/policy/patcher.rb +28 -30
- data/lib/contrast/agent/patching/policy/policy.rb +7 -7
- data/lib/contrast/agent/patching/policy/policy_node.rb +3 -11
- data/lib/contrast/agent/patching/policy/trigger_node.rb +2 -5
- data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +63 -0
- data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +52 -0
- data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +68 -0
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +117 -0
- data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +54 -0
- data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +129 -0
- data/lib/contrast/agent/protect/policy/policy.rb +6 -6
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +51 -0
- data/lib/contrast/agent/protect/rule.rb +0 -5
- data/lib/contrast/agent/protect/rule/base.rb +19 -37
- data/lib/contrast/agent/protect/rule/base_service.rb +3 -1
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +12 -15
- data/lib/contrast/agent/protect/rule/default_scanner.rb +0 -13
- data/lib/contrast/agent/protect/rule/deserialization.rb +2 -0
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +2 -2
- data/lib/contrast/agent/protect/rule/no_sqli.rb +4 -4
- data/lib/contrast/agent/protect/rule/path_traversal.rb +6 -10
- data/lib/contrast/agent/protect/rule/sqli.rb +5 -4
- data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +2 -0
- data/lib/contrast/agent/protect/rule/xss.rb +2 -0
- data/lib/contrast/agent/protect/rule/xxe.rb +10 -4
- data/lib/contrast/agent/railtie.rb +3 -8
- data/lib/contrast/agent/reaction_processor.rb +5 -5
- data/lib/contrast/agent/request.rb +11 -18
- data/lib/contrast/agent/request_context.rb +16 -19
- data/lib/contrast/agent/request_handler.rb +35 -0
- data/lib/contrast/agent/response.rb +39 -86
- data/lib/contrast/agent/rewriter.rb +22 -10
- data/lib/contrast/agent/rule_set.rb +49 -0
- data/lib/contrast/agent/scope.rb +0 -6
- data/lib/contrast/agent/service_heartbeat.rb +3 -4
- data/lib/contrast/agent/socket_client.rb +25 -19
- data/lib/contrast/agent/static_analysis.rb +41 -0
- data/lib/contrast/agent/thread.rb +1 -1
- data/lib/contrast/agent/tracepoint_hook.rb +1 -5
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/api.rb +1 -1
- data/lib/contrast/api/decorators.rb +14 -0
- data/lib/contrast/api/decorators/application_settings.rb +37 -0
- data/lib/contrast/api/decorators/application_update.rb +66 -0
- data/lib/contrast/api/decorators/input_analysis.rb +17 -0
- data/lib/contrast/api/decorators/server_features.rb +24 -0
- data/lib/contrast/api/speedracer.rb +28 -24
- data/lib/contrast/api/tcp_socket.rb +0 -2
- data/lib/contrast/components/agent.rb +34 -24
- data/lib/contrast/components/app_context.rb +45 -38
- data/lib/contrast/components/assess.rb +25 -15
- data/lib/contrast/components/config.rb +7 -5
- data/lib/contrast/components/contrast_service.rb +23 -71
- data/lib/contrast/components/heap_dump.rb +12 -8
- data/lib/contrast/components/interface.rb +15 -22
- data/lib/contrast/components/inventory.rb +5 -1
- data/lib/contrast/components/logger.rb +3 -68
- data/lib/contrast/components/protect.rb +40 -4
- data/lib/contrast/components/sampling.rb +22 -11
- data/lib/contrast/components/scope.rb +2 -52
- data/lib/contrast/components/settings.rb +42 -23
- data/lib/contrast/config/base_configuration.rb +1 -0
- data/lib/contrast/config/default_value.rb +1 -0
- data/lib/contrast/config/protect_rule_configuration.rb +0 -14
- data/lib/contrast/config/protect_rules_configuration.rb +0 -1
- data/lib/contrast/configuration.rb +2 -2
- data/lib/contrast/{extensions/ruby_core → extension}/assess.rb +12 -15
- data/lib/contrast/extension/assess/array.rb +77 -0
- data/lib/contrast/{extensions/ruby_core → extension}/assess/assess_extension.rb +29 -24
- data/lib/contrast/{extensions/ruby_core → extension}/assess/erb.rb +0 -8
- data/lib/contrast/extension/assess/eval_trigger.rb +78 -0
- data/lib/contrast/{extensions/ruby_core → extension}/assess/exec_trigger.rb +7 -9
- data/lib/contrast/extension/assess/fiber.rb +113 -0
- data/lib/contrast/extension/assess/hash.rb +39 -0
- data/lib/contrast/extension/assess/kernel.rb +110 -0
- data/lib/contrast/extension/assess/regexp.rb +84 -0
- data/lib/contrast/{extensions/ruby_core → extension}/assess/string.rb +18 -10
- data/lib/contrast/{extensions/ruby_core → extension}/delegator.rb +0 -0
- data/lib/contrast/{extensions/ruby_core → extension}/inventory.rb +2 -2
- data/lib/contrast/extension/kernel.rb +54 -0
- data/lib/contrast/{extensions/ruby_core → extension}/module.rb +0 -0
- data/lib/contrast/{extensions/ruby_core → extension}/protect.rb +2 -2
- data/lib/contrast/extension/protect/kernel.rb +44 -0
- data/lib/contrast/{extensions/ruby_core → extension}/protect/psych.rb +1 -1
- data/lib/contrast/{extensions/ruby_core → extension}/thread.rb +0 -0
- data/lib/contrast/framework/base_support.rb +32 -0
- data/lib/contrast/framework/manager.rb +59 -8
- data/lib/contrast/framework/platform_version.rb +1 -0
- data/lib/contrast/framework/rack/patch/session_cookie.rb +126 -0
- data/lib/contrast/framework/rack/patch/support.rb +24 -0
- data/lib/contrast/framework/rack/support.rb +22 -0
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +43 -0
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +103 -0
- data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +31 -0
- data/lib/contrast/framework/rails/patch/support.rb +67 -0
- data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +34 -0
- data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +39 -0
- data/lib/contrast/framework/rails/rewrite/active_record_named.rb +73 -0
- data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +33 -0
- data/lib/contrast/framework/rails/support.rb +115 -0
- data/lib/contrast/framework/sinatra/application_helper.rb +51 -0
- data/lib/contrast/framework/sinatra/patch/base.rb +83 -0
- data/lib/contrast/framework/sinatra/patch/support.rb +27 -0
- data/lib/contrast/framework/sinatra/support.rb +109 -0
- data/lib/contrast/framework/view_technologies_descriptor.rb +1 -0
- data/lib/contrast/logger/application.rb +80 -0
- data/lib/contrast/logger/log.rb +143 -0
- data/lib/contrast/logger/time.rb +50 -0
- data/lib/contrast/tasks/config.rb +54 -0
- data/lib/contrast/tasks/service.rb +3 -13
- data/lib/contrast/utils/assess/sampling_util.rb +4 -9
- data/lib/contrast/utils/assess/tracking_util.rb +7 -1
- data/lib/contrast/utils/boolean_util.rb +2 -2
- data/lib/contrast/utils/cache.rb +0 -11
- data/lib/contrast/utils/class_util.rb +21 -2
- data/lib/contrast/utils/gemfile_reader.rb +7 -5
- data/lib/contrast/utils/hash_digest.rb +2 -11
- data/lib/contrast/utils/heap_dump_util.rb +12 -11
- data/lib/contrast/utils/invalid_configuration_util.rb +4 -4
- data/lib/contrast/utils/inventory_util.rb +2 -2
- data/lib/contrast/utils/io_util.rb +1 -11
- data/lib/contrast/utils/job_servers_running.rb +6 -4
- data/lib/contrast/utils/object_share.rb +1 -28
- data/lib/contrast/utils/os.rb +1 -25
- data/lib/contrast/utils/service_response_util.rb +36 -60
- data/lib/contrast/utils/service_sender_util.rb +84 -23
- data/lib/contrast/utils/sinatra_helper.rb +0 -6
- data/lib/contrast/utils/stack_trace_utils.rb +86 -182
- data/lib/contrast/utils/string_utils.rb +18 -2
- data/lib/contrast/utils/tag_util.rb +11 -1
- data/lib/contrast/utils/thread_tracker.rb +2 -2
- data/lib/contrast/utils/timer.rb +0 -40
- data/resources/assess/policy.json +42 -71
- data/resources/inventory/policy.json +2 -2
- data/resources/protect/policy.json +15 -15
- data/ruby-agent.gemspec +11 -4
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +122 -111
- data/ext/cs__assess_regexp_track/cs__assess_regexp_track.c +0 -63
- data/ext/cs__assess_regexp_track/cs__assess_regexp_track.h +0 -29
- data/ext/cs__assess_regexp_track/extconf.rb +0 -2
- data/lib/contrast/agent/assess/frozen_properties.rb +0 -41
- data/lib/contrast/agent/assess/rule/csrf.rb +0 -66
- data/lib/contrast/agent/assess/rule/csrf/csrf_action.rb +0 -28
- data/lib/contrast/agent/assess/rule/csrf/csrf_applicator.rb +0 -73
- data/lib/contrast/agent/assess/rule/csrf/csrf_watcher.rb +0 -132
- data/lib/contrast/agent/assess/rule/response_scanning_rule.rb +0 -47
- data/lib/contrast/agent/assess/rule/response_watcher.rb +0 -36
- data/lib/contrast/agent/assess/rule/watcher.rb +0 -36
- data/lib/contrast/agent/feature_state.rb +0 -376
- data/lib/contrast/agent/logger_manager.rb +0 -116
- data/lib/contrast/agent/protect/rule/csrf.rb +0 -118
- data/lib/contrast/agent/protect/rule/csrf/csrf_evaluator.rb +0 -103
- data/lib/contrast/agent/protect/rule/csrf/csrf_token_injector.rb +0 -85
- data/lib/contrast/agent/settings_state.rb +0 -152
- data/lib/contrast/delegators.rb +0 -9
- data/lib/contrast/delegators/application_update.rb +0 -32
- data/lib/contrast/extensions/framework/rack/cookie.rb +0 -24
- data/lib/contrast/extensions/framework/rack/request.rb +0 -24
- data/lib/contrast/extensions/framework/rack/response.rb +0 -23
- data/lib/contrast/extensions/framework/rails/action_controller_railties_helper_inherited.rb +0 -20
- data/lib/contrast/extensions/framework/rails/active_record.rb +0 -26
- data/lib/contrast/extensions/framework/rails/active_record_named.rb +0 -53
- data/lib/contrast/extensions/framework/rails/active_record_time_zone_inherited.rb +0 -21
- data/lib/contrast/extensions/framework/rails/buffer.rb +0 -28
- data/lib/contrast/extensions/framework/rails/configuration.rb +0 -27
- data/lib/contrast/extensions/framework/sinatra/base.rb +0 -59
- data/lib/contrast/extensions/ruby_core/assess/array.rb +0 -59
- data/lib/contrast/extensions/ruby_core/assess/basic_object.rb +0 -15
- data/lib/contrast/extensions/ruby_core/assess/fiber.rb +0 -124
- data/lib/contrast/extensions/ruby_core/assess/hash.rb +0 -22
- data/lib/contrast/extensions/ruby_core/assess/kernel.rb +0 -95
- data/lib/contrast/extensions/ruby_core/assess/module.rb +0 -14
- data/lib/contrast/extensions/ruby_core/assess/regexp.rb +0 -206
- data/lib/contrast/extensions/ruby_core/assess/tilt_template_trigger.rb +0 -73
- data/lib/contrast/extensions/ruby_core/assess/xpath_library_trigger.rb +0 -40
- data/lib/contrast/extensions/ruby_core/eval_trigger.rb +0 -52
- data/lib/contrast/extensions/ruby_core/inventory/datastores.rb +0 -37
- data/lib/contrast/extensions/ruby_core/protect/applies_command_injection_rule.rb +0 -72
- data/lib/contrast/extensions/ruby_core/protect/applies_deserialization_rule.rb +0 -60
- data/lib/contrast/extensions/ruby_core/protect/applies_no_sqli_rule.rb +0 -83
- data/lib/contrast/extensions/ruby_core/protect/applies_path_traversal_rule.rb +0 -123
- data/lib/contrast/extensions/ruby_core/protect/applies_sqli_rule.rb +0 -65
- data/lib/contrast/extensions/ruby_core/protect/applies_xxe_rule.rb +0 -143
- data/lib/contrast/extensions/ruby_core/protect/kernel.rb +0 -30
- data/lib/contrast/framework/rails_support.rb +0 -88
- data/lib/contrast/framework/sinatra_application_helper.rb +0 -49
- data/lib/contrast/framework/sinatra_support.rb +0 -94
- data/lib/contrast/utils/comment_range.rb +0 -19
- data/lib/contrast/utils/data_store_util.rb +0 -23
- data/lib/contrast/utils/environment_util.rb +0 -81
- data/lib/contrast/utils/performs_logging.rb +0 -152
- data/lib/contrast/utils/rack_assess_session_cookie.rb +0 -104
- data/lib/contrast/utils/rails_assess_configuration.rb +0 -95
- data/lib/contrast/utils/random_util.rb +0 -22
- data/resources/csrf/inject.js +0 -44
- data/resources/factory-bot-spec/spec_helper.rb +0 -30
- data/resources/rubocops/kernel/catch_cop.rb +0 -37
- data/resources/rubocops/kernel/require_cop.rb +0 -37
- data/resources/rubocops/kernel/require_relative_cop.rb +0 -33
- data/resources/rubocops/module/autoload_cop.rb +0 -37
- data/resources/rubocops/module/const_defined_cop.rb +0 -37
- data/resources/rubocops/module/const_get_cop.rb +0 -37
- data/resources/rubocops/module/const_set_cop.rb +0 -37
- data/resources/rubocops/module/constants_cop.rb +0 -37
- data/resources/rubocops/module/name_cop.rb +0 -37
- data/resources/rubocops/object/class_cop.rb +0 -37
- data/resources/rubocops/object/freeze_cop.rb +0 -37
- data/resources/rubocops/object/frozen_cop.rb +0 -37
- data/resources/rubocops/object/is_a_cop.rb +0 -37
- data/resources/rubocops/object/method_cop.rb +0 -37
- data/resources/rubocops/object/respond_to_cop.rb +0 -37
- data/resources/rubocops/object/singleton_class_cop.rb +0 -37
- data/resources/rubocops/regexp/spelling_cop.rb +0 -44
- data/resources/rubocops/thread/new_cop.rb +0 -39
- data/resources/ruby-spec/ancestors_spec.rb +0 -70
- data/resources/ruby-spec/modulo_spec.rb +0 -831
- data/resources/ruby-spec/parameters_spec.rb +0 -261
- data/resources/ruby-spec/ruby_spec_spec_helper.rb +0 -35
@@ -88,13 +88,13 @@ module Contrast
|
|
88
88
|
puts "!!! Contrast - Configuration file at #{ path } is not readable by current user"
|
89
89
|
next
|
90
90
|
end
|
91
|
-
config = yaml_to_hash(path)
|
91
|
+
config = yaml_to_hash(path) || {}
|
92
92
|
break
|
93
93
|
end
|
94
94
|
|
95
95
|
if config.empty?
|
96
96
|
puts "!!! Contrast - working directory: #{ Dir.pwd }"
|
97
|
-
puts '!!! Contrast - configuration file could not be found at any of the search paths'
|
97
|
+
puts '!!! Contrast - valid configuration file could not be found at any of the search paths'
|
98
98
|
puts 'Valid configuration paths are: '
|
99
99
|
configuration_paths.each do |path|
|
100
100
|
puts(path)
|
@@ -2,14 +2,15 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
module Contrast
|
5
|
-
module
|
6
|
-
# Our top level
|
5
|
+
module Extension
|
6
|
+
# Our top level Assess namespace in the Core Extension section of our
|
7
7
|
# code. These patches are those that are invoked directly from a patched
|
8
8
|
# Class.
|
9
9
|
#
|
10
10
|
# @deprecated This is one of our earliest designs and is not nearly as
|
11
11
|
# relevant given the move to C based patching and the lessons learned
|
12
12
|
# therein.
|
13
|
+
# Removing it requires a C refactor to handle the namespace.
|
13
14
|
module Assess
|
14
15
|
cs__scoped_require 'contrast/agent/patching/policy/patcher'
|
15
16
|
|
@@ -31,22 +32,18 @@ module Contrast
|
|
31
32
|
cs__scoped_require 'contrast/agent/assess/policy/patcher'
|
32
33
|
|
33
34
|
# classes that don't play nice w/ our standard propagation
|
34
|
-
cs__scoped_require 'contrast/
|
35
|
-
cs__scoped_require 'contrast/extensions/ruby_core/assess/assess_extension'
|
35
|
+
cs__scoped_require 'contrast/extension/assess/assess_extension'
|
36
36
|
# this needs to come first b/c array and others work on strings and
|
37
37
|
# expect them to be trackable
|
38
|
-
cs__scoped_require 'contrast/
|
38
|
+
cs__scoped_require 'contrast/extension/assess/string'
|
39
39
|
|
40
|
-
cs__scoped_require 'contrast/
|
41
|
-
cs__scoped_require 'contrast/
|
42
|
-
cs__scoped_require 'contrast/
|
43
|
-
cs__scoped_require 'contrast/
|
44
|
-
cs__scoped_require 'contrast/
|
45
|
-
cs__scoped_require 'contrast/
|
46
|
-
cs__scoped_require 'contrast/
|
47
|
-
cs__scoped_require 'contrast/extensions/ruby_core/assess/basic_object'
|
48
|
-
cs__scoped_require 'contrast/extensions/ruby_core/assess/tilt_template_trigger'
|
49
|
-
cs__scoped_require 'contrast/extensions/ruby_core/assess/xpath_library_trigger'
|
40
|
+
cs__scoped_require 'contrast/extension/assess/array'
|
41
|
+
cs__scoped_require 'contrast/extension/assess/erb'
|
42
|
+
cs__scoped_require 'contrast/extension/assess/eval_trigger'
|
43
|
+
cs__scoped_require 'contrast/extension/assess/fiber'
|
44
|
+
cs__scoped_require 'contrast/extension/assess/hash'
|
45
|
+
cs__scoped_require 'contrast/extension/assess/kernel'
|
46
|
+
cs__scoped_require 'contrast/extension/assess/regexp'
|
50
47
|
end
|
51
48
|
end
|
52
49
|
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
cs__scoped_require 'contrast/agent/patching/policy/patch'
|
5
|
+
cs__scoped_require 'contrast/agent/patching/policy/patcher'
|
6
|
+
cs__scoped_require 'contrast/components/interface'
|
7
|
+
|
8
|
+
module Contrast
|
9
|
+
module Extension
|
10
|
+
module Assess
|
11
|
+
# This is our patch of the Array class required to handle propagation
|
12
|
+
# Disclaimer: there may be a better way, but we're in a 'get it work' state.
|
13
|
+
# Hopefully, we'll be in a 'get it right' state soon.
|
14
|
+
class ArrayPropagator
|
15
|
+
include Contrast::Components::Interface
|
16
|
+
|
17
|
+
access_component :scope
|
18
|
+
|
19
|
+
ARRAY_JOIN_HASH = {
|
20
|
+
'class_name' => 'Array',
|
21
|
+
'instance_method' => true,
|
22
|
+
'method_visibility' => 'public',
|
23
|
+
'method_name' => 'join',
|
24
|
+
'action' => 'CUSTOM',
|
25
|
+
'source' => 'O',
|
26
|
+
'target' => 'R',
|
27
|
+
'patch_class' => 'NOOP',
|
28
|
+
'patch_method' => 'cs__track_join'
|
29
|
+
}.cs__freeze
|
30
|
+
ARRAY_JOIN_NODE = Contrast::Agent::Assess::Policy::PropagationNode.new(ARRAY_JOIN_HASH)
|
31
|
+
|
32
|
+
class << self
|
33
|
+
# When you call join, they use an internal thing, so there's no good way to get at the thing being returned.
|
34
|
+
# Multiple Strings are appended with the #join method. Because that
|
35
|
+
# operation happens in C, we have to do it here rather than rely on the
|
36
|
+
# patch of our String append or concat methods.
|
37
|
+
def cs__track_join ary, separator, ret
|
38
|
+
return unless ary
|
39
|
+
return ret if Contrast::Agent::Patching::Policy::Patch.skip_assess_analysis?
|
40
|
+
|
41
|
+
with_contrast_scope do
|
42
|
+
shift = 0
|
43
|
+
separator_length = separator.nil? ? 0 : separator.to_s.length
|
44
|
+
ary.each do |obj|
|
45
|
+
if obj # skip nil here
|
46
|
+
ret.cs__copy_from(obj, shift)
|
47
|
+
shift += obj.to_s.length
|
48
|
+
end
|
49
|
+
shift += separator_length
|
50
|
+
end
|
51
|
+
return ret unless ret.cs__tracked?
|
52
|
+
|
53
|
+
ret.cs__properties.cleanup_tags
|
54
|
+
ret.cs__properties.build_event(
|
55
|
+
ARRAY_JOIN_NODE,
|
56
|
+
ret,
|
57
|
+
ary,
|
58
|
+
ret,
|
59
|
+
[separator])
|
60
|
+
ret
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def instrument_array_track
|
65
|
+
@_instrument_array_track ||= begin
|
66
|
+
cs__scoped_require 'cs__assess_array/cs__assess_array'
|
67
|
+
true
|
68
|
+
end
|
69
|
+
rescue StandardError, LoadError => e
|
70
|
+
logger.error('Error loading assess track patch', e)
|
71
|
+
false
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -2,17 +2,16 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
cs__scoped_require 'contrast/agent/assess/properties'
|
5
|
-
cs__scoped_require 'contrast/agent/assess/frozen_properties'
|
6
5
|
cs__scoped_require 'contrast/agent/assess/insulator'
|
7
6
|
|
8
7
|
module Contrast
|
9
|
-
module
|
8
|
+
module Extension
|
10
9
|
module Assess
|
11
10
|
# This module is responsible for maintaining the data we need to
|
12
11
|
# construct a trace event for the object in which it is included. Rather
|
13
12
|
# than have this code all over the place, any class that wants to use
|
14
13
|
# dataflow features should be sent
|
15
|
-
# 'include Contrast::
|
14
|
+
# 'include Contrast::Extension::Assess::AssessExtension'
|
16
15
|
module AssessExtension
|
17
16
|
# Lazily build properties object. Only objects that have been tracked
|
18
17
|
# will have the @_cs__properties, but all will respond to the
|
@@ -86,6 +85,7 @@ module Contrast
|
|
86
85
|
existing = cs__properties.fetch_tag(key)
|
87
86
|
if existing
|
88
87
|
existing.concat(new_tags)
|
88
|
+
Contrast::Utils::TagUtil.size_aware_merge(self, existing)
|
89
89
|
else
|
90
90
|
cs__properties.set_tags(key, new_tags)
|
91
91
|
end
|
@@ -99,33 +99,38 @@ module Contrast
|
|
99
99
|
# If the return already had that tag, the existing tag
|
100
100
|
# range is recycled to save us an object.
|
101
101
|
def cs__splat_tags ret, source = self
|
102
|
-
return unless Contrast::Utils::DuckUtils.
|
103
|
-
ret,
|
104
|
-
:cs__tracked?)
|
102
|
+
return unless Contrast::Utils::DuckUtils.trackable?(ret)
|
105
103
|
|
106
|
-
|
107
|
-
|
108
|
-
|
104
|
+
length = Contrast::Utils::StringUtils.ret_length(ret)
|
105
|
+
return if length.zero?
|
106
|
+
|
107
|
+
cs__splat_from_source(ret, length, source)
|
108
|
+
cs__splat_from_ret(ret, length)
|
109
|
+
end
|
110
|
+
|
111
|
+
def cs__splat_from_source ret, ret_length, source
|
112
|
+
splat_source = Contrast::Utils::DuckUtils.trackable?(source)
|
109
113
|
splat_source &&= source.cs__tracked?
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
end
|
114
|
+
return unless splat_source
|
115
|
+
|
116
|
+
source.cs__properties.tag_keys.each do |key|
|
117
|
+
existing = ret.cs__properties.fetch_tag(key)
|
118
|
+
# if the tag already exists, drop all but the first range
|
119
|
+
# then change that range to cover the entire return
|
120
|
+
if existing
|
121
|
+
existing.drop(existing.length - 1)
|
122
|
+
range = existing[0]
|
123
|
+
range.repurpose(0, ret_length)
|
124
|
+
else
|
125
|
+
span = Contrast::Agent::Assess::AdjustedSpan.new(0, ret_length)
|
126
|
+
ret.cs__properties.add_tag(key, span)
|
124
127
|
end
|
125
128
|
end
|
129
|
+
end
|
130
|
+
|
131
|
+
def cs__splat_from_ret ret, length
|
126
132
|
return unless ret.cs__tracked?
|
127
133
|
|
128
|
-
length ||= Contrast::Utils::StringUtils.ret_length(ret)
|
129
134
|
ret.cs__properties.tag_keys.each do |key|
|
130
135
|
next unless key
|
131
136
|
|
@@ -1,18 +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/components/interface'
|
5
|
-
|
6
4
|
# This module is used to track propagation through ERB template rendering
|
7
5
|
module ERBPropagator
|
8
6
|
class << self
|
9
|
-
include Contrast::Components::Interface
|
10
|
-
access_component :logging
|
11
|
-
|
12
7
|
def result_tagger patcher, preshift, ret, _block
|
13
8
|
return unless preshift.args.length >= 1
|
14
9
|
|
15
|
-
logger.debug('ERBPropagator - running propagation')
|
16
10
|
used_binding = preshift.args[0]
|
17
11
|
binding_variable_set = used_binding.local_variables
|
18
12
|
|
@@ -25,7 +19,6 @@ module ERBPropagator
|
|
25
19
|
start_index = ret.index(bound_variable_value)
|
26
20
|
next if start_index.nil?
|
27
21
|
|
28
|
-
logger.debug('ERBPropagator - found bound_variable in erb template result')
|
29
22
|
ret.cs__copy_from(bound_variable_value, start_index)
|
30
23
|
end
|
31
24
|
ret.cs__properties.build_event(
|
@@ -35,7 +28,6 @@ module ERBPropagator
|
|
35
28
|
ret,
|
36
29
|
preshift.args,
|
37
30
|
1)
|
38
|
-
logger.debug('ERBPropgator - Finished erb result propagation')
|
39
31
|
ret
|
40
32
|
end
|
41
33
|
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
cs__scoped_require 'contrast/components/interface'
|
5
|
+
|
6
|
+
module Contrast
|
7
|
+
module Extension
|
8
|
+
module Assess
|
9
|
+
# This Module allows us to track calls to the BasicObject#eval method,
|
10
|
+
# which violates the design of most methods we track in that we have to
|
11
|
+
# apply the trigger in a custom patch over one of the generic triggers in
|
12
|
+
# TriggerMethod.
|
13
|
+
class EvalTrigger
|
14
|
+
include Contrast::Components::Interface
|
15
|
+
access_component :logging
|
16
|
+
|
17
|
+
class << self
|
18
|
+
def instance_eval_trigger_check obj, source, ret
|
19
|
+
apply_trigger(obj, source, ret, 'BasicObject', :instance_eval)
|
20
|
+
end
|
21
|
+
|
22
|
+
def eval_trigger_check obj, source, ret, method
|
23
|
+
apply_trigger(obj, source, ret, 'Module', method)
|
24
|
+
end
|
25
|
+
|
26
|
+
def apply_trigger obj, source, ret, clazz, method
|
27
|
+
current_context = Contrast::Agent::REQUEST_TRACKER.current
|
28
|
+
return unless current_context
|
29
|
+
|
30
|
+
# Since we know this is the source of the trigger, we can do some
|
31
|
+
# optimization here and return when it is not tracked
|
32
|
+
return unless Contrast::Utils::Assess::TrackingUtil.tracked?(source)
|
33
|
+
|
34
|
+
# source might not be all the args passed in, but it is the one we care
|
35
|
+
# about. we could pass in all the args in the last param here if it
|
36
|
+
# becomes an issue in rendering on TS
|
37
|
+
Contrast::Agent::Assess::Policy::TriggerMethod.apply_eval_trigger(
|
38
|
+
current_context,
|
39
|
+
trigger_node(clazz, method),
|
40
|
+
source,
|
41
|
+
obj,
|
42
|
+
ret,
|
43
|
+
source)
|
44
|
+
end
|
45
|
+
|
46
|
+
def instrument_basic_object_track
|
47
|
+
@_instrument_basic_object_track ||= begin
|
48
|
+
cs__scoped_require 'cs__assess_basic_object/cs__assess_basic_object'
|
49
|
+
true
|
50
|
+
end
|
51
|
+
rescue StandardError, LoadError => e
|
52
|
+
logger.error('Error loading basic object track patch', e)
|
53
|
+
false
|
54
|
+
end
|
55
|
+
|
56
|
+
def instrument_module_track
|
57
|
+
@_instrument_module_track ||= begin
|
58
|
+
cs__scoped_require 'cs__assess_module/cs__assess_module'
|
59
|
+
true
|
60
|
+
end
|
61
|
+
rescue StandardError, LoadError => e
|
62
|
+
logger.error('Error loading module track patch', e)
|
63
|
+
false
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def trigger_node clazz, method
|
69
|
+
triggers = Contrast::Agent::Assess::Policy::Policy.instance.triggers
|
70
|
+
return unless triggers
|
71
|
+
|
72
|
+
triggers.find { |node| node.class_name == clazz && node.method_name == method }
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -1,17 +1,15 @@
|
|
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/
|
4
|
+
cs__scoped_require 'contrast/agent/at_exit_hook'
|
5
5
|
|
6
6
|
module Contrast
|
7
|
-
module
|
7
|
+
module Extension
|
8
8
|
module Assess
|
9
9
|
# This Module allows us to track calls to the Kernel#exec method, which
|
10
10
|
# violates the design of most methods we track in that we have to apply
|
11
11
|
# the trigger at the start in order to account for the process hand off.
|
12
12
|
module ExecTrigger
|
13
|
-
include Contrast::Components::Interface
|
14
|
-
access_component :contrast_service
|
15
13
|
def apply_trigger source
|
16
14
|
current_context = Contrast::Agent::REQUEST_TRACKER.current
|
17
15
|
return unless current_context
|
@@ -27,12 +25,12 @@ module Contrast
|
|
27
25
|
current_context,
|
28
26
|
trigger_node,
|
29
27
|
source,
|
30
|
-
|
31
|
-
|
32
|
-
1,
|
28
|
+
Kernel,
|
29
|
+
nil,
|
33
30
|
source)
|
34
|
-
# Exec replaces the current process, if we occur in a forked process
|
35
|
-
|
31
|
+
# Exec replaces the current process, if we occur in a forked process
|
32
|
+
# our appendage of this finding will not make it to TS
|
33
|
+
Contrast::Agent::AtExitHook.on_exit
|
36
34
|
end
|
37
35
|
|
38
36
|
private
|
@@ -0,0 +1,113 @@
|
|
1
|
+
# Copyright (c) 2020 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
cs__scoped_require 'contrast/agent/assess/policy/propagation_node'
|
5
|
+
cs__scoped_require 'contrast/components/interface'
|
6
|
+
|
7
|
+
# In order to instrument some difficult methods like String#gsub, as it
|
8
|
+
# returns an enumerator, we need to instrument methods on Fiber.
|
9
|
+
# Specifically, we instrument 'rb_fiber_yield' and 'rb_fiber_new' in
|
10
|
+
# order to track what happens within Enumerator#next.
|
11
|
+
module Contrast
|
12
|
+
module Extension
|
13
|
+
module Assess
|
14
|
+
# This Class provides us with a way to invoke Regexp propagation for those
|
15
|
+
# methods which are too complex to fit into one of the standard
|
16
|
+
# Contrast::Agent::Assess::Policy::Propagator molds without cluttering up the
|
17
|
+
# Fiber Class or exposing our methods there.
|
18
|
+
class FiberPropagator
|
19
|
+
include Contrast::Components::Interface
|
20
|
+
|
21
|
+
access_component :analysis, :logging, :scope
|
22
|
+
|
23
|
+
# we use funchook to patch rb_fiber_new the initialize method is not exposed by Ruby core
|
24
|
+
FIBER_NEW_NODE_HASH = {
|
25
|
+
'class_name' => 'Fiber',
|
26
|
+
'instance_method' => true,
|
27
|
+
'method_visibility' => 'public',
|
28
|
+
'method_name' => 'c_new',
|
29
|
+
'action' => 'CUSTOM',
|
30
|
+
'source' => 'O',
|
31
|
+
'target' => 'R',
|
32
|
+
'patch_class' => 'Contrast::Extension::Assess::FiberPropagator',
|
33
|
+
'patch_method' => 'track_rb_fiber_new'
|
34
|
+
}.cs__freeze
|
35
|
+
FIBER_NEW_NODE = Contrast::Agent::Assess::Policy::PropagationNode.new(FIBER_NEW_NODE_HASH)
|
36
|
+
private_constant :FIBER_NEW_NODE_HASH
|
37
|
+
private_constant :FIBER_NEW_NODE
|
38
|
+
|
39
|
+
FIBER_YIELD_NODE_HASH = {
|
40
|
+
'class_name' => 'Fiber',
|
41
|
+
'instance_method' => true,
|
42
|
+
'method_visibility' => 'public',
|
43
|
+
'method_name' => 'c_yield',
|
44
|
+
'action' => 'CUSTOM',
|
45
|
+
'source' => 'O',
|
46
|
+
'target' => 'R',
|
47
|
+
'patch_class' => 'Contrast::Extension::Assess::FiberPropagator',
|
48
|
+
'patch_method' => 'track_rb_fiber_yield'
|
49
|
+
}.cs__freeze
|
50
|
+
FIBER_YIELD_NODE = Contrast::Agent::Assess::Policy::PropagationNode.new(FIBER_YIELD_NODE_HASH)
|
51
|
+
private_constant :FIBER_YIELD_NODE_HASH
|
52
|
+
private_constant :FIBER_YIELD_NODE
|
53
|
+
|
54
|
+
class << self
|
55
|
+
def track_rb_fiber_yield fiber, _method, results
|
56
|
+
return unless ASSESS.enabled?
|
57
|
+
return unless Contrast::Utils::DuckUtils.trackable?(fiber)
|
58
|
+
|
59
|
+
# results will be nil if StopIteration was raised,
|
60
|
+
# otherwise an Array of the yielded arguments
|
61
|
+
return unless results.cs__is_a?(Array)
|
62
|
+
|
63
|
+
with_contrast_scope do
|
64
|
+
results.each do |result|
|
65
|
+
next unless Contrast::Utils::DuckUtils.trackable?(result)
|
66
|
+
next if result.cs__frozen?
|
67
|
+
|
68
|
+
fiber.cs__splat_tags(result)
|
69
|
+
result.cs__properties.build_event(
|
70
|
+
FIBER_YIELD_NODE,
|
71
|
+
result,
|
72
|
+
fiber,
|
73
|
+
result,
|
74
|
+
[])
|
75
|
+
end
|
76
|
+
end
|
77
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
78
|
+
logger.error('Unable to propagate during Fiber#yield', e)
|
79
|
+
end
|
80
|
+
|
81
|
+
def track_rb_fiber_new fiber, _enum, _enum_method, underlying, _underlying_method
|
82
|
+
return unless ASSESS.enabled?
|
83
|
+
return unless Contrast::Utils::DuckUtils.trackable?(fiber)
|
84
|
+
return unless Contrast::Utils::DuckUtils.trackable?(underlying)
|
85
|
+
return unless underlying.is_a?(String) && !underlying.empty?
|
86
|
+
|
87
|
+
with_contrast_scope do
|
88
|
+
underlying.cs__splat_tags(fiber)
|
89
|
+
fiber.cs__properties.build_event(
|
90
|
+
FIBER_NEW_NODE,
|
91
|
+
fiber,
|
92
|
+
underlying,
|
93
|
+
fiber,
|
94
|
+
[])
|
95
|
+
end
|
96
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
97
|
+
logger.error('Unable to propagate during Fiber.new', e)
|
98
|
+
end
|
99
|
+
|
100
|
+
def instrument_fiber_track
|
101
|
+
@_instrument_fiber_variables ||= begin
|
102
|
+
cs__scoped_require 'cs__assess_fiber_track/cs__assess_fiber_track'
|
103
|
+
true
|
104
|
+
end
|
105
|
+
rescue StandardError, LoadError => e
|
106
|
+
logger.error('Error loading fiber track patch', e)
|
107
|
+
false
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|