contrast-agent 3.14.0 → 4.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.c +18 -15
- data/ext/cs__assess_marshal_module/cs__assess_marshal_module.h +1 -0
- data/ext/cs__assess_string/cs__assess_string.c +24 -25
- data/ext/cs__assess_string/cs__assess_string.h +3 -1
- data/ext/cs__common/cs__common.c +4 -2
- data/ext/cs__common/cs__common.h +1 -1
- data/lib/contrast.rb +1 -1
- data/lib/contrast/agent.rb +4 -12
- data/lib/contrast/agent/assess.rb +1 -0
- data/lib/contrast/agent/assess/contrast_event.rb +143 -79
- data/lib/contrast/agent/assess/events/source_event.rb +1 -1
- data/lib/contrast/agent/assess/finalizers/freeze.rb +3 -1
- data/lib/contrast/agent/assess/finalizers/hash.rb +45 -1
- data/lib/contrast/agent/assess/policy/dynamic_source_factory.rb +10 -3
- data/lib/contrast/agent/assess/policy/patcher.rb +1 -1
- data/lib/contrast/agent/assess/policy/policy.rb +0 -2
- data/lib/contrast/agent/assess/policy/policy_node.rb +15 -10
- data/lib/contrast/agent/assess/policy/policy_scanner.rb +19 -3
- data/lib/contrast/agent/assess/policy/preshift.rb +7 -11
- data/lib/contrast/agent/assess/policy/propagation_method.rb +50 -33
- 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/database_write.rb +5 -3
- 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 +4 -7
- data/lib/contrast/agent/assess/policy/propagator/next.rb +7 -5
- data/lib/contrast/agent/assess/policy/propagator/prepend.rb +8 -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 +24 -19
- data/lib/contrast/agent/assess/policy/propagator/substitution.rb +47 -31
- data/lib/contrast/agent/assess/policy/propagator/trim.rb +11 -5
- data/lib/contrast/agent/assess/policy/source_method.rb +85 -58
- data/lib/contrast/agent/assess/policy/trigger/reflected_xss.rb +16 -12
- data/lib/contrast/agent/assess/policy/trigger/xpath.rb +1 -1
- data/lib/contrast/agent/assess/policy/trigger_method.rb +76 -28
- data/lib/contrast/agent/assess/policy/trigger_node.rb +38 -43
- data/lib/contrast/agent/assess/policy/trigger_validation/ssrf_validator.rb +2 -1
- data/lib/contrast/agent/assess/properties.rb +2 -0
- data/lib/contrast/agent/assess/property/evented.rb +5 -18
- data/lib/contrast/agent/assess/property/tagged.rb +9 -3
- data/lib/contrast/agent/assess/property/updated.rb +131 -0
- data/lib/contrast/agent/assess/rule/provider/hardcoded_key.rb +58 -5
- data/lib/contrast/agent/assess/rule/provider/hardcoded_password.rb +23 -8
- data/lib/contrast/agent/assess/rule/provider/hardcoded_value_rule.rb +83 -14
- 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 +5 -5
- data/lib/contrast/agent/class_reopener.rb +7 -5
- 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/middleware.rb +1 -3
- data/lib/contrast/agent/patching/policy/after_load_patch.rb +5 -5
- data/lib/contrast/agent/patching/policy/after_load_patcher.rb +20 -20
- data/lib/contrast/agent/patching/policy/module_policy.rb +10 -10
- data/lib/contrast/agent/patching/policy/patch.rb +6 -0
- data/lib/contrast/agent/patching/policy/patcher.rb +13 -22
- data/lib/contrast/agent/patching/policy/policy.rb +17 -6
- data/lib/contrast/agent/protect/policy/applies_command_injection_rule.rb +3 -5
- data/lib/contrast/agent/protect/policy/applies_path_traversal_rule.rb +4 -3
- data/lib/contrast/agent/protect/policy/applies_xxe_rule.rb +1 -1
- data/lib/contrast/agent/protect/rule/cmd_injection.rb +9 -25
- data/lib/contrast/agent/protect/rule/no_sqli/mongo_no_sql_scanner.rb +1 -0
- data/lib/contrast/agent/request.rb +34 -34
- data/lib/contrast/agent/request_handler.rb +1 -1
- data/lib/contrast/agent/response.rb +17 -6
- data/lib/contrast/agent/rewriter.rb +1 -3
- data/lib/contrast/agent/scope.rb +59 -53
- data/lib/contrast/agent/static_analysis.rb +7 -7
- data/lib/contrast/agent/tracepoint_hook.rb +1 -1
- data/lib/contrast/agent/version.rb +1 -1
- data/lib/contrast/api/communication/messaging_queue.rb +1 -4
- data/lib/contrast/api/communication/socket_client.rb +36 -1
- data/lib/contrast/api/decorators.rb +3 -0
- data/lib/contrast/api/decorators/address.rb +13 -14
- data/lib/contrast/api/decorators/application_update.rb +2 -4
- 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 +1 -0
- data/lib/contrast/api/decorators/trace_event.rb +25 -23
- data/lib/contrast/common_agent_configuration.rb +2 -1
- data/lib/contrast/components/agent.rb +6 -5
- data/lib/contrast/components/app_context.rb +49 -38
- data/lib/contrast/components/config.rb +30 -48
- data/lib/contrast/components/contrast_service.rb +9 -9
- data/lib/contrast/components/interface.rb +25 -3
- data/lib/contrast/components/inventory.rb +6 -1
- data/lib/contrast/components/scope.rb +49 -6
- data/lib/contrast/components/settings.rb +23 -23
- data/lib/contrast/config/application_configuration.rb +5 -2
- data/lib/contrast/config/inventory_configuration.rb +2 -2
- data/lib/contrast/config/service_configuration.rb +8 -0
- data/lib/contrast/configuration.rb +88 -47
- data/lib/contrast/extension/assess.rb +0 -2
- data/lib/contrast/extension/assess/array.rb +15 -8
- data/lib/contrast/extension/assess/erb.rb +11 -3
- data/lib/contrast/extension/assess/eval_trigger.rb +6 -6
- data/lib/contrast/extension/assess/exec_trigger.rb +1 -4
- data/lib/contrast/extension/assess/fiber.rb +12 -12
- data/lib/contrast/extension/assess/hash.rb +5 -6
- data/lib/contrast/extension/assess/kernel.rb +28 -23
- data/lib/contrast/extension/assess/marshal.rb +11 -6
- data/lib/contrast/extension/assess/regexp.rb +8 -7
- data/lib/contrast/extension/assess/string.rb +21 -21
- data/lib/contrast/extension/protect/kernel.rb +3 -3
- data/lib/contrast/framework/base_support.rb +1 -1
- data/lib/contrast/framework/manager.rb +3 -3
- data/lib/contrast/framework/rack/patch/session_cookie.rb +22 -28
- data/lib/contrast/framework/rails/patch/action_controller_live_buffer.rb +13 -13
- data/lib/contrast/framework/rails/patch/assess_configuration.rb +5 -11
- data/lib/contrast/framework/rails/patch/rails_application_configuration.rb +10 -10
- data/lib/contrast/framework/rails/patch/support.rb +1 -1
- 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 +3 -3
- data/lib/contrast/framework/rails/rewrite/active_record_time_zone_inherited.rb +12 -12
- data/lib/contrast/framework/rails/support.rb +5 -0
- data/lib/contrast/framework/sinatra/patch/base.rb +11 -11
- data/lib/contrast/framework/sinatra/support.rb +4 -4
- data/lib/contrast/logger/application.rb +11 -3
- data/lib/contrast/logger/log.rb +7 -2
- data/lib/contrast/utils/assess/tracking_util.rb +48 -3
- data/lib/contrast/utils/duck_utils.rb +0 -10
- data/lib/contrast/utils/env_configuration_item.rb +2 -1
- data/lib/contrast/utils/invalid_configuration_util.rb +20 -21
- data/lib/contrast/utils/inventory_util.rb +0 -7
- data/lib/contrast/utils/sha256_builder.rb +0 -12
- data/lib/contrast/utils/string_utils.rb +10 -5
- data/resources/assess/policy.json +31 -22
- data/ruby-agent.gemspec +21 -18
- data/service_executables/VERSION +1 -1
- data/service_executables/linux/contrast-service +0 -0
- data/service_executables/mac/contrast-service +0 -0
- metadata +71 -30
- data/lib/contrast/agent/assess/finalizers/finalize.rb +0 -21
- data/lib/contrast/extension/assess/assess_extension.rb +0 -145
- 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
@@ -30,9 +30,9 @@ module Contrast
|
|
30
30
|
|
31
31
|
def instrument
|
32
32
|
@_instrument ||= begin
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
require 'cs__protect_kernel/cs__protect_kernel'
|
34
|
+
true
|
35
|
+
end
|
36
36
|
rescue StandardError, LoadError => e
|
37
37
|
logger.error('Error loading kernel protect patch', e)
|
38
38
|
false
|
@@ -46,7 +46,7 @@ module Contrast
|
|
46
46
|
#
|
47
47
|
# By default, and hopefully in all cases, we won't need these patches,
|
48
48
|
# so we're allowing nil here rather than raising an exception.
|
49
|
-
def before_load_patches
|
49
|
+
def before_load_patches!; end
|
50
50
|
|
51
51
|
# Some Frameworks require specific patching for their classes to handle
|
52
52
|
# functionality like routing. To accommodate this, this method provides
|
@@ -39,9 +39,9 @@ module Contrast
|
|
39
39
|
# configuration.
|
40
40
|
def before_load_patches!
|
41
41
|
@_before_load_patches ||= begin
|
42
|
-
|
43
|
-
|
44
|
-
|
42
|
+
SUPPORTED_FRAMEWORKS.each(&:before_load_patches!)
|
43
|
+
true
|
44
|
+
end
|
45
45
|
end
|
46
46
|
|
47
47
|
# Return all the After Load Patches for all the Frameworks we know, even
|
@@ -24,20 +24,20 @@ module Contrast
|
|
24
24
|
|
25
25
|
def instrument
|
26
26
|
@_instrument ||= begin
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
27
|
+
::Rack::Session::Cookie.class_eval do
|
28
|
+
alias_method :cs__patched_initialize, :initialize
|
29
|
+
def initialize app, options = {}
|
30
|
+
Contrast::Framework::Rack::Patch::SessionCookie.analyze(options)
|
31
|
+
cs__patched_initialize(app, options)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
true
|
35
|
+
end
|
36
36
|
end
|
37
37
|
|
38
38
|
def analyze options
|
39
39
|
return unless AGENT.enabled?
|
40
|
-
return if
|
40
|
+
return if ASSESS.forcibly_disabled?
|
41
41
|
|
42
42
|
apply_session_timeout(options)
|
43
43
|
apply_httponly(options)
|
@@ -67,12 +67,10 @@ module Contrast
|
|
67
67
|
options,
|
68
68
|
safe_default: false)
|
69
69
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
caller_locations(10, 9)[0])
|
75
|
-
end
|
70
|
+
cs__report_finding(
|
71
|
+
CS__SECURE_RULE_NAME,
|
72
|
+
options,
|
73
|
+
caller_locations(10, 9)[0])
|
76
74
|
rescue StandardError => e
|
77
75
|
begin
|
78
76
|
logger.error('Unable to track call to secure session', e)
|
@@ -88,12 +86,10 @@ module Contrast
|
|
88
86
|
safe_default: false,
|
89
87
|
comparison_type: :greater_than)
|
90
88
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
caller_locations(10, 9)[0])
|
96
|
-
end
|
89
|
+
cs__report_finding(
|
90
|
+
CS__SESSION_TIMEOUT_NAME,
|
91
|
+
options,
|
92
|
+
caller_locations(10, 9)[0])
|
97
93
|
rescue StandardError => e
|
98
94
|
begin
|
99
95
|
logger.error('Unable to track call to set session timeout', e)
|
@@ -105,12 +101,10 @@ module Contrast
|
|
105
101
|
def apply_httponly options
|
106
102
|
return unless vulnerable_setting?(:httponly, true, options)
|
107
103
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
caller_locations(10, 9)[0])
|
113
|
-
end
|
104
|
+
cs__report_finding(
|
105
|
+
CS__HTTPONLY_NAME,
|
106
|
+
options,
|
107
|
+
caller_locations(10, 9)[0])
|
114
108
|
rescue StandardError => e
|
115
109
|
begin
|
116
110
|
logger.error('Unable to track call to httponly', e)
|
@@ -19,19 +19,19 @@ module Contrast
|
|
19
19
|
|
20
20
|
def instrument
|
21
21
|
@_instrument ||= begin
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
22
|
+
::ActionController::Live::Buffer.class_eval do
|
23
|
+
# normally pre->in->post filters are applied however, in a streamed response
|
24
|
+
# we can run into a case where it's pre -> in -> post -> more infilters
|
25
|
+
# in order to submit anything found during the infilters after the response has
|
26
|
+
# been written we need to explicitly send them
|
27
|
+
alias_method :cs__close, :close
|
28
|
+
def close
|
29
|
+
Contrast::Framework::Rails::Patch::ActionControllerLiveBuffer.send_messages
|
30
|
+
cs__close
|
31
|
+
end
|
32
|
+
end
|
33
|
+
true
|
34
|
+
end
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -12,7 +12,7 @@ module Contrast
|
|
12
12
|
module AssessConfiguration
|
13
13
|
include Contrast::Components::Interface
|
14
14
|
|
15
|
-
access_component :agent, :analysis, :logging
|
15
|
+
access_component :agent, :analysis, :logging
|
16
16
|
|
17
17
|
CS__SESSION_TIMEOUT_NAME = 'session-timeout'
|
18
18
|
SAFE_SESSION_TIMEOUT = (30 * 60 * 1000)
|
@@ -23,7 +23,7 @@ module Contrast
|
|
23
23
|
include Contrast::Utils::InvalidConfigurationUtil
|
24
24
|
|
25
25
|
def analyze_session_store *args
|
26
|
-
return if
|
26
|
+
return if ASSESS.forcibly_disabled?
|
27
27
|
|
28
28
|
apply_httponly_disabled(*args)
|
29
29
|
apply_secure_cookie_disabled(*args)
|
@@ -52,9 +52,7 @@ module Contrast
|
|
52
52
|
return unless vulnerable_setting?(:expire_after, SAFE_SESSION_TIMEOUT, args, comparison_type: :greater_than, safe_default: false)
|
53
53
|
|
54
54
|
rails_session_settings = args[1]
|
55
|
-
|
56
|
-
cs__report_finding(CS__SESSION_TIMEOUT_NAME, rails_session_settings, caller_locations(6, 5)[0])
|
57
|
-
end
|
55
|
+
cs__report_finding(CS__SESSION_TIMEOUT_NAME, rails_session_settings, caller_locations(3, 2)[0])
|
58
56
|
rescue StandardError => e
|
59
57
|
begin
|
60
58
|
logger.error('Unable to track call to set session timeout', e)
|
@@ -68,9 +66,7 @@ module Contrast
|
|
68
66
|
return unless vulnerable_setting?(:secure, true, args)
|
69
67
|
|
70
68
|
rails_session_settings = args[1]
|
71
|
-
|
72
|
-
cs__report_finding(CS__SECURE_RULE_NAME, rails_session_settings, caller_locations(6, 5)[0])
|
73
|
-
end
|
69
|
+
cs__report_finding(CS__SECURE_RULE_NAME, rails_session_settings, caller_locations(3, 2)[0])
|
74
70
|
rescue StandardError => e
|
75
71
|
begin
|
76
72
|
logger.error('Unable to track call to disable secure cookies', e)
|
@@ -84,9 +80,7 @@ module Contrast
|
|
84
80
|
return unless vulnerable_setting?(:httponly, true, args)
|
85
81
|
|
86
82
|
rails_session_settings = args[1]
|
87
|
-
|
88
|
-
cs__report_finding(CS__HTTPONLY_RULE_NAME, rails_session_settings, caller_locations(6, 5)[0])
|
89
|
-
end
|
83
|
+
cs__report_finding(CS__HTTPONLY_RULE_NAME, rails_session_settings, caller_locations(3, 2)[0])
|
90
84
|
rescue StandardError => e
|
91
85
|
begin
|
92
86
|
logger.error('Unable to track call to disable httponly in session cookie', e)
|
@@ -13,16 +13,16 @@ module Contrast
|
|
13
13
|
class RailsApplicationConfiguration
|
14
14
|
def self.instrument
|
15
15
|
@_instrument ||= begin
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
16
|
+
::Rails::Application::Configuration.class_eval do
|
17
|
+
alias_method :cs__patched_session_store, :session_store
|
18
|
+
def session_store *args
|
19
|
+
ret = cs__patched_session_store(*args)
|
20
|
+
Contrast::Framework::Rails::Patch::AssessConfiguration.analyze_session_store(*args)
|
21
|
+
ret
|
22
|
+
end
|
23
|
+
end
|
24
|
+
true
|
25
|
+
end
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -11,7 +11,7 @@ module Contrast
|
|
11
11
|
# Extension point allowing for the registration of Patches required to
|
12
12
|
# support the Rails framework.
|
13
13
|
module Support
|
14
|
-
# (See BaseSupport#before_load_patches)
|
14
|
+
# (See BaseSupport#before_load_patches!)
|
15
15
|
def before_load_patches!
|
16
16
|
return unless defined?(::Rails)
|
17
17
|
|
@@ -15,17 +15,17 @@ module Contrast
|
|
15
15
|
class ActionControllerRailtiesHelperInherited
|
16
16
|
def self.instrument
|
17
17
|
@_instrument ||= begin
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
18
|
+
::ActionController::Railties::Helpers.class_eval do
|
19
|
+
alias_method :cs__patched_helper_inherited, :inherited
|
20
|
+
def inherited klass # rubocop:disable Lint/MissingSuper
|
21
|
+
klass&.instance_variable_set(:@cs__defining_class, true)
|
22
|
+
cs__patched_helper_inherited(klass) # This calls the original inherited, which should handle super as needed.
|
23
|
+
ensure
|
24
|
+
klass&.instance_variable_set(:@cs__defining_class, false)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
true
|
28
|
+
end
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -17,20 +17,20 @@ module Contrast
|
|
17
17
|
class ActiveRecordAttributeMethodsRead
|
18
18
|
def self.instrument
|
19
19
|
@_instrument ||= begin
|
20
|
-
|
21
|
-
|
20
|
+
::ActiveRecord::AttributeMethods::Read::ClassMethods.class_eval do
|
21
|
+
alias_method :cs__patched_define_method_attribute, :define_method_attribute
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
def define_method_attribute *args, &block
|
24
|
+
ret = cs__patched_define_method_attribute(*args, &block)
|
25
|
+
method_name = args[0]
|
26
|
+
Contrast::Agent::Assess::Policy::Patcher.patch_assess_method(self, method_name)
|
27
|
+
ret
|
28
|
+
end
|
29
29
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
30
|
+
protected :cs__patched_define_method_attribute, :define_method_attribute
|
31
|
+
end
|
32
|
+
true
|
33
|
+
end
|
34
34
|
end
|
35
35
|
end
|
36
36
|
end
|
@@ -58,9 +58,9 @@ module Contrast
|
|
58
58
|
|
59
59
|
def instrument
|
60
60
|
@_instrument_named_track ||= begin
|
61
|
-
|
62
|
-
|
63
|
-
|
61
|
+
require 'cs__assess_active_record_named/cs__assess_active_record_named'
|
62
|
+
true
|
63
|
+
end
|
64
64
|
rescue StandardError, LoadError => e
|
65
65
|
logger.error('Error loading active record named track patch', e)
|
66
66
|
false
|
@@ -12,19 +12,19 @@ module Contrast
|
|
12
12
|
class ActiveRecordTimeZoneInherited
|
13
13
|
def self.instrument
|
14
14
|
@_instrument ||= begin
|
15
|
-
|
16
|
-
|
15
|
+
::ActiveRecord::AttributeMethods::TimeZoneConversion::ClassMethods.class_eval do
|
16
|
+
private
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
alias_method :cs__patched_inherited, :inherited
|
19
|
+
def inherited klass # rubocop:disable Lint/MissingSuper
|
20
|
+
klass&.instance_variable_set(:@cs__defining_class, true)
|
21
|
+
cs__patched_inherited(klass) # This calls the original inherited, which should handle super as needed.
|
22
|
+
ensure
|
23
|
+
klass&.instance_variable_set(:@cs__defining_class, false)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
true
|
27
|
+
end
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
@@ -45,6 +45,9 @@ module Contrast
|
|
45
45
|
find_all_routes(::Rails.application, [])
|
46
46
|
end
|
47
47
|
|
48
|
+
# Find the current route, based on the provided Request wrapper
|
49
|
+
# @param request[Contrast::Agent::Request]
|
50
|
+
# @return [Contrast::Api::Dtm::RouteCoverage]
|
48
51
|
def current_route request
|
49
52
|
return unless ::Rails.cs__respond_to?(:application)
|
50
53
|
|
@@ -118,6 +121,8 @@ module Contrast
|
|
118
121
|
|
119
122
|
# Rails engine routes need to be detected by inspecting Engine class route set
|
120
123
|
def find_all_routes app, route_list
|
124
|
+
return route_list unless app.cs__respond_to?(:routes) && app.routes.cs__respond_to?(:routes)
|
125
|
+
|
121
126
|
app.routes.routes.each do |route|
|
122
127
|
if route.cs__respond_to?(:app) && route.app.cs__class == ActionDispatch::Routing::RouteSet::Dispatcher
|
123
128
|
route_list << Contrast::Api::Dtm::RouteCoverage.from_action_dispatch_journey(route)
|
@@ -34,17 +34,17 @@ module Contrast
|
|
34
34
|
|
35
35
|
def instrument
|
36
36
|
@_instrument ||= begin
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
37
|
+
::Sinatra::Base.class_eval do
|
38
|
+
alias_method :cs__patched_sinatra_base_call!, :call!
|
39
|
+
# publicly available method for Sinatra::Base things -- unfortunately,
|
40
|
+
# getting the routes appear to require a lookup every time
|
41
|
+
def call! *args
|
42
|
+
Contrast::Framework::Sinatra::Patch::Base.map_route(cs__class, settings, *args)
|
43
|
+
cs__patched_sinatra_base_call!(*args)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
true
|
47
|
+
end
|
48
48
|
end
|
49
49
|
|
50
50
|
private
|
@@ -70,10 +70,10 @@ module Contrast
|
|
70
70
|
return nil unless defined?(::Sinatra) && defined?(::Sinatra::Base)
|
71
71
|
|
72
72
|
@_app_class ||= begin
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
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
77
|
end
|
78
78
|
|
79
79
|
# Iterate over every class that extends Sinatra::Base, pull out its routes
|
@@ -33,9 +33,17 @@ module Contrast
|
|
33
33
|
def application_configuration
|
34
34
|
return unless info?
|
35
35
|
|
36
|
-
loggable = CONFIG.
|
37
|
-
|
38
|
-
|
36
|
+
loggable = CONFIG.loggable
|
37
|
+
info('Current configuration', configuration: loggable)
|
38
|
+
env_keys = ENV.keys.select { |env_key| env_key&.to_s&.start_with?(Contrast::Components::Config::CONTRAST_ENV_MARKER) }
|
39
|
+
env_items = env_keys.map { |env_key| Contrast::Utils::EnvConfigurationItem.new(env_key, nil) }
|
40
|
+
env_translations = env_items.each_with_object({}) do |conversion, hash|
|
41
|
+
hash[conversion.key] = conversion.dot_path_array.join('.')
|
42
|
+
end
|
43
|
+
info('Set by environment', overrides: env_translations)
|
44
|
+
rescue StandardError => e
|
45
|
+
puts e
|
46
|
+
sleep(5)
|
39
47
|
end
|
40
48
|
|
41
49
|
def application_libraries
|
data/lib/contrast/logger/log.rb
CHANGED
@@ -49,14 +49,19 @@ module Contrast
|
|
49
49
|
path = valid_path(config_path || log_file)
|
50
50
|
level_const = valid_level(config_level || log_level)
|
51
51
|
|
52
|
+
path_change = path != previous_path
|
53
|
+
level_change = level_const != previous_level
|
54
|
+
|
52
55
|
# don't needlessly recreate logger
|
53
|
-
return if @_logger && (
|
56
|
+
return if @_logger && !(path_change || level_change)
|
54
57
|
|
55
58
|
@previous_path = path
|
56
59
|
@previous_level = level_const
|
57
60
|
|
58
61
|
@_logger = build(path: path, level_const: level_const)
|
59
|
-
|
62
|
+
# If we're logging to a new path, then let's start it w/ our helpful
|
63
|
+
# data gathering messages
|
64
|
+
log_update if path_change
|
60
65
|
rescue StandardError => e
|
61
66
|
if logger
|
62
67
|
logger.error('Unable to process update to LoggerManager.', e)
|