contrast-agent 3.13.2 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/contrast_service +1 -7
- data/ext/cs__assess_active_record_named/cs__active_record_named.c +8 -7
- data/ext/cs__assess_array/cs__assess_array.c +6 -5
- data/ext/cs__assess_basic_object/cs__assess_basic_object.c +5 -5
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +2 -1
- data/ext/cs__assess_hash/cs__assess_hash.c +18 -17
- data/ext/cs__assess_hash/cs__assess_hash.h +2 -1
- data/ext/cs__assess_kernel/cs__assess_kernel.c +7 -8
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +18 -16
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.h +1 -0
- data/ext/cs__assess_module/cs__assess_module.c +6 -6
- data/ext/cs__assess_regexp/cs__assess_regexp.c +4 -4
- data/ext/cs__assess_string/cs__assess_string.c +31 -16
- data/ext/cs__assess_string/cs__assess_string.h +6 -1
- data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +4 -2
- data/ext/cs__assess_yield_track/cs__assess_yield_track.c +2 -2
- data/ext/cs__common/cs__common.c +48 -39
- data/ext/cs__common/cs__common.h +16 -21
- data/ext/cs__contrast_patch/cs__contrast_patch.c +27 -25
- data/ext/cs__contrast_patch/cs__contrast_patch.h +5 -7
- data/ext/cs__protect_kernel/cs__protect_kernel.c +11 -12
- data/ext/cs__protect_kernel/cs__protect_kernel.h +2 -2
- data/lib/contrast-agent.rb +1 -1
- data/lib/contrast.rb +13 -23
- data/lib/contrast/agent.rb +39 -47
- data/lib/contrast/agent/assess.rb +12 -12
- data/lib/contrast/agent/assess/contrast_event.rb +151 -85
- data/lib/contrast/agent/assess/events/event_factory.rb +2 -2
- data/lib/contrast/agent/assess/events/source_event.rb +3 -3
- data/lib/contrast/agent/assess/finalizers/freeze.rb +15 -0
- data/lib/contrast/agent/assess/finalizers/hash.rb +97 -0
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +11 -4
- data/lib/contrast/agent/assess/policy/patcher.rb +6 -6
- data/lib/contrast/agent/assess/policy/policy.rb +9 -11
- data/lib/contrast/agent/assess/policy/policy_node.rb +17 -12
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +21 -5
- data/lib/contrast/agent/assess/policy/preshift.rb +13 -7
- data/lib/contrast/agent/assess/policy/propagation_method.rb +64 -44
- data/lib/contrast/agent/assess/policy/propagation_node.rb +2 -2
- data/lib/contrast/agent/assess/policy/propagator.rb +18 -18
- data/lib/contrast/agent/assess/policy/propagator/append.rb +8 -5
- data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/center.rb +9 -5
- data/lib/contrast/agent/assess/policy/propagator/custom.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/database_write.rb +6 -4
- data/lib/contrast/agent/assess/policy/propagator/insert.rb +7 -4
- data/lib/contrast/agent/assess/policy/propagator/keep.rb +4 -1
- data/lib/contrast/agent/assess/policy/propagator/match_data.rb +7 -9
- data/lib/contrast/agent/assess/policy/propagator/next.rb +7 -5
- data/lib/contrast/agent/assess/policy/propagator/prepend.rb +13 -5
- data/lib/contrast/agent/assess/policy/propagator/remove.rb +8 -4
- data/lib/contrast/agent/assess/policy/propagator/replace.rb +5 -2
- data/lib/contrast/agent/assess/policy/propagator/reverse.rb +7 -5
- data/lib/contrast/agent/assess/policy/propagator/select.rb +13 -7
- data/lib/contrast/agent/assess/policy/propagator/splat.rb +10 -9
- data/lib/contrast/agent/assess/policy/propagator/split.rb +27 -22
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +52 -35
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +11 -5
- data/lib/contrast/agent/assess/policy/rewriter_patch.rb +5 -5
- data/lib/contrast/agent/assess/policy/source_method.rb +90 -72
- data/lib/contrast/agent/assess/policy/source_validation/cross_site_validator.rb +1 -1
- data/lib/contrast/agent/assess/policy/source_validation/source_validation.rb +1 -1
- data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +16 -12
- data/lib/contrast/agent/assess/policy/trigger/xpath.rb +2 -2
- data/lib/contrast/agent/assess/policy/trigger_method.rb +81 -33
- data/lib/contrast/agent/assess/policy/trigger_node.rb +41 -46
- data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -1
- data/lib/contrast/agent/assess/policy/trigger_validation/trigger_validation.rb +2 -2
- data/lib/contrast/agent/assess/properties.rb +15 -5
- data/lib/contrast/agent/assess/property/evented.rb +7 -20
- data/lib/contrast/agent/assess/property/tagged.rb +13 -7
- data/lib/contrast/agent/assess/property/updated.rb +131 -0
- data/lib/contrast/agent/assess/rule.rb +2 -2
- data/lib/contrast/agent/assess/rule/base.rb +3 -4
- data/lib/contrast/agent/assess/rule/provider.rb +3 -3
- data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +58 -5
- data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +24 -9
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +85 -16
- data/lib/contrast/agent/assess/tag.rb +1 -1
- data/lib/contrast/agent/assess/tracker.rb +66 -0
- data/lib/contrast/agent/at_exit_hook.rb +6 -6
- data/lib/contrast/agent/class_reopener.rb +14 -11
- data/lib/contrast/agent/deadzone/policy/deadzone_node.rb +1 -1
- data/lib/contrast/agent/deadzone/policy/policy.rb +2 -2
- data/lib/contrast/agent/disable_reaction.rb +1 -1
- data/lib/contrast/agent/exclusion_matcher.rb +1 -1
- data/lib/contrast/agent/inventory.rb +15 -0
- data/lib/contrast/agent/inventory/dependencies.rb +50 -0
- data/lib/contrast/agent/inventory/dependency_analysis.rb +37 -0
- data/lib/contrast/agent/inventory/dependency_usage_analysis.rb +104 -0
- data/lib/contrast/agent/inventory/gemfile_digest_cache.rb +38 -0
- data/lib/contrast/agent/inventory/policy/datastores.rb +2 -2
- data/lib/contrast/agent/inventory/policy/policy.rb +3 -3
- data/lib/contrast/agent/inventory/policy/trigger_node.rb +1 -1
- data/lib/contrast/agent/middleware.rb +33 -34
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +9 -9
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +23 -22
- data/lib/contrast/agent/patching/policy/module_policy.rb +11 -11
- data/lib/contrast/agent/patching/policy/patch.rb +15 -15
- data/lib/contrast/agent/patching/policy/patcher.rb +43 -44
- data/lib/contrast/agent/patching/policy/policy.rb +23 -12
- data/lib/contrast/agent/patching/policy/policy_node.rb +1 -1
- data/lib/contrast/agent/patching/policy/trigger_node.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +6 -8
- data/lib/contrast/agent/protect/policy/applies_deserialization_rule.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_no_sqli_rule.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +7 -6
- data/lib/contrast/agent/protect/policy/applies_sqli_rule.rb +2 -2
- data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +4 -4
- data/lib/contrast/agent/protect/policy/policy.rb +8 -8
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +1 -1
- data/lib/contrast/agent/protect/policy/trigger_node.rb +1 -1
- data/lib/contrast/agent/protect/rule.rb +18 -18
- data/lib/contrast/agent/protect/rule/base.rb +4 -3
- data/lib/contrast/agent/protect/rule/base_service.rb +1 -1
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +5 -5
- data/lib/contrast/agent/protect/rule/deserialization.rb +1 -1
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +1 -1
- data/lib/contrast/agent/protect/rule/no_sqli.rb +1 -1
- data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +1 -0
- data/lib/contrast/agent/protect/rule/path_traversal.rb +4 -5
- data/lib/contrast/agent/protect/rule/sqli.rb +2 -2
- data/lib/contrast/agent/protect/rule/unsafe_file_upload.rb +1 -1
- data/lib/contrast/agent/protect/rule/xss.rb +1 -1
- data/lib/contrast/agent/protect/rule/xxe.rb +3 -5
- data/lib/contrast/agent/protect/rule/xxe/entity_wrapper.rb +2 -2
- data/lib/contrast/agent/railtie.rb +1 -1
- data/lib/contrast/agent/reaction_processor.rb +2 -2
- data/lib/contrast/agent/request.rb +45 -43
- data/lib/contrast/agent/request_context.rb +10 -6
- data/lib/contrast/agent/request_handler.rb +1 -1
- data/lib/contrast/agent/response.rb +23 -12
- data/lib/contrast/agent/rewriter.rb +6 -9
- data/lib/contrast/agent/service_heartbeat.rb +2 -2
- data/lib/contrast/agent/static_analysis.rb +9 -9
- data/lib/contrast/agent/thread.rb +1 -1
- data/lib/contrast/agent/thread_watcher.rb +2 -2
- data/lib/contrast/agent/tracepoint_hook.rb +2 -2
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/api.rb +4 -4
- data/lib/contrast/api/communication.rb +9 -9
- data/lib/contrast/api/communication/messaging_queue.rb +3 -6
- data/lib/contrast/api/communication/response_processor.rb +1 -1
- data/lib/contrast/api/communication/socket_client.rb +41 -6
- data/lib/contrast/api/communication/speedracer.rb +1 -1
- data/lib/contrast/api/communication/tcp_socket.rb +1 -1
- data/lib/contrast/api/communication/unix_socket.rb +1 -1
- data/lib/contrast/api/decorators.rb +17 -14
- data/lib/contrast/api/decorators/address.rb +20 -20
- data/lib/contrast/api/decorators/application_settings.rb +3 -2
- data/lib/contrast/api/decorators/application_update.rb +7 -8
- data/lib/contrast/api/decorators/http_request.rb +13 -12
- data/lib/contrast/api/decorators/input_analysis.rb +3 -2
- data/lib/contrast/api/decorators/library.rb +53 -0
- data/lib/contrast/api/decorators/library_usage_update.rb +30 -0
- data/lib/contrast/api/decorators/message.rb +4 -2
- data/lib/contrast/api/decorators/rasp_rule_sample.rb +2 -1
- data/lib/contrast/api/decorators/route_coverage.rb +3 -2
- data/lib/contrast/api/decorators/server_features.rb +3 -2
- data/lib/contrast/api/decorators/trace_event.rb +28 -25
- data/lib/contrast/api/decorators/trace_event_object.rb +6 -5
- data/lib/contrast/api/decorators/trace_event_signature.rb +5 -4
- data/lib/contrast/api/decorators/trace_taint_range.rb +4 -3
- data/lib/contrast/api/decorators/user_input.rb +4 -4
- data/lib/contrast/common_agent_configuration.rb +2 -2
- data/lib/contrast/components/agent.rb +8 -7
- data/lib/contrast/components/app_context.rb +50 -39
- data/lib/contrast/components/config.rb +32 -50
- data/lib/contrast/components/contrast_service.rb +10 -10
- data/lib/contrast/components/interface.rb +39 -17
- data/lib/contrast/components/inventory.rb +6 -1
- data/lib/contrast/components/logger.rb +1 -1
- data/lib/contrast/components/scope.rb +3 -3
- data/lib/contrast/components/settings.rb +20 -23
- data/lib/contrast/config.rb +18 -18
- data/lib/contrast/config/application_configuration.rb +5 -2
- data/lib/contrast/config/base_configuration.rb +2 -2
- data/lib/contrast/config/inventory_configuration.rb +2 -2
- data/lib/contrast/config/protect_rule_configuration.rb +1 -1
- data/lib/contrast/config/service_configuration.rb +8 -0
- data/lib/contrast/configuration.rb +93 -52
- data/lib/contrast/extension/assess.rb +21 -22
- data/lib/contrast/extension/assess/array.rb +18 -11
- data/lib/contrast/extension/assess/erb.rb +11 -3
- data/lib/contrast/extension/assess/eval_trigger.rb +7 -7
- data/lib/contrast/extension/assess/exec_trigger.rb +2 -2
- data/lib/contrast/extension/assess/fiber.rb +14 -14
- data/lib/contrast/extension/assess/hash.rb +7 -6
- data/lib/contrast/extension/assess/kernel.rb +34 -28
- data/lib/contrast/extension/assess/marshal.rb +67 -0
- data/lib/contrast/extension/assess/regexp.rb +10 -9
- data/lib/contrast/extension/assess/string.rb +23 -23
- data/lib/contrast/extension/inventory.rb +4 -4
- data/lib/contrast/extension/kernel.rb +1 -1
- data/lib/contrast/extension/module.rb +1 -1
- data/lib/contrast/extension/protect.rb +3 -3
- data/lib/contrast/extension/protect/kernel.rb +4 -4
- data/lib/contrast/extension/protect/psych.rb +2 -2
- data/lib/contrast/framework/base_support.rb +1 -1
- data/lib/contrast/framework/manager.rb +10 -11
- data/lib/contrast/framework/rack/patch/session_cookie.rb +23 -29
- data/lib/contrast/framework/rack/patch/support.rb +1 -1
- data/lib/contrast/framework/rack/support.rb +2 -2
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +13 -13
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +7 -13
- data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +11 -11
- data/lib/contrast/framework/rails/patch/support.rb +4 -4
- data/lib/contrast/framework/rails/rewrite/action_controller_railties_helper_inherited.rb +11 -11
- data/lib/contrast/framework/rails/rewrite/active_record_attribute_methods_read.rb +12 -12
- data/lib/contrast/framework/rails/rewrite/active_record_named.rb +4 -4
- data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +12 -12
- data/lib/contrast/framework/rails/support.rb +67 -14
- data/lib/contrast/framework/sinatra/patch/base.rb +12 -12
- data/lib/contrast/framework/sinatra/patch/support.rb +1 -1
- data/lib/contrast/framework/sinatra/support.rb +6 -6
- data/lib/contrast/funchook/funchook.rb +1 -1
- data/lib/contrast/logger/application.rb +13 -5
- data/lib/contrast/logger/format.rb +22 -9
- data/lib/contrast/logger/log.rb +17 -10
- data/lib/contrast/logger/request.rb +30 -0
- data/lib/contrast/tasks/config.rb +1 -1
- data/lib/contrast/tasks/service.rb +2 -2
- data/lib/contrast/utils/assess/sampling_util.rb +2 -2
- data/lib/contrast/utils/assess/tracking_util.rb +49 -4
- data/lib/contrast/utils/class_util.rb +2 -2
- data/lib/contrast/utils/duck_utils.rb +0 -10
- data/lib/contrast/utils/env_configuration_item.rb +2 -1
- data/lib/contrast/utils/hash_digest.rb +2 -1
- data/lib/contrast/utils/heap_dump_util.rb +2 -2
- data/lib/contrast/utils/invalid_configuration_util.rb +21 -22
- data/lib/contrast/utils/inventory_util.rb +3 -10
- data/lib/contrast/utils/io_util.rb +1 -1
- data/lib/contrast/utils/os.rb +1 -1
- data/lib/contrast/utils/ruby_ast_rewriter.rb +1 -1
- data/lib/contrast/utils/sha256_builder.rb +2 -14
- data/lib/contrast/utils/stack_trace_utils.rb +2 -2
- data/lib/contrast/utils/string_utils.rb +11 -6
- data/resources/assess/policy.json +31 -22
- data/ruby-agent.gemspec +21 -19
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +73 -30
- data/lib/contrast/agent/assess/insulator.rb +0 -49
- data/lib/contrast/agent/require_state.rb +0 -61
- data/lib/contrast/extension/assess/assess_extension.rb +0 -147
- data/lib/contrast/utils/boolean_util.rb +0 -30
- data/lib/contrast/utils/freeze_util.rb +0 -32
- data/lib/contrast/utils/gemfile_reader.rb +0 -193
@@ -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
|
-
|
4
|
+
require 'contrast/components/interface'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Agent
|
@@ -184,9 +184,10 @@ module Contrast
|
|
184
184
|
end
|
185
185
|
|
186
186
|
def update_successful_attack_response context, ia_result, result, attack_string = nil
|
187
|
-
|
187
|
+
case mode
|
188
|
+
when Contrast::Api::Settings::ProtectionRule::Mode::MONITOR
|
188
189
|
result.response = Contrast::Api::Dtm::AttackResult::ResponseType::MONITORED
|
189
|
-
|
190
|
+
when Contrast::Api::Settings::ProtectionRule::Mode::BLOCK
|
190
191
|
result.response = Contrast::Api::Dtm::AttackResult::ResponseType::BLOCKED
|
191
192
|
end
|
192
193
|
|
@@ -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
|
-
|
4
|
+
require 'contrast/agent/protect/rule/base'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Agent
|
@@ -1,11 +1,11 @@
|
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
require 'contrast/agent/at_exit_hook'
|
5
|
+
require 'contrast/agent/protect/rule/base_service'
|
6
|
+
require 'contrast/utils/stack_trace_utils'
|
7
|
+
require 'contrast/utils/object_share'
|
8
|
+
require 'contrast/components/interface'
|
9
9
|
|
10
10
|
module Contrast
|
11
11
|
module Agent
|
@@ -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
|
-
|
4
|
+
require 'contrast/agent/protect/rule/base'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Agent
|
@@ -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
|
-
|
4
|
+
require 'contrast/agent/protect/rule/base_service'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Agent
|
@@ -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
|
-
|
4
|
+
require 'contrast/agent/protect/rule/base_service'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Agent
|
@@ -1,9 +1,9 @@
|
|
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
|
-
|
5
|
-
|
6
|
-
|
4
|
+
require 'contrast/agent/protect/rule/base_service'
|
5
|
+
require 'contrast/components/interface'
|
6
|
+
require 'contrast/utils/stack_trace_utils'
|
7
7
|
|
8
8
|
module Contrast
|
9
9
|
module Agent
|
@@ -52,8 +52,7 @@ module Contrast
|
|
52
52
|
def find_attacker context, path
|
53
53
|
attack_result = nil
|
54
54
|
attack_result = super(context, path) if infilter?(context)
|
55
|
-
|
56
|
-
attack_result
|
55
|
+
check_rep_features(context, path, attack_result)
|
57
56
|
end
|
58
57
|
|
59
58
|
# Build a subclass of the RaspRuleSample using the query string and the
|
@@ -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
|
-
|
5
|
-
|
4
|
+
require 'contrast/agent/protect/rule/base_service'
|
5
|
+
require 'contrast/agent/protect/policy/applies_sqli_rule'
|
6
6
|
|
7
7
|
module Contrast
|
8
8
|
module Agent
|
@@ -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
|
-
|
4
|
+
require 'contrast/agent/protect/rule/base_service'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Agent
|
@@ -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
|
-
|
4
|
+
require 'contrast/agent/protect/rule/base_service'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Agent
|
@@ -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
|
-
|
5
|
-
|
4
|
+
require 'contrast/agent/protect/rule/base'
|
5
|
+
require 'contrast/utils/timer'
|
6
6
|
|
7
7
|
module Contrast
|
8
8
|
module Agent
|
@@ -50,14 +50,12 @@ module Contrast
|
|
50
50
|
# string to the end of the last entity declaration.
|
51
51
|
xxe_details.xml = Contrast::Utils::StringUtils.protobuf_safe_string(xml[0, last_idx])
|
52
52
|
ia_result = build_evaluation(xxe_details.xml)
|
53
|
-
|
53
|
+
build_attack_with_match(
|
54
54
|
context,
|
55
55
|
ia_result,
|
56
56
|
nil,
|
57
57
|
nil,
|
58
58
|
details: xxe_details)
|
59
|
-
|
60
|
-
result
|
61
59
|
end
|
62
60
|
|
63
61
|
def build_details xml, _evaluation = nil
|
@@ -27,14 +27,14 @@ module Contrast
|
|
27
27
|
end
|
28
28
|
|
29
29
|
# <!ENTITY name SYSTEM "URI">
|
30
|
-
SYSTEM_ID_REGEXP = /<!ENTITY\s+([a-zA-Z0-f]+)\s+SYSTEM\s+"(?<id>.*?)">/.cs__freeze
|
30
|
+
SYSTEM_ID_REGEXP = /<!ENTITY\s+(?<name>[a-zA-Z0-f]+)\s+SYSTEM\s+"(?<id>.*?)">/.cs__freeze
|
31
31
|
def parse_system_id entity
|
32
32
|
match = SYSTEM_ID_REGEXP.match(entity)
|
33
33
|
match[:id] if match
|
34
34
|
end
|
35
35
|
|
36
36
|
# <!ENTITY name PUBLIC "public_ID" "URI">
|
37
|
-
PUBLIC_ID_REGEXP = /<!ENTITY\s+([a-zA-Z0-f]+)\s+PUBLIC\s+".*?"\s+"(?<id>.*?)">/.cs__freeze
|
37
|
+
PUBLIC_ID_REGEXP = /<!ENTITY\s+(?<name>[a-zA-Z0-f]+)\s+PUBLIC\s+".*?"\s+"(?<id>.*?)">/.cs__freeze
|
38
38
|
def parse_public_id entity
|
39
39
|
match = PUBLIC_ID_REGEXP.match(entity)
|
40
40
|
match[:id] if match
|
@@ -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
|
-
|
4
|
+
require 'contrast/utils/job_servers_running'
|
5
5
|
|
6
6
|
module Contrast
|
7
7
|
module Agent
|
@@ -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
|
-
|
5
|
-
|
4
|
+
require 'contrast/agent/disable_reaction'
|
5
|
+
require 'contrast/components/interface'
|
6
6
|
|
7
7
|
module Contrast
|
8
8
|
module Agent
|
@@ -1,13 +1,13 @@
|
|
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
|
-
|
5
|
-
|
4
|
+
require 'resolv'
|
5
|
+
require 'timeout'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
require 'contrast/utils/object_share'
|
8
|
+
require 'contrast/utils/string_utils'
|
9
|
+
require 'contrast/utils/hash_digest'
|
10
|
+
require 'contrast/components/interface'
|
11
11
|
|
12
12
|
module Contrast
|
13
13
|
module Agent
|
@@ -21,8 +21,8 @@ module Contrast
|
|
21
21
|
|
22
22
|
extend Forwardable
|
23
23
|
|
24
|
-
INNER_REST_TOKEN = %r{
|
25
|
-
LAST_REST_TOKEN = %r{
|
24
|
+
INNER_REST_TOKEN = %r{/\d+/}.cs__freeze
|
25
|
+
LAST_REST_TOKEN = %r{/\d+$}.cs__freeze
|
26
26
|
INNER_NUMBER_MARKER = '/{n}/'
|
27
27
|
LAST_NUMBER_MARKER = '/{n}'
|
28
28
|
|
@@ -46,42 +46,42 @@ module Contrast
|
|
46
46
|
# Should also handle the ;jsessionid.
|
47
47
|
def normalized_uri
|
48
48
|
@_normalized_uri ||= begin
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
49
|
+
path = rack_request.path
|
50
|
+
uri = path.split(Contrast::Utils::ObjectShare::SEMICOLON)[0] # remove ;jsessionid
|
51
|
+
uri = uri.split(Contrast::Utils::ObjectShare::QUESTION_MARK)[0] # remove ?query_string=
|
52
|
+
uri.gsub(INNER_REST_TOKEN, INNER_NUMBER_MARKER) # replace interior tokens
|
53
|
+
uri.gsub(LAST_REST_TOKEN, LAST_NUMBER_MARKER) # replace last token
|
54
|
+
end
|
55
55
|
end
|
56
56
|
|
57
57
|
def document_type
|
58
58
|
@_document_type ||= begin
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
59
|
+
if /xml/i.match?(content_type) || body&.start_with?('<?xml')
|
60
|
+
:XML
|
61
|
+
elsif /json/i.match?(content_type) || body&.match?(/\s*[{\[]/)
|
62
|
+
:JSON
|
63
|
+
else
|
64
|
+
:NORMAL
|
65
|
+
end
|
66
|
+
end
|
67
67
|
end
|
68
68
|
|
69
69
|
# Header keys upcased and any underscores replaced with dashes
|
70
70
|
def headers
|
71
71
|
@_headers ||= begin
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
72
|
+
with_contrast_scope do
|
73
|
+
hash = {}
|
74
|
+
env.each do |key, value|
|
75
|
+
next unless key
|
76
|
+
|
77
|
+
name = key.to_s
|
78
|
+
next unless name.start_with?(Contrast::Utils::ObjectShare::HTTP_SCORE)
|
79
|
+
|
80
|
+
hash[Contrast::Utils::StringUtils.normalized_key(name)] = value
|
81
|
+
end
|
82
|
+
hash
|
83
|
+
end
|
84
|
+
end
|
85
85
|
end
|
86
86
|
|
87
87
|
def body
|
@@ -121,13 +121,13 @@ module Contrast
|
|
121
121
|
|
122
122
|
def file_names
|
123
123
|
@_file_names ||= begin
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
124
|
+
names = {}
|
125
|
+
parsed_data = Rack::Multipart.parse_multipart(rack_request.env)
|
126
|
+
traverse_parsed_multipart(parsed_data, names)
|
127
|
+
rescue StandardError => _e
|
128
|
+
logger.warn('Unable to parse multipart request!')
|
129
|
+
{}
|
130
|
+
end
|
131
131
|
end
|
132
132
|
|
133
133
|
def hash_id
|
@@ -168,7 +168,9 @@ module Contrast
|
|
168
168
|
# (rather than breaking this out into two methods)
|
169
169
|
case val
|
170
170
|
when Tempfile
|
171
|
-
|
171
|
+
# Skip if it's the auto-generated value from rails when it handles
|
172
|
+
# file uploads. The file name will still be sent to SR for analysis.
|
173
|
+
{}
|
172
174
|
when Hash
|
173
175
|
res = val.each_with_object({}) do |(k, v), hash|
|
174
176
|
k = Contrast::Utils::StringUtils.force_utf8(k)
|
@@ -1,11 +1,11 @@
|
|
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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
4
|
+
require 'contrast/utils/timer'
|
5
|
+
require 'contrast/agent/request'
|
6
|
+
require 'contrast/agent/response'
|
7
|
+
require 'contrast/utils/inventory_util'
|
8
|
+
require 'contrast/components/interface'
|
9
9
|
|
10
10
|
module Contrast
|
11
11
|
module Agent
|
@@ -19,6 +19,7 @@ module Contrast
|
|
19
19
|
EMPTY_INPUT_ANALYSIS_PB = Contrast::Api::Settings::InputAnalysis.new
|
20
20
|
|
21
21
|
attr_reader :timer,
|
22
|
+
:logging_hash,
|
22
23
|
:speedracer_input_analysis,
|
23
24
|
:request,
|
24
25
|
:response,
|
@@ -29,8 +30,11 @@ module Contrast
|
|
29
30
|
|
30
31
|
def initialize rack_request, app_loaded = true
|
31
32
|
with_contrast_scope do
|
32
|
-
# all requests get a timer
|
33
|
+
# all requests get a timer and hash
|
33
34
|
@timer = Contrast::Utils::Timer.new
|
35
|
+
@logging_hash = {
|
36
|
+
request_id: __id__
|
37
|
+
}
|
34
38
|
|
35
39
|
# instantiate helper for request and response
|
36
40
|
@request = Contrast::Agent::Request.new(rack_request)
|
@@ -18,7 +18,7 @@ module Contrast
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def send_activity_messages
|
21
|
-
Contrast::
|
21
|
+
Contrast::Agent::Inventory::DependencyUsageAnalysis.instance.generate_library_usage(context.activity)
|
22
22
|
[context.server_activity, context.activity, context.observed_route].each do |message|
|
23
23
|
Contrast::Agent.messaging_queue.send_event_eventually(message)
|
24
24
|
end
|
@@ -1,13 +1,13 @@
|
|
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
|
-
|
5
|
-
|
4
|
+
require 'resolv'
|
5
|
+
require 'timeout'
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
require 'contrast/utils/object_share'
|
8
|
+
require 'contrast/utils/string_utils'
|
9
|
+
require 'contrast/utils/hash_digest'
|
10
|
+
require 'contrast/components/interface'
|
11
11
|
|
12
12
|
module Contrast
|
13
13
|
module Agent
|
@@ -44,14 +44,9 @@ module Contrast
|
|
44
44
|
context_response = Contrast::Api::Dtm::HttpResponse.new
|
45
45
|
context_response.response_code = response_code.to_i
|
46
46
|
headers&.each_pair do |key, value|
|
47
|
-
|
48
|
-
v = Contrast::Utils::StringUtils.force_utf8(value)
|
49
|
-
context_response.response_headers[k] = v
|
47
|
+
append_pair(context_response.normalized_response_headers, key, value)
|
50
48
|
end
|
51
|
-
context_response.parsed_response_headers = true
|
52
|
-
|
53
49
|
context_response.response_body_binary = Contrast::Utils::StringUtils.force_utf8(body)
|
54
|
-
context_response.parsed_response_body = false
|
55
50
|
|
56
51
|
doc_type = document_type
|
57
52
|
context_response.document_type = doc_type if doc_type
|
@@ -97,6 +92,22 @@ module Contrast
|
|
97
92
|
|
98
93
|
private
|
99
94
|
|
95
|
+
# From the dtm for normalized_response_headers:
|
96
|
+
# Key is UPPERCASE_UNDERSCORE
|
97
|
+
#
|
98
|
+
# Example: Content-Type: text/html; charset=utf-8
|
99
|
+
# "CONTENT_TYPE" => Content-Type,["text/html; charset=utf8"]
|
100
|
+
def append_pair map, key, value
|
101
|
+
return unless key && value
|
102
|
+
return if value.is_a?(Hash)
|
103
|
+
|
104
|
+
safe_key = Contrast::Utils::StringUtils.force_utf8(key)
|
105
|
+
hash_key = Contrast::Utils::StringUtils.normalized_key(safe_key)
|
106
|
+
map[hash_key] ||= Contrast::Api::Dtm::Pair.new
|
107
|
+
map[hash_key].key = safe_key
|
108
|
+
map[hash_key].values << Contrast::Utils::StringUtils.force_utf8(value)
|
109
|
+
end
|
110
|
+
|
100
111
|
HTTP_PREFIX = /^[Hh][Tt][Tt][Pp][_-]/i.cs__freeze
|
101
112
|
|
102
113
|
# Given some holder of the content of the response's body, extract that
|
@@ -3,10 +3,10 @@
|
|
3
3
|
|
4
4
|
# intentional -- we're using a << operator here
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
require 'contrast/agent/class_reopener'
|
7
|
+
require 'contrast/agent/patching/policy/patch_status'
|
8
|
+
require 'contrast/components/interface'
|
9
|
+
require 'contrast/utils/ruby_ast_rewriter'
|
10
10
|
|
11
11
|
module Contrast
|
12
12
|
module Agent
|
@@ -61,9 +61,7 @@ module Contrast
|
|
61
61
|
status ||= Contrast::Agent::Patching::Policy::PatchStatus.get_status(mod)
|
62
62
|
status.failed_rewrite!
|
63
63
|
ensure
|
64
|
-
|
65
|
-
opener&.commit_patches
|
66
|
-
end
|
64
|
+
opener&.commit_patches
|
67
65
|
logger.trace('Rewriting complete',
|
68
66
|
module: module_data.name,
|
69
67
|
result: Contrast::Agent::Patching::Policy::PatchStatus.get_status(
|
@@ -163,8 +161,7 @@ module Contrast
|
|
163
161
|
|
164
162
|
def rewrite_method original_source_code
|
165
163
|
new_code = rewrite(original_source_code)
|
166
|
-
|
167
|
-
new_code
|
164
|
+
remove_self_definition(new_code)
|
168
165
|
end
|
169
166
|
|
170
167
|
def rewrite source
|