tcell_agent 1.1.12 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/bin/tcell_agent +26 -14
- data/lib/tcell_agent.rb +16 -10
- data/lib/tcell_agent/agent.rb +78 -97
- data/lib/tcell_agent/agent/route_manager.rb +0 -16
- data/lib/tcell_agent/agent/static_agent.rb +9 -30
- data/lib/tcell_agent/authlogic.rb +3 -6
- data/lib/tcell_agent/config/unknown_options.rb +4 -8
- data/lib/tcell_agent/configuration.rb +38 -119
- data/lib/tcell_agent/devise.rb +25 -27
- data/lib/tcell_agent/hooks/login_fraud.rb +30 -33
- data/lib/tcell_agent/instrument_servers.rb +25 -0
- data/lib/tcell_agent/instrumentation.rb +12 -10
- data/lib/tcell_agent/instrumentation/cmdi.rb +19 -15
- data/lib/tcell_agent/instrumentation/lfi.rb +73 -0
- data/lib/tcell_agent/instrumentation/monkey_patches/file.rb +25 -0
- data/lib/tcell_agent/instrumentation/monkey_patches/io.rb +123 -0
- data/lib/tcell_agent/instrumentation/monkey_patches/kernel.rb +159 -0
- data/lib/tcell_agent/logger.rb +50 -114
- data/lib/tcell_agent/patches.rb +6 -7
- data/lib/tcell_agent/policies/appfirewall_policy.rb +26 -0
- data/lib/tcell_agent/policies/command_injection_policy.rb +28 -0
- data/lib/tcell_agent/policies/dataloss_policy.rb +44 -44
- data/lib/tcell_agent/policies/headers_policy.rb +25 -0
- data/lib/tcell_agent/policies/http_redirect_policy.rb +13 -79
- data/lib/tcell_agent/policies/js_agent_policy.rb +27 -0
- data/lib/tcell_agent/policies/local_file_access.rb +28 -0
- data/lib/tcell_agent/policies/login_policy.rb +43 -0
- data/lib/tcell_agent/policies/patches_policy.rb +27 -0
- data/lib/tcell_agent/policies/policies_manager.rb +68 -0
- data/lib/tcell_agent/policies/policy_polling.rb +58 -0
- data/lib/tcell_agent/policies/policy_types.rb +14 -0
- data/lib/tcell_agent/policies/system_enablements.rb +27 -0
- data/lib/tcell_agent/rails/auth/authlogic.rb +43 -68
- data/lib/tcell_agent/rails/auth/devise.rb +20 -23
- data/lib/tcell_agent/rails/auth/doorkeeper.rb +63 -74
- data/lib/tcell_agent/rails/csrf_exception.rb +2 -2
- data/lib/tcell_agent/rails/dlp.rb +25 -15
- data/lib/tcell_agent/rails/dlp_handler.rb +1 -2
- data/lib/tcell_agent/rails/js_agent_insert.rb +12 -13
- data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +4 -25
- data/lib/tcell_agent/rails/middleware/context_middleware.rb +2 -12
- data/lib/tcell_agent/rails/middleware/global_middleware.rb +0 -1
- data/lib/tcell_agent/rails/middleware/headers_middleware.rb +14 -34
- data/lib/tcell_agent/rails/on_start.rb +32 -31
- data/lib/tcell_agent/rails/routes.rb +7 -6
- data/lib/tcell_agent/rails/routes/grape.rb +1 -3
- data/lib/tcell_agent/rails/routes/route_id.rb +3 -1
- data/lib/tcell_agent/rails/settings_reporter.rb +23 -36
- data/lib/tcell_agent/rails/start_agent_after_initializers.rb +12 -0
- data/lib/tcell_agent/rails/tcell_body_proxy.rb +6 -4
- data/lib/tcell_agent/rust/agent_config.rb +49 -0
- data/lib/tcell_agent/rust/{libtcellagent-alpine-1.3.2.so → libtcellagent-4.14.0.dylib} +0 -0
- data/lib/tcell_agent/rust/libtcellagent-4.14.0.so +0 -0
- data/lib/tcell_agent/rust/{libtcellagent-1.3.2.so → libtcellagent-alpine-4.14.0.so} +0 -0
- data/lib/tcell_agent/rust/models.rb +0 -55
- data/lib/tcell_agent/rust/native_agent.rb +531 -0
- data/lib/tcell_agent/rust/native_agent_response.rb +42 -0
- data/lib/tcell_agent/rust/native_library.rb +68 -0
- data/lib/tcell_agent/rust/tcellagent-4.14.0.dll +0 -0
- data/lib/tcell_agent/sensor_events/agent_setting_event.rb +12 -0
- data/lib/tcell_agent/sensor_events/{app_config.rb → app_config_setting_event.rb} +0 -6
- data/lib/tcell_agent/sensor_events/dlp.rb +2 -6
- data/lib/tcell_agent/sensor_events/sensor.rb +0 -62
- data/lib/tcell_agent/sensor_events/server_agent.rb +13 -18
- data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +0 -108
- data/lib/tcell_agent/sensor_events/util/utils.rb +0 -2
- data/lib/tcell_agent/servers/passenger.rb +1 -28
- data/lib/tcell_agent/servers/puma.rb +3 -21
- data/lib/tcell_agent/servers/rails_server.rb +1 -1
- data/lib/tcell_agent/servers/thin.rb +2 -2
- data/lib/tcell_agent/servers/unicorn.rb +19 -80
- data/lib/tcell_agent/servers/webrick.rb +1 -1
- data/lib/tcell_agent/settings_reporter.rb +24 -24
- data/lib/tcell_agent/sinatra.rb +14 -16
- data/lib/tcell_agent/tcell_context.rb +40 -14
- data/lib/tcell_agent/utils/headers.rb +14 -0
- data/lib/tcell_agent/version.rb +1 -1
- data/spec/lib/tcell_agent/cmdi_spec.rb +0 -585
- data/spec/lib/tcell_agent/config/unknown_options_spec.rb +0 -18
- data/spec/lib/tcell_agent/configuration_spec.rb +4 -140
- data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +46 -173
- data/spec/lib/tcell_agent/instrumentation/cmdi/io_cmdi_spec.rb +504 -0
- data/spec/lib/tcell_agent/instrumentation/cmdi/kernel_cmdi_spec.rb +435 -0
- data/spec/lib/tcell_agent/instrumentation/lfi/file_lfi_spec.rb +326 -0
- data/spec/lib/tcell_agent/instrumentation/lfi/io_lfi_spec.rb +556 -0
- data/spec/lib/tcell_agent/instrumentation/lfi/kernel_lfi_spec.rb +249 -0
- data/spec/lib/tcell_agent/instrumentation/lfi_spec.rb +105 -0
- data/spec/lib/tcell_agent/patches_spec.rb +25 -43
- data/spec/lib/tcell_agent/policies/appfirewall_policy_spec.rb +183 -0
- data/spec/lib/tcell_agent/policies/clickjacking_policy_spec.rb +57 -0
- data/spec/lib/tcell_agent/policies/command_injection_policy_spec.rb +84 -773
- data/spec/lib/tcell_agent/policies/content_security_policy_spec.rb +161 -0
- data/spec/lib/tcell_agent/policies/dataloss_policy_spec.rb +9 -9
- data/spec/lib/tcell_agent/policies/http_redirect_policy_spec.rb +243 -198
- data/spec/lib/tcell_agent/policies/js_agent_policy_spec.rb +75 -0
- data/spec/lib/tcell_agent/policies/login_policy_spec.rb +165 -33
- data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +84 -277
- data/spec/lib/tcell_agent/policies/policies_manager_spec.rb +104 -0
- data/spec/lib/tcell_agent/policies/policy_polling_spec.rb +6 -0
- data/spec/lib/tcell_agent/policies/secure_headers_policy_spec.rb +56 -0
- data/spec/lib/tcell_agent/rails/csrf_exception_spec.rb +9 -18
- data/spec/lib/tcell_agent/rails/js_agent_insert_spec.rb +13 -30
- data/spec/lib/tcell_agent/rails/logger_spec.rb +27 -7
- data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +17 -12
- data/spec/lib/tcell_agent/rails/routes/routes_spec.rb +14 -14
- data/spec/lib/tcell_agent/sensor_events/util/sanitizer_utilities_spec.rb +0 -35
- data/spec/lib/tcell_agent/settings_reporter_spec.rb +127 -153
- data/spec/spec_helper.rb +1 -1
- data/spec/support/builders.rb +104 -0
- data/spec/support/force_logger_mocking.rb +38 -0
- data/spec/support/resources/lfi_sample_file.txt +2 -0
- data/spec/support/static_agent_overrides.rb +0 -15
- metadata +63 -74
- data/lib/tcell_agent/agent/event_processor.rb +0 -326
- data/lib/tcell_agent/agent/fork_pipe_manager.rb +0 -113
- data/lib/tcell_agent/agent/policy_manager.rb +0 -219
- data/lib/tcell_agent/agent/policy_types.rb +0 -30
- data/lib/tcell_agent/api.rb +0 -91
- data/lib/tcell_agent/appsensor/injections_reporter.rb +0 -24
- data/lib/tcell_agent/config/child_process_events.rb +0 -8
- data/lib/tcell_agent/instrumentation/cmdi/backtick.rb +0 -10
- data/lib/tcell_agent/instrumentation/cmdi/exec.rb +0 -14
- data/lib/tcell_agent/instrumentation/cmdi/popen.rb +0 -28
- data/lib/tcell_agent/instrumentation/cmdi/spawn.rb +0 -11
- data/lib/tcell_agent/instrumentation/cmdi/system.rb +0 -11
- data/lib/tcell_agent/policies/http_tx_policy.rb +0 -60
- data/lib/tcell_agent/policies/login_fraud_policy.rb +0 -45
- data/lib/tcell_agent/policies/rust_policies.rb +0 -110
- data/lib/tcell_agent/rails.rb +0 -40
- data/lib/tcell_agent/rust/libtcellagent-1.3.2.dylib +0 -0
- data/lib/tcell_agent/rust/tcellagent-1.3.2.dll +0 -0
- data/lib/tcell_agent/rust/whisperer.rb +0 -308
- data/lib/tcell_agent/sensor_events/appsensor_event.rb +0 -52
- data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +0 -45
- data/lib/tcell_agent/sensor_events/command_injection.rb +0 -75
- data/lib/tcell_agent/sensor_events/honeytokens.rb +0 -16
- data/lib/tcell_agent/sensor_events/login_fraud.rb +0 -60
- data/lib/tcell_agent/sensor_events/metrics.rb +0 -123
- data/lib/tcell_agent/sensor_events/patches.rb +0 -21
- data/lib/tcell_agent/start_background_thread.rb +0 -55
- data/lib/tcell_agent/system_info.rb +0 -11
- data/lib/tcell_agent/utils/io.rb +0 -38
- data/lib/tcell_agent/utils/passwords.rb +0 -28
- data/lib/tcell_agent/utils/queue_with_timeout.rb +0 -142
- data/spec/lib/tcell_agent/agent/fork_pipe_manager_spec.rb +0 -100
- data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +0 -535
- data/spec/lib/tcell_agent/agent/static_agent_spec.rb +0 -133
- data/spec/lib/tcell_agent/api/api_spec.rb +0 -39
- data/spec/lib/tcell_agent/appsensor/injections_reporter_spec.rb +0 -187
- data/spec/lib/tcell_agent/instrumentation_spec.rb +0 -225
- data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +0 -517
- data/spec/lib/tcell_agent/policies/http_tx_policy_spec.rb +0 -22
- data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +0 -293
- data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +0 -198
- data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +0 -180
- data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +0 -116
- data/spec/lib/tcell_agent/rust/models_spec.rb +0 -120
- data/spec/lib/tcell_agent/rust/whisperer_spec.rb +0 -704
- data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +0 -45
- data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +0 -272
- data/spec/lib/tcell_agent/utils/bounded_queue_spec.rb +0 -52
- data/spec/lib/tcell_agent/utils/passwords_spec.rb +0 -143
@@ -2,14 +2,12 @@ if TCellAgent.configuration.should_instrument_devise? && defined?(Devise)
|
|
2
2
|
module TCellAgent
|
3
3
|
require 'base64'
|
4
4
|
require 'tcell_agent/agent'
|
5
|
-
require 'tcell_agent/sensor_events/login_fraud'
|
6
5
|
|
7
6
|
module DeviseInstrumentation
|
8
7
|
module TCellFailureAppRespond
|
9
8
|
def respond
|
10
9
|
TCellAgent::Instrumentation.safe_block('Devise Failure App Respond') do
|
11
|
-
if TCellAgent.configuration.
|
12
|
-
TCellAgent.configuration.should_intercept_requests?
|
10
|
+
if TCellAgent.configuration.should_intercept_requests?
|
13
11
|
tcell_data = request.env[TCellAgent::Instrumentation::TCELL_ID]
|
14
12
|
if tcell_data
|
15
13
|
# in the case of http auth, user_id is set in
|
@@ -22,19 +20,16 @@ if TCellAgent.configuration.should_instrument_devise? && defined?(Devise)
|
|
22
20
|
password = tcell_data.password
|
23
21
|
password ||= _get_tcell_password
|
24
22
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
)
|
35
|
-
end
|
23
|
+
user_valid = nil
|
24
|
+
login_policy = TCellAgent.policy(TCellAgent::PolicyTypes::LOGINFRAUD)
|
25
|
+
login_policy.report_login_failure(
|
26
|
+
user_id,
|
27
|
+
password,
|
28
|
+
request.env,
|
29
|
+
user_valid,
|
30
|
+
tcell_data
|
31
|
+
)
|
36
32
|
end
|
37
|
-
|
38
33
|
end
|
39
34
|
end
|
40
35
|
|
@@ -97,7 +92,7 @@ if TCellAgent.configuration.should_instrument_devise? && defined?(Devise)
|
|
97
92
|
# gets the first entry in the current backtrace
|
98
93
|
# syntax suggested by rubocop to improve performance
|
99
94
|
if caller(1..1).first.include? 'two_factor_authenticatable'
|
100
|
-
TCellAgent.logger.debug('Not sending login success event for Devise::Strategies::TwoFactorAuthenticatable since 2fa is unsupported')
|
95
|
+
TCellAgent.logger.debug('Not sending login success event for Devise::Strategies::TwoFactorAuthenticatable since 2fa is unsupported', 'TCellAgent::DeviseInstrumentation')
|
101
96
|
send_event = false
|
102
97
|
end
|
103
98
|
|
@@ -113,13 +108,15 @@ if TCellAgent.configuration.should_instrument_devise? && defined?(Devise)
|
|
113
108
|
end
|
114
109
|
end
|
115
110
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
111
|
+
tcell_data = request.env[TCellAgent::Instrumentation::TCELL_ID]
|
112
|
+
return is_valid unless tcell_data
|
113
|
+
|
114
|
+
login_policy = TCellAgent.policy(TCellAgent::PolicyTypes::LOGINFRAUD)
|
115
|
+
login_policy.report_login_success(
|
116
|
+
username,
|
117
|
+
request.env,
|
118
|
+
tcell_data
|
119
|
+
)
|
123
120
|
end
|
124
121
|
end
|
125
122
|
|
@@ -1,90 +1,79 @@
|
|
1
|
-
if TCellAgent.configuration.should_instrument_doorkeeper?
|
1
|
+
if TCellAgent.configuration.should_instrument_doorkeeper? && defined?(Doorkeeper)
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
require 'tcell_agent/sensor_events/login_fraud'
|
3
|
+
require 'tcell_agent/agent'
|
4
|
+
require 'tcell_agent/sensor_events/login_fraud'
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
6
|
+
module TCellAgent
|
7
|
+
module DoorkeeperInstrumentation
|
8
|
+
Doorkeeper::TokensController.class_eval do
|
9
|
+
alias_method :tcell_authorize_response, :authorize_response
|
10
|
+
def authorize_response
|
11
|
+
result = tcell_authorize_response
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
TCellAgent.configuration.should_intercept_requests?
|
17
|
-
login_fraud_policy = TCellAgent.policy(TCellAgent::PolicyTypes::LOGINFRAUD)
|
18
|
-
if login_fraud_policy &&
|
19
|
-
login_fraud_policy.enabled &&
|
20
|
-
login_fraud_policy.login_failed_enabled
|
21
|
-
tcell_data = request.env[TCellAgent::Instrumentation::TCELL_ID]
|
13
|
+
TCellAgent::Instrumentation.safe_block('Doorkeeper Token Authorize') do
|
14
|
+
return result unless TCellAgent.configuration.should_intercept_requests?
|
22
15
|
|
23
|
-
|
24
|
-
|
25
|
-
if result.is_a?(Doorkeeper::OAuth::TokenResponse)
|
26
|
-
TCellAgent.send_event(
|
27
|
-
TCellAgent::SensorEvents::LoginSuccess.new(
|
28
|
-
request.env,
|
29
|
-
tcell_data,
|
30
|
-
result.token.resource_owner_id,
|
31
|
-
password
|
32
|
-
)
|
33
|
-
)
|
34
|
-
elsif result.is_a?(Doorkeeper::OAuth::ErrorResponse)
|
35
|
-
TCellAgent.send_event(
|
36
|
-
TCellAgent::SensorEvents::LoginFailure.new(
|
37
|
-
request.env,
|
38
|
-
tcell_data,
|
39
|
-
request.POST['client_id'],
|
40
|
-
password
|
41
|
-
)
|
42
|
-
)
|
43
|
-
end
|
16
|
+
login_policy = TCellAgent.policy(TCellAgent::PolicyTypes::LOGINFRAUD)
|
17
|
+
tcell_data = request.env[TCellAgent::Instrumentation::TCELL_ID]
|
44
18
|
|
45
|
-
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|
19
|
+
return unless tcell_data
|
20
|
+
headers = request.env
|
49
21
|
|
50
|
-
result
|
22
|
+
if result.is_a?(Doorkeeper::OAuth::TokenResponse)
|
23
|
+
user_id = result.token.resource_owner_id
|
24
|
+
login_policy.report_login_success(
|
25
|
+
user_id,
|
26
|
+
headers,
|
27
|
+
tcell_data
|
28
|
+
)
|
29
|
+
elsif result.is_a?(Doorkeeper::OAuth::ErrorResponse)
|
30
|
+
user_id = request.POST['client_id']
|
31
|
+
password = nil
|
32
|
+
user_valid = nil
|
33
|
+
login_policy.report_login_failure(
|
34
|
+
user_id,
|
35
|
+
password,
|
36
|
+
headers,
|
37
|
+
user_valid,
|
38
|
+
tcell_data
|
39
|
+
)
|
40
|
+
end
|
51
41
|
end
|
42
|
+
|
43
|
+
result
|
52
44
|
end
|
45
|
+
end
|
53
46
|
|
54
|
-
|
55
|
-
|
56
|
-
|
47
|
+
module TCellAuthorizationsNew
|
48
|
+
def new
|
49
|
+
super if defined?(super)
|
57
50
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
51
|
+
TCellAgent::Instrumentation.safe_block('Doorkeeper Token Authorize') do
|
52
|
+
return unless TCellAgent.configuration.should_intercept_requests?
|
53
|
+
return unless pre_auth.error
|
54
|
+
|
55
|
+
login_policy = TCellAgent.policy(TCellAgent::PolicyTypes::LOGINFRAUD)
|
56
|
+
tcell_data = request.env[TCellAgent::Instrumentation::TCELL_ID]
|
57
|
+
|
58
|
+
return unless tcell_data
|
59
|
+
|
60
|
+
user_id = current_resource_owner.id
|
61
|
+
password = nil
|
62
|
+
headers = request.env
|
63
|
+
user_valid = nil
|
64
|
+
login_policy.report_login_failure(
|
65
|
+
user_id,
|
66
|
+
password,
|
67
|
+
headers,
|
68
|
+
user_valid,
|
69
|
+
tcell_data
|
70
|
+
)
|
82
71
|
end
|
83
72
|
end
|
84
|
-
|
85
|
-
# prepend is ruby 2+ feature
|
86
|
-
Doorkeeper::AuthorizationsController.send(:prepend, TCellAuthorizationsNew)
|
87
73
|
end
|
74
|
+
|
75
|
+
# prepend is ruby 2+ feature
|
76
|
+
Doorkeeper::AuthorizationsController.send(:prepend, TCellAuthorizationsNew)
|
88
77
|
end
|
89
78
|
end
|
90
79
|
end
|
@@ -4,8 +4,8 @@ module TCellAgent
|
|
4
4
|
module CsrfExceptionReporter
|
5
5
|
def handle_unverified_request
|
6
6
|
TCellAgent::Instrumentation.safe_block('AppSensor CSRF Exception processing') do
|
7
|
-
|
8
|
-
if
|
7
|
+
appfirewall_policy = TCellAgent.policy(TCellAgent::PolicyTypes::APPSENSOR)
|
8
|
+
if appfirewall_policy.enabled
|
9
9
|
tcell_data = request.env[TCellAgent::Instrumentation::TCELL_ID]
|
10
10
|
if tcell_data
|
11
11
|
tcell_data.csrf_exception_name = 'ActionController::InvalidAuthenticityToken'
|
@@ -5,7 +5,6 @@ require 'tcell_agent/devise' if defined?(Devise)
|
|
5
5
|
|
6
6
|
require 'rails'
|
7
7
|
require 'uri'
|
8
|
-
require 'tcell_agent/logger'
|
9
8
|
require 'tcell_agent/agent'
|
10
9
|
require 'tcell_agent/sensor_events/sensor'
|
11
10
|
require 'tcell_agent/sensor_events/server_agent'
|
@@ -31,11 +30,20 @@ require 'tcell_agent/rails/responses'
|
|
31
30
|
|
32
31
|
module TCellAgent
|
33
32
|
module DLP
|
33
|
+
def self.get_dlp_logger
|
34
|
+
unless defined?(@rails_dlp_logger)
|
35
|
+
@rails_dlp_logger = TCellAgent::ModuleLogger.new(
|
36
|
+
TCellAgent.logger, name
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
@rails_dlp_logger
|
41
|
+
end
|
42
|
+
|
34
43
|
def self.instrument_pluck(results, column_names, model)
|
35
44
|
return if results.empty?
|
36
45
|
|
37
|
-
if TCellAgent.configuration.
|
38
|
-
TCellAgent.configuration.should_instrument? &&
|
46
|
+
if TCellAgent.configuration.should_instrument? &&
|
39
47
|
TCellAgent.configuration.should_intercept_requests?
|
40
48
|
|
41
49
|
dlp_policy = TCellAgent.policy(TCellAgent::PolicyTypes::DATALOSS)
|
@@ -88,7 +96,7 @@ module TCellAgent
|
|
88
96
|
end
|
89
97
|
|
90
98
|
if results.size > TCellAgent.configuration.max_data_ex_db_records_per_request
|
91
|
-
|
99
|
+
get_dlp_logger.warn("Route (#{tcell_context.route_id}) retrieved too many records")
|
92
100
|
end
|
93
101
|
|
94
102
|
return if column_name_to_rules.empty?
|
@@ -138,8 +146,7 @@ module TCellAgent
|
|
138
146
|
def self.instrument_find_by_sql(results)
|
139
147
|
return if results.empty?
|
140
148
|
|
141
|
-
if TCellAgent.configuration.
|
142
|
-
TCellAgent.configuration.should_instrument? &&
|
149
|
+
if TCellAgent.configuration.should_instrument? &&
|
143
150
|
TCellAgent.configuration.should_intercept_requests?
|
144
151
|
|
145
152
|
dlp_policy = TCellAgent.policy(TCellAgent::PolicyTypes::DATALOSS)
|
@@ -167,7 +174,7 @@ module TCellAgent
|
|
167
174
|
end
|
168
175
|
|
169
176
|
if results.size > TCellAgent.configuration.max_data_ex_db_records_per_request
|
170
|
-
|
177
|
+
get_dlp_logger.warn("Route (#{tcell_context.route_id}) retrieved too many records")
|
171
178
|
end
|
172
179
|
|
173
180
|
column_name_to_rules = column_names.each_with_object({}) do |column_name, memo|
|
@@ -214,8 +221,8 @@ module TCellAgent
|
|
214
221
|
result = tcell_translate_exception(exception, message)
|
215
222
|
|
216
223
|
TCellAgent::Instrumentation.safe_block('Set sql_exception_detected in meta') do
|
217
|
-
|
218
|
-
if
|
224
|
+
appfirewall_policy = TCellAgent.policy(TCellAgent::PolicyTypes::APPSENSOR)
|
225
|
+
if appfirewall_policy.enabled
|
219
226
|
request_env = TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS.fetch(
|
220
227
|
Thread.current.object_id, {}
|
221
228
|
)
|
@@ -290,8 +297,7 @@ module TCellAgent
|
|
290
297
|
module Policies
|
291
298
|
class DataLossPolicy
|
292
299
|
def log_enforce(tcell_context, sanitize_string)
|
293
|
-
if TCellAgent.configuration.
|
294
|
-
TCellAgent.configuration.should_instrument? &&
|
300
|
+
if TCellAgent.configuration.should_instrument? &&
|
295
301
|
TCellAgent.configuration.should_intercept_requests?
|
296
302
|
if tcell_context && tcell_context.session_id
|
297
303
|
session_id_actions = get_actions_for_session_id
|
@@ -326,8 +332,7 @@ module TCellAgent
|
|
326
332
|
end
|
327
333
|
|
328
334
|
def response_body_enforce(tcell_context, sanitize_string)
|
329
|
-
if TCellAgent.configuration.
|
330
|
-
TCellAgent.configuration.should_instrument? &&
|
335
|
+
if TCellAgent.configuration.should_instrument? &&
|
331
336
|
TCellAgent.configuration.should_intercept_requests?
|
332
337
|
if tcell_context && tcell_context.session_id
|
333
338
|
session_id_actions = get_actions_for_session_id
|
@@ -367,6 +372,8 @@ end
|
|
367
372
|
class Logger
|
368
373
|
alias_method :tcell_old_add, :add
|
369
374
|
def add(severity, message = nil, progname = nil)
|
375
|
+
return tcell_old_add(severity, message, progname) unless severity >= level
|
376
|
+
|
370
377
|
if severity >= level
|
371
378
|
progname ||= @progname
|
372
379
|
if message.nil?
|
@@ -383,9 +390,12 @@ class Logger
|
|
383
390
|
TCellAgent.configuration.should_intercept_requests?
|
384
391
|
|
385
392
|
TCellAgent::Instrumentation.safe_block_no_log('Handling DLP log message filtering') do
|
386
|
-
|
393
|
+
dataloss_policy = TCellAgent.policy(TCellAgent::PolicyTypes::DATALOSS)
|
394
|
+
return tcell_old_add(severity, message, progname) unless dataloss_policy && dataloss_policy.enabled
|
395
|
+
|
387
396
|
request_env = TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS.fetch(Thread.current.object_id, nil)
|
388
|
-
|
397
|
+
|
398
|
+
if message && request_env
|
389
399
|
tcell_context = request_env[TCellAgent::Instrumentation::TCELL_ID]
|
390
400
|
tcell_context.filter_log(message) if tcell_context
|
391
401
|
end
|
@@ -38,8 +38,7 @@ module TCellAgent
|
|
38
38
|
tcell_context = nil
|
39
39
|
|
40
40
|
TCellAgent::Instrumentation.safe_block('DLP Handler get handler and context') do
|
41
|
-
if TCellAgent.configuration.
|
42
|
-
TCellAgent.configuration.should_instrument? &&
|
41
|
+
if TCellAgent.configuration.should_instrument? &&
|
43
42
|
TCellAgent.configuration.should_intercept_requests?
|
44
43
|
|
45
44
|
# do all this work so that dlp doesn't run at all unless it's on and there
|
@@ -44,19 +44,18 @@ module TCellAgent
|
|
44
44
|
script_insert = nil
|
45
45
|
|
46
46
|
TCellAgent::Instrumentation.safe_block('JSAgent get handler and script insert') do
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
47
|
+
return [nil, nil] unless (response_headers['Content-Type'] || '').start_with?('text/html')
|
48
|
+
|
49
|
+
js_agent_policy = TCellAgent.policy(TCellAgent::PolicyTypes::JSAGENTINJECTION)
|
50
|
+
script_insert = js_agent_policy.get_js_agent_script_tag(
|
51
|
+
request.env[TCellAgent::Instrumentation::TCELL_ID]
|
52
|
+
)
|
53
|
+
|
54
|
+
return [nil, nil] unless script_insert
|
55
|
+
|
56
|
+
js_agent_handler = proc { |si, resp|
|
57
|
+
handle_js_agent_insert(si, resp)
|
58
|
+
}
|
60
59
|
end
|
61
60
|
|
62
61
|
[js_agent_handler, script_insert]
|
@@ -2,7 +2,6 @@
|
|
2
2
|
|
3
3
|
require 'rails'
|
4
4
|
require 'uri'
|
5
|
-
require 'tcell_agent/logger'
|
6
5
|
require 'tcell_agent/agent'
|
7
6
|
require 'tcell_agent/sensor_events/sensor'
|
8
7
|
require 'tcell_agent/sensor_events/server_agent'
|
@@ -22,34 +21,14 @@ module TCellAgent
|
|
22
21
|
end
|
23
22
|
|
24
23
|
def call(env)
|
25
|
-
|
24
|
+
start_time = (Time.now.to_f * 1000).to_i
|
26
25
|
|
27
26
|
response = @app.call(env)
|
28
27
|
|
29
28
|
if TCellAgent.configuration.should_intercept_requests?
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
if route_id
|
34
|
-
TCellAgent.increment_route(route_id, response_time)
|
35
|
-
else
|
36
|
-
TCellAgent.increment_route('', response_time)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
TCellAgent::Instrumentation.safe_block('Handling Sessions Info') do
|
40
|
-
login_fraud_policy = TCellAgent.policy(TCellAgent::PolicyTypes::LOGINFRAUD)
|
41
|
-
if login_fraud_policy && login_fraud_policy.session_hijacking_metrics
|
42
|
-
hmac_session_id = env[TCellAgent::Instrumentation::TCELL_ID].hmac_session_id
|
43
|
-
user_id = env[TCellAgent::Instrumentation::TCELL_ID].user_id
|
44
|
-
if user_id && hmac_session_id
|
45
|
-
TCellAgent.increment_session_info(
|
46
|
-
hmac_session_id,
|
47
|
-
user_id,
|
48
|
-
env[TCellAgent::Instrumentation::TCELL_ID].ip_address,
|
49
|
-
env[TCellAgent::Instrumentation::TCELL_ID].user_agent
|
50
|
-
)
|
51
|
-
end
|
52
|
-
end
|
29
|
+
TCellAgent::Instrumentation.safe_block('Handling reporting metrics') do
|
30
|
+
response_time = (Time.now.to_f * 1000).to_i - start_time
|
31
|
+
TCellAgent.report_metrics(response_time, env[TCellAgent::Instrumentation::TCELL_ID])
|
53
32
|
end
|
54
33
|
end
|
55
34
|
|
@@ -2,18 +2,8 @@
|
|
2
2
|
|
3
3
|
require 'rails'
|
4
4
|
require 'uri'
|
5
|
-
require 'tcell_agent/logger'
|
6
5
|
require 'tcell_agent/agent'
|
7
|
-
require 'tcell_agent/
|
8
|
-
require 'tcell_agent/sensor_events/server_agent'
|
9
|
-
require 'tcell_agent/sensor_events/util/sanitizer_utilities'
|
10
|
-
|
11
|
-
require 'tcell_agent/userinfo'
|
12
|
-
require 'cgi'
|
13
|
-
|
14
|
-
require 'tcell_agent/instrumentation'
|
15
|
-
require 'tcell_agent/configuration'
|
16
|
-
require 'thread'
|
6
|
+
require 'tcell_agent/rails/better_ip'
|
17
7
|
|
18
8
|
module TCellAgent
|
19
9
|
module Instrumentation
|
@@ -36,7 +26,7 @@ module TCellAgent
|
|
36
26
|
env[TCellAgent::Instrumentation::TCELL_ID].path = request.path
|
37
27
|
env[TCellAgent::Instrumentation::TCELL_ID].user_agent = request.user_agent
|
38
28
|
env[TCellAgent::Instrumentation::TCELL_ID].referrer = request.referrer
|
39
|
-
env[TCellAgent::Instrumentation::TCELL_ID].
|
29
|
+
env[TCellAgent::Instrumentation::TCELL_ID].remote_address = TCellAgent::Utils::Rails.better_ip(request)
|
40
30
|
if request.request_method
|
41
31
|
env[TCellAgent::Instrumentation::TCELL_ID].request_method = request.request_method
|
42
32
|
end
|