contrast-agent 3.12.2 → 3.13.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.dockerignore +0 -1
- data/.gitignore +1 -1
- data/.simplecov +1 -1
- data/Rakefile +31 -0
- data/ext/build_funchook.rb +0 -2
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.c +2 -8
- data/ext/cs__assess_fiber_track/cs__assess_fiber_track.h +0 -1
- data/ext/cs__assess_string_interpolation26/cs__assess_string_interpolation26.c +1 -6
- data/ext/cs__assess_yield_track/cs__assess_yield_track.c +1 -5
- data/ext/cs__assess_yield_track/cs__assess_yield_track.h +0 -1
- data/ext/cs__common/cs__common.c +24 -0
- data/ext/cs__common/cs__common.h +3 -0
- data/ext/cs__common/extconf.rb +0 -14
- data/ext/extconf_common.rb +0 -28
- data/lib/contrast.rb +3 -1
- data/lib/contrast/agent.rb +14 -2
- data/lib/contrast/agent/assess/contrast_event.rb +28 -167
- data/lib/contrast/agent/assess/events/source_event.rb +3 -7
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +1 -1
- data/lib/contrast/agent/assess/policy/policy_node.rb +4 -98
- data/lib/contrast/agent/assess/policy/propagation_method.rb +1 -2
- data/lib/contrast/agent/assess/policy/propagation_node.rb +5 -1
- data/lib/contrast/agent/assess/policy/propagator/base.rb +1 -1
- data/lib/contrast/agent/assess/policy/propagator/insert.rb +1 -4
- data/lib/contrast/agent/assess/policy/propagator/match_data.rb +9 -1
- data/lib/contrast/agent/assess/policy/propagator/remove.rb +6 -11
- data/lib/contrast/agent/assess/policy/propagator/select.rb +4 -4
- data/lib/contrast/agent/assess/policy/propagator/split.rb +2 -2
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +4 -4
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +6 -10
- data/lib/contrast/agent/assess/policy/source_method.rb +1 -2
- data/lib/contrast/agent/assess/policy/trigger_method.rb +1 -9
- data/lib/contrast/agent/assess/policy/trigger_node.rb +16 -4
- data/lib/contrast/agent/assess/properties.rb +4 -382
- data/lib/contrast/agent/assess/property/evented.rb +78 -0
- data/lib/contrast/agent/assess/property/tagged.rb +339 -0
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +2 -20
- data/lib/contrast/agent/assess/tag.rb +27 -12
- data/lib/contrast/agent/at_exit_hook.rb +3 -1
- data/lib/contrast/agent/exclusion_matcher.rb +2 -2
- data/lib/contrast/agent/inventory/policy/datastores.rb +0 -1
- data/lib/contrast/agent/middleware.rb +2 -14
- data/lib/contrast/agent/patching/policy/patch.rb +1 -1
- data/lib/contrast/agent/patching/policy/policy.rb +3 -3
- data/lib/contrast/agent/patching/policy/policy_node.rb +2 -2
- data/lib/contrast/agent/protect/policy/rule_applicator.rb +2 -2
- data/lib/contrast/agent/protect/rule/base.rb +19 -31
- data/lib/contrast/agent/protect/rule/base_service.rb +1 -1
- data/lib/contrast/agent/protect/rule/http_method_tampering.rb +2 -7
- data/lib/contrast/agent/protect/rule/xxe.rb +1 -0
- data/lib/contrast/agent/reaction_processor.rb +3 -3
- data/lib/contrast/agent/request.rb +92 -331
- data/lib/contrast/agent/request_context.rb +15 -15
- data/lib/contrast/agent/request_handler.rb +1 -1
- data/lib/contrast/agent/response.rb +2 -14
- data/lib/contrast/agent/scope.rb +1 -1
- data/lib/contrast/agent/service_heartbeat.rb +7 -9
- data/lib/contrast/agent/static_analysis.rb +1 -1
- data/lib/contrast/agent/thread_watcher.rb +49 -0
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/agent/worker_thread.rb +24 -0
- data/lib/contrast/api.rb +3 -5
- data/lib/contrast/api/communication.rb +20 -0
- data/lib/contrast/api/communication/connection_status.rb +41 -0
- data/lib/contrast/api/communication/messaging_queue.rb +79 -0
- data/lib/contrast/{utils/service_response_util.rb → api/communication/response_processor.rb} +9 -18
- data/lib/contrast/api/communication/service_lifecycle.rb +61 -0
- data/lib/contrast/api/communication/socket.rb +45 -0
- data/lib/contrast/api/communication/socket_client.rb +76 -0
- data/lib/contrast/api/communication/speedracer.rb +111 -0
- data/lib/contrast/api/communication/tcp_socket.rb +31 -0
- data/lib/contrast/api/communication/unix_socket.rb +27 -0
- data/lib/contrast/api/decorators.rb +10 -0
- data/lib/contrast/api/decorators/address.rb +60 -0
- data/lib/contrast/api/decorators/application_settings.rb +7 -3
- data/lib/contrast/api/decorators/application_update.rb +0 -9
- data/lib/contrast/api/decorators/http_request.rb +139 -0
- data/lib/contrast/api/decorators/message.rb +75 -0
- data/lib/contrast/api/decorators/rasp_rule_sample.rb +28 -0
- data/lib/contrast/api/decorators/route_coverage.rb +57 -0
- data/lib/contrast/api/decorators/trace_event.rb +99 -0
- data/lib/contrast/api/decorators/trace_event_object.rb +57 -0
- data/lib/contrast/api/decorators/trace_event_signature.rb +46 -0
- data/lib/contrast/api/decorators/trace_taint_range.rb +51 -0
- data/lib/contrast/api/decorators/trace_taint_range_tags.rb +109 -0
- data/lib/contrast/api/decorators/user_input.rb +40 -0
- data/lib/contrast/components/app_context.rb +0 -7
- data/lib/contrast/components/config.rb +4 -9
- data/lib/contrast/components/interface.rb +1 -1
- data/lib/contrast/components/settings.rb +0 -6
- data/lib/contrast/extension/assess.rb +0 -1
- data/lib/contrast/extension/assess/assess_extension.rb +1 -2
- data/lib/contrast/extension/assess/fiber.rb +1 -1
- data/lib/contrast/extension/assess/string.rb +1 -1
- data/lib/contrast/extension/inventory.rb +0 -1
- data/lib/contrast/framework/base_support.rb +0 -23
- data/lib/contrast/framework/manager.rb +0 -9
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +1 -3
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +3 -4
- data/lib/contrast/framework/rails/support.rb +3 -32
- data/lib/contrast/framework/sinatra/patch/base.rb +1 -1
- data/lib/contrast/framework/sinatra/support.rb +11 -22
- data/lib/contrast/funchook/funchook.rb +45 -0
- data/lib/contrast/logger/application.rb +1 -1
- data/lib/contrast/logger/format.rb +51 -0
- data/lib/contrast/logger/log.rb +8 -2
- data/lib/contrast/utils/assess/tracking_util.rb +45 -20
- data/lib/contrast/utils/hash_digest.rb +11 -2
- data/lib/contrast/utils/invalid_configuration_util.rb +1 -17
- data/lib/contrast/utils/inventory_util.rb +2 -7
- data/lib/contrast/utils/object_share.rb +0 -1
- data/lib/contrast/utils/os.rb +16 -4
- data/lib/contrast/utils/stack_trace_utils.rb +0 -1
- data/lib/contrast/utils/tag_util.rb +1 -1
- data/lib/contrast/utils/thread_tracker.rb +1 -14
- data/lib/contrast/utils/timer.rb +1 -17
- data/ruby-agent.gemspec +4 -4
- metadata +48 -72
- data/funchook/Makefile +0 -29
- data/funchook/autom4te.cache/output.0 +0 -4964
- data/funchook/autom4te.cache/requests +0 -77
- data/funchook/autom4te.cache/traces.0 +0 -361
- data/funchook/config.log +0 -651
- data/funchook/config.status +0 -1015
- data/funchook/configure +0 -4964
- data/funchook/src/Makefile +0 -70
- data/funchook/src/config.h +0 -101
- data/funchook/src/config.h.in +0 -100
- data/funchook/src/decoder.o +0 -0
- data/funchook/src/distorm.o +0 -0
- data/funchook/src/funchook.o +0 -0
- data/funchook/src/funchook_io.o +0 -0
- data/funchook/src/funchook_syscall.o +0 -0
- data/funchook/src/funchook_unix.o +0 -0
- data/funchook/src/funchook_x86.o +0 -0
- data/funchook/src/instructions.o +0 -0
- data/funchook/src/insts.o +0 -0
- data/funchook/src/libfunchook.dylib +0 -0
- data/funchook/src/mnemonics.o +0 -0
- data/funchook/src/operands.o +0 -0
- data/funchook/src/os_func.o +0 -0
- data/funchook/src/os_func_unix.o +0 -0
- data/funchook/src/prefix.o +0 -0
- data/funchook/src/printf_base.o +0 -0
- data/funchook/src/textdefs.o +0 -0
- data/funchook/src/wstring.o +0 -0
- data/funchook/test/Makefile +0 -43
- data/funchook/test/funchook_test +0 -0
- data/funchook/test/libfunchook_test.so +0 -0
- data/funchook/test/libfunchook_test.so.dSYM/Contents/Info.plist +0 -20
- data/funchook/test/libfunchook_test.so.dSYM/Contents/Resources/DWARF/libfunchook_test.so +0 -0
- data/funchook/test/test_main.o +0 -0
- data/funchook/test/x86_64_test.o +0 -0
- data/lib/contrast/agent/assess/adjusted_span.rb +0 -27
- data/lib/contrast/agent/socket_client.rb +0 -134
- data/lib/contrast/api/connection_status.rb +0 -49
- data/lib/contrast/api/socket.rb +0 -43
- data/lib/contrast/api/speedracer.rb +0 -188
- data/lib/contrast/api/tcp_socket.rb +0 -29
- data/lib/contrast/api/unix_socket.rb +0 -25
- data/lib/contrast/framework/sinatra/application_helper.rb +0 -51
- data/lib/contrast/framework/view_technologies_descriptor.rb +0 -21
- data/lib/contrast/internal_exception.rb +0 -8
- data/lib/contrast/utils/cache.rb +0 -58
- data/lib/contrast/utils/service_sender_util.rb +0 -167
- data/lib/contrast/utils/sinatra_helper.rb +0 -49
@@ -1,8 +1,6 @@
|
|
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/service_sender_util'
|
5
|
-
|
6
4
|
module Contrast
|
7
5
|
module Framework
|
8
6
|
module Rails
|
@@ -15,7 +13,7 @@ module Contrast
|
|
15
13
|
return unless (context = Contrast::Agent::REQUEST_TRACKER.current)
|
16
14
|
|
17
15
|
[context.server_activity, context.activity, context.observed_route].each do |msg|
|
18
|
-
Contrast::
|
16
|
+
Contrast::Agent.messaging_queue.send_event_immediately(msg)
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
@@ -23,7 +23,6 @@ module Contrast
|
|
23
23
|
include Contrast::Utils::InvalidConfigurationUtil
|
24
24
|
|
25
25
|
def analyze_session_store *args
|
26
|
-
return unless AGENT.enabled?
|
27
26
|
return if PROTECT.enabled?
|
28
27
|
|
29
28
|
apply_httponly_disabled(*args)
|
@@ -54,7 +53,7 @@ module Contrast
|
|
54
53
|
|
55
54
|
rails_session_settings = args[1]
|
56
55
|
with_contrast_scope do
|
57
|
-
cs__report_finding(CS__SESSION_TIMEOUT_NAME, rails_session_settings, caller_locations(
|
56
|
+
cs__report_finding(CS__SESSION_TIMEOUT_NAME, rails_session_settings, caller_locations(6, 5)[0])
|
58
57
|
end
|
59
58
|
rescue StandardError => e
|
60
59
|
begin
|
@@ -70,7 +69,7 @@ module Contrast
|
|
70
69
|
|
71
70
|
rails_session_settings = args[1]
|
72
71
|
with_contrast_scope do
|
73
|
-
cs__report_finding(CS__SECURE_RULE_NAME, rails_session_settings, caller_locations(
|
72
|
+
cs__report_finding(CS__SECURE_RULE_NAME, rails_session_settings, caller_locations(6, 5)[0])
|
74
73
|
end
|
75
74
|
rescue StandardError => e
|
76
75
|
begin
|
@@ -86,7 +85,7 @@ module Contrast
|
|
86
85
|
|
87
86
|
rails_session_settings = args[1]
|
88
87
|
with_contrast_scope do
|
89
|
-
cs__report_finding(CS__HTTPONLY_RULE_NAME, rails_session_settings, caller_locations(
|
88
|
+
cs__report_finding(CS__HTTPONLY_RULE_NAME, rails_session_settings, caller_locations(6, 5)[0])
|
90
89
|
end
|
91
90
|
rescue StandardError => e
|
92
91
|
begin
|
@@ -1,10 +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
|
-
cs__scoped_require 'contrast/api/
|
4
|
+
cs__scoped_require 'contrast/api/dtm.pb'
|
5
5
|
cs__scoped_require 'contrast/framework/base_support'
|
6
6
|
cs__scoped_require 'contrast/framework/rails/patch/support'
|
7
|
-
cs__scoped_require 'contrast/framework/view_technologies_descriptor'
|
8
7
|
cs__scoped_require 'contrast/utils/string_utils'
|
9
8
|
|
10
9
|
module Contrast
|
@@ -15,15 +14,6 @@ module Contrast
|
|
15
14
|
extend Contrast::Framework::Rails::Patch::Support
|
16
15
|
|
17
16
|
class << self
|
18
|
-
RAILS_VIEWS = [
|
19
|
-
Contrast::Framework::ViewTechnologiesDescriptor.new('app/assets', 'coffee', %w[CoffeeScript]),
|
20
|
-
Contrast::Framework::ViewTechnologiesDescriptor.new('app/assets', 'scss', %w[SASS]),
|
21
|
-
Contrast::Framework::ViewTechnologiesDescriptor.new('app/views', 'html', %w[HTML5]),
|
22
|
-
Contrast::Framework::ViewTechnologiesDescriptor.new('app/views', 'html.erb', %w[HTML5 ERB]),
|
23
|
-
Contrast::Framework::ViewTechnologiesDescriptor.new('app/views', 'html.haml', %w[HTML5 HAML]),
|
24
|
-
Contrast::Framework::ViewTechnologiesDescriptor.new('public', 'html', %w[HTML5])
|
25
|
-
].cs__freeze
|
26
|
-
|
27
17
|
RAILS_MODULE_NAME_VERSION = Gem::Version.new('6.0.0')
|
28
18
|
|
29
19
|
def detection_class
|
@@ -51,13 +41,9 @@ module Contrast
|
|
51
41
|
'rails'
|
52
42
|
end
|
53
43
|
|
54
|
-
def scan_views
|
55
|
-
scan_view_directories(RAILS_VIEWS)
|
56
|
-
end
|
57
|
-
|
58
44
|
def collect_routes
|
59
45
|
routes = ::Rails.application.routes.routes.map do |route|
|
60
|
-
|
46
|
+
Contrast::Api::Dtm::RouteCoverage.from_action_dispatch_journey(route)
|
61
47
|
end
|
62
48
|
routes
|
63
49
|
end
|
@@ -79,7 +65,7 @@ module Contrast
|
|
79
65
|
route = full_route[2] # route w/ highest precedence
|
80
66
|
return unless route
|
81
67
|
|
82
|
-
|
68
|
+
Contrast::Api::Dtm::RouteCoverage.from_action_dispatch_journey(route)
|
83
69
|
end
|
84
70
|
|
85
71
|
def retrieve_request env
|
@@ -93,21 +79,6 @@ module Contrast
|
|
93
79
|
|
94
80
|
env[AC_INSTANCE].cs__class.included_modules.include?(::ActionController::Live)
|
95
81
|
end
|
96
|
-
|
97
|
-
private
|
98
|
-
|
99
|
-
# Convert ActionDispatch::Journey::Route to Contrast::Api::Dtm::RouteCoverage
|
100
|
-
def route_to_coverage route
|
101
|
-
route_coverage = Contrast::Api::Dtm::RouteCoverage.new
|
102
|
-
route_coverage.route = "#{ route.defaults[:controller] }##{ route.defaults[:action] }"
|
103
|
-
|
104
|
-
verb = source_or_string(route.verb)
|
105
|
-
route_coverage.verb = Contrast::Utils::StringUtils.force_utf8(verb)
|
106
|
-
|
107
|
-
url = source_or_string(route.path.spec)
|
108
|
-
route_coverage.url = Contrast::Utils::StringUtils.force_utf8(url)
|
109
|
-
route_coverage
|
110
|
-
end
|
111
82
|
end
|
112
83
|
end
|
113
84
|
end
|
@@ -70,7 +70,7 @@ module Contrast
|
|
70
70
|
routes.each do |pattern, _, _| # Mustermann::Sinatra
|
71
71
|
next unless pattern.params(route)
|
72
72
|
|
73
|
-
dtm = Contrast::
|
73
|
+
dtm = Contrast::Api::Dtm::RouteCoverage.from_sinatra_route(clazz, method, pattern)
|
74
74
|
context.append_route_coverage(dtm)
|
75
75
|
break
|
76
76
|
end
|
@@ -2,7 +2,6 @@
|
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
cs__scoped_require 'contrast/framework/base_support'
|
5
|
-
cs__scoped_require 'contrast/framework/sinatra/application_helper'
|
6
5
|
cs__scoped_require 'contrast/framework/sinatra/patch/support'
|
7
6
|
|
8
7
|
module Contrast
|
@@ -10,7 +9,6 @@ module Contrast
|
|
10
9
|
module Sinatra
|
11
10
|
# Used when Sinatra is present to define framework specific behavior
|
12
11
|
class Support < BaseSupport
|
13
|
-
extend Contrast::Framework::Sinatra::ApplicationHelper
|
14
12
|
extend Contrast::Framework::Sinatra::Patch::Support
|
15
13
|
class << self
|
16
14
|
def detection_class
|
@@ -37,12 +35,6 @@ module Contrast
|
|
37
35
|
'sinatra'
|
38
36
|
end
|
39
37
|
|
40
|
-
def scan_views
|
41
|
-
return unless app_class
|
42
|
-
|
43
|
-
scan_view_directories(scannable_view_dirs)
|
44
|
-
end
|
45
|
-
|
46
38
|
# Iterate over every class that extends Sinatra::Base, pull out its routes
|
47
39
|
# (array of arrays with Mustermann::Sinatra as [][0]) and convert them into
|
48
40
|
# Contrast::Api::Dtm::RouteCoverage
|
@@ -56,7 +48,7 @@ module Contrast
|
|
56
48
|
class_routes.each_pair do |method, list|
|
57
49
|
# item: [ Mustermann::Sinatra, [], Proc]
|
58
50
|
list.each do |item|
|
59
|
-
routes <<
|
51
|
+
routes << Contrast::Api::Dtm::RouteCoverage.from_sinatra_route(clazz, method, item[0])
|
60
52
|
end
|
61
53
|
end
|
62
54
|
end
|
@@ -74,6 +66,16 @@ module Contrast
|
|
74
66
|
|
75
67
|
private
|
76
68
|
|
69
|
+
def app_class
|
70
|
+
return nil unless defined?(::Sinatra) && defined?(::Sinatra::Base)
|
71
|
+
|
72
|
+
@_app_class ||= begin
|
73
|
+
sinatra_layers = ObjectSpace.each_object(::Sinatra::Base).to_a
|
74
|
+
result_layer = sinatra_layers.find { |layer| layer.app.nil? }
|
75
|
+
result_layer
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
77
79
|
# Iterate over every class that extends Sinatra::Base, pull out its routes
|
78
80
|
# (array of arrays with Mustermann::Sinatra as [][0]) and convert them into
|
79
81
|
# Contrast::Api::Dtm::RouteCoverage
|
@@ -89,19 +91,6 @@ module Contrast
|
|
89
91
|
logger.trace('Sinatra controller found with no route instances', module: controller)
|
90
92
|
nil
|
91
93
|
end
|
92
|
-
|
93
|
-
# TODO: RUBY-763
|
94
|
-
# given clazz, method, and Mustermann::Sinatra, build a
|
95
|
-
# Contrast::Api::Dtm::RouteCoverage
|
96
|
-
def route_to_coverage clazz, method, pattern
|
97
|
-
safe_pattern = source_or_string(pattern)
|
98
|
-
|
99
|
-
route_coverage = Contrast::Api::Dtm::RouteCoverage.new
|
100
|
-
route_coverage.route = "#{ clazz }##{ method } #{ safe_pattern }"
|
101
|
-
route_coverage.verb = Contrast::Utils::StringUtils.force_utf8(method)
|
102
|
-
route_coverage.url = Contrast::Utils::StringUtils.force_utf8(safe_pattern)
|
103
|
-
route_coverage
|
104
|
-
end
|
105
94
|
end
|
106
95
|
end
|
107
96
|
end
|
@@ -0,0 +1,45 @@
|
|
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
|
+
# This module is used to find funchook library and determine availability
|
6
|
+
module Funchook
|
7
|
+
include Contrast::Components::Interface
|
8
|
+
access_component :logging
|
9
|
+
attr_accessor :path
|
10
|
+
|
11
|
+
# Possible platform library files
|
12
|
+
ACCEPTABLE_FILES = %w[libfunchook.dylib libfunchook.so].cs__freeze
|
13
|
+
|
14
|
+
# Top level agent directories that should have the funchook libraries
|
15
|
+
SEARCH_DIRS = [
|
16
|
+
File.join('ext'),
|
17
|
+
File.join('shared_libraries'),
|
18
|
+
File.join('funchook', 'src')
|
19
|
+
].cs__freeze
|
20
|
+
|
21
|
+
AGENT_ROOT = File.join(__dir__, '..', '..', '..')
|
22
|
+
|
23
|
+
def self.resolve_path!
|
24
|
+
actual_path_segments = SEARCH_DIRS.product(ACCEPTABLE_FILES).find do |potential_funchook_path|
|
25
|
+
load_path = absolute_path(potential_funchook_path)
|
26
|
+
File.exist?(load_path)
|
27
|
+
end
|
28
|
+
|
29
|
+
if actual_path_segments.nil?
|
30
|
+
logger.warn('Unable to find funchook')
|
31
|
+
else
|
32
|
+
@path = absolute_path(actual_path_segments)
|
33
|
+
logger.info('Funchook found', path: @path)
|
34
|
+
end
|
35
|
+
@path
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.absolute_path path_array
|
39
|
+
File.absolute_path(File.join(AGENT_ROOT, *path_array))
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.available?
|
43
|
+
@_available ||= !!resolve_path!
|
44
|
+
end
|
45
|
+
end
|
@@ -35,7 +35,7 @@ module Contrast
|
|
35
35
|
|
36
36
|
loggable = CONFIG.raw.send(:load_config)
|
37
37
|
loggable.delete('api')
|
38
|
-
info('Current configuration',
|
38
|
+
info('Current configuration', configuration: JSON.pretty_generate(loggable))
|
39
39
|
end
|
40
40
|
|
41
41
|
def application_libraries
|
@@ -0,0 +1,51 @@
|
|
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 'ougai'
|
5
|
+
cs__scoped_require 'contrast/utils/thread_tracker'
|
6
|
+
|
7
|
+
module Contrast
|
8
|
+
module Logger
|
9
|
+
# Our format for the Ougai logger allowing for custom log format that
|
10
|
+
# extends the behavior of the default Ougai logger
|
11
|
+
class Format < Ougai::Formatters::Bunyan
|
12
|
+
LOG_TRACKER = Contrast::Utils::ThreadTracker.new
|
13
|
+
# Our override of the _call method to add in the extra data that we want,
|
14
|
+
# based on
|
15
|
+
# https://github.com/tilfin/ougai/blob/1fe4fc2587be8eabc47d36dc57ee2814f8a0162b/lib/ougai/formatters/bunyan.rb#L26
|
16
|
+
# By default, it adds:
|
17
|
+
# name: progname || @app_name,
|
18
|
+
# hostname: @hostname,
|
19
|
+
# pid: $$,
|
20
|
+
# level: to_level(severity),
|
21
|
+
# time: time,
|
22
|
+
# v: 0
|
23
|
+
# and we add the fields from #format_hash
|
24
|
+
def _call severity, time, progname, data
|
25
|
+
super(severity,
|
26
|
+
time,
|
27
|
+
progname,
|
28
|
+
format_hash.merge(data)
|
29
|
+
)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
# The extra values to add to the Bunyan hash. Because this is unique per
|
35
|
+
# thread, we'll create it once and then store it, rather than create a
|
36
|
+
# new hash on every log call.
|
37
|
+
# @return [Hash{Symbol => Object}] the extra data to log
|
38
|
+
# tid: current thread id
|
39
|
+
def format_hash
|
40
|
+
hash = LOG_TRACKER.get(:thread_id_hash)
|
41
|
+
unless hash
|
42
|
+
hash = {
|
43
|
+
tid: Thread.current.object_id
|
44
|
+
}
|
45
|
+
LOG_TRACKER.set(:thread_id_hash, hash)
|
46
|
+
end
|
47
|
+
hash
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/contrast/logger/log.rb
CHANGED
@@ -8,6 +8,7 @@ cs__scoped_require 'singleton'
|
|
8
8
|
cs__scoped_require 'contrast/components/interface'
|
9
9
|
cs__scoped_require 'contrast/extension/module'
|
10
10
|
cs__scoped_require 'contrast/logger/application'
|
11
|
+
cs__scoped_require 'contrast/logger/format'
|
11
12
|
cs__scoped_require 'contrast/logger/time'
|
12
13
|
|
13
14
|
module Contrast
|
@@ -90,6 +91,7 @@ module Contrast
|
|
90
91
|
add_contrast_loggers(logger)
|
91
92
|
logger.progname = 'Contrast Agent'
|
92
93
|
logger.level = level_const
|
94
|
+
logger.formatter = Contrast::Logger::Format.new
|
93
95
|
logger.formatter.datetime_format = '%Y-%m-%dT%H:%M:%S.%L%z'
|
94
96
|
logger
|
95
97
|
end
|
@@ -108,10 +110,14 @@ module Contrast
|
|
108
110
|
if write_permission?(path)
|
109
111
|
path
|
110
112
|
elsif write_permission?(DEFAULT_NAME)
|
111
|
-
|
113
|
+
# Log once when the path is invalid. We'll change to this path, so no
|
114
|
+
# need to log again.
|
115
|
+
puts "[!] Unable to write to '#{ path }'. Writing to default log '#{ DEFAULT_NAME }' instead." if previous_path != DEFAULT_NAME
|
112
116
|
DEFAULT_NAME
|
113
117
|
else
|
114
|
-
|
118
|
+
# Log once when the path is invalid. We'll change to this path, so no
|
119
|
+
# need to log again.
|
120
|
+
puts "[!] Unable to write to '#{ path }'. Writing to standard out instead." if previous_path != STDOUT_STR
|
115
121
|
STDOUT_STR
|
116
122
|
end
|
117
123
|
end
|
@@ -12,30 +12,55 @@ module Contrast
|
|
12
12
|
|
13
13
|
access_component :logging
|
14
14
|
|
15
|
-
|
16
|
-
|
15
|
+
class << self
|
16
|
+
# Public interface to our tracking check, isolating the internals
|
17
|
+
# required for recursion.
|
18
|
+
#
|
19
|
+
# @param obj [Object] the thing to check if tracked
|
20
|
+
# @return [Boolean] if the obj, or something in it if a collection, is
|
21
|
+
# tracked.
|
22
|
+
def tracked? obj
|
23
|
+
_tracked?(obj, 0)
|
24
|
+
end
|
17
25
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
private
|
27
|
+
|
28
|
+
# Sometimes things are nested inside of each other, such as an Array
|
29
|
+
# holding a Hash, holding that Array. In those cases, rather than
|
30
|
+
# entering an infinite loop, we'll break out.
|
31
|
+
# Right now, that level of nesting has been arbitrarily set to 10.
|
32
|
+
#
|
33
|
+
# @param obj [Object] the thing to check if tracked
|
34
|
+
# @param idx [Integer] the number of levels nested we've gone
|
35
|
+
# @return [Boolean] if the obj, or something in it if a collection, is
|
36
|
+
# tracked.
|
37
|
+
def _tracked? obj, idx
|
38
|
+
return false if obj.nil?
|
39
|
+
return false if idx > 10
|
40
|
+
|
41
|
+
idx += 1
|
42
|
+
if Contrast::Utils::DuckUtils.iterable_hash?(obj)
|
43
|
+
obj.each_pair do |k, v|
|
44
|
+
return true if _tracked?(k, idx)
|
45
|
+
return true if _tracked?(v, idx)
|
46
|
+
end
|
47
|
+
false
|
48
|
+
elsif Contrast::Utils::DuckUtils.iterable_enumerable?(obj)
|
49
|
+
obj.any? do |ele|
|
50
|
+
_tracked?(ele, idx) unless obj == ele
|
51
|
+
end
|
52
|
+
elsif Contrast::Utils::DuckUtils.quacks_to?(obj, :cs__tracked?)
|
53
|
+
obj.cs__tracked?
|
54
|
+
else
|
55
|
+
false
|
27
56
|
end
|
28
|
-
|
29
|
-
|
30
|
-
|
57
|
+
rescue StandardError => e
|
58
|
+
# This is used to ask if a ton of objects are tracked. They may not
|
59
|
+
# all be iterable. Bad things could happen in some cases, like when
|
60
|
+
# checking a closed statement for SQL injection trigger events
|
61
|
+
logger.warn('Failed to determine tracking', e, module: obj.cs__class)
|
31
62
|
false
|
32
63
|
end
|
33
|
-
rescue StandardError => e
|
34
|
-
# This is used to ask if a ton of objects are tracked. They may not
|
35
|
-
# all be iterable. Bad things could happen in some cases, like when
|
36
|
-
# checking a closed statement for SQL injection trigger events
|
37
|
-
logger.warn('Failed to determine tracking', e, module: obj.cs__class)
|
38
|
-
false
|
39
64
|
end
|
40
65
|
end
|
41
66
|
end
|
@@ -32,8 +32,8 @@ module Contrast
|
|
32
32
|
request.parameters.each_key do |name|
|
33
33
|
hash.update(name)
|
34
34
|
end
|
35
|
-
cl = request.
|
36
|
-
hash.
|
35
|
+
cl = request.headers[CONTENT_LENGTH_HEADER]
|
36
|
+
hash.update_on_content_length(cl) if cl
|
37
37
|
hash.finish
|
38
38
|
end
|
39
39
|
|
@@ -121,6 +121,15 @@ module Contrast
|
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
|
+
CHARS = %w[a b c d e f g].cs__freeze
|
125
|
+
# This method converts and integer value for length into a string value
|
126
|
+
# that we can hash on, based on the logarithmic value of the length, and
|
127
|
+
# updates the current hash with that value.
|
128
|
+
# @param chr [Numeric] the length to translate
|
129
|
+
def update_on_content_length chr
|
130
|
+
update(CHARS[Math.log10(chr.to_s.length).to_i] || CHARS[-1])
|
131
|
+
end
|
132
|
+
|
124
133
|
def initialize
|
125
134
|
@crc32 = 0
|
126
135
|
end
|