tcell_agent 1.1.3 → 1.1.4
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 +4 -4
- data/bin/tcell_agent +10 -2
- data/lib/tcell_agent.rb +3 -3
- data/lib/tcell_agent/agent.rb +42 -52
- data/lib/tcell_agent/agent/event_processor.rb +129 -162
- data/lib/tcell_agent/agent/fork_pipe_manager.rb +57 -62
- data/lib/tcell_agent/agent/policy_manager.rb +83 -104
- data/lib/tcell_agent/agent/policy_types.rb +24 -29
- data/lib/tcell_agent/agent/route_manager.rb +36 -46
- data/lib/tcell_agent/agent/static_agent.rb +19 -21
- data/lib/tcell_agent/api.rb +23 -28
- data/lib/tcell_agent/appsensor/injections_reporter.rb +7 -11
- data/lib/tcell_agent/authlogic.rb +7 -7
- data/lib/tcell_agent/cmdi.rb +22 -23
- data/lib/tcell_agent/config/unknown_options.rb +71 -69
- data/lib/tcell_agent/configuration.rb +187 -191
- data/lib/tcell_agent/devise.rb +13 -15
- data/lib/tcell_agent/hooks/login_fraud.rb +1 -1
- data/lib/tcell_agent/instrumentation.rb +120 -124
- data/lib/tcell_agent/logger.rb +29 -45
- data/lib/tcell_agent/patches.rb +5 -5
- data/lib/tcell_agent/policies/dataloss_policy.rb +263 -288
- data/lib/tcell_agent/policies/http_redirect_policy.rb +25 -37
- data/lib/tcell_agent/policies/http_tx_policy.rb +48 -52
- data/lib/tcell_agent/policies/login_fraud_policy.rb +15 -20
- data/lib/tcell_agent/policies/policy.rb +0 -2
- data/lib/tcell_agent/policies/rust_policies.rb +24 -29
- data/lib/tcell_agent/rails.rb +2 -3
- data/lib/tcell_agent/rails/auth/authlogic.rb +2 -2
- data/lib/tcell_agent/rails/auth/devise.rb +2 -2
- data/lib/tcell_agent/rails/auth/doorkeeper.rb +2 -2
- data/lib/tcell_agent/rails/better_ip.rb +12 -16
- data/lib/tcell_agent/rails/csrf_exception.rb +4 -7
- data/lib/tcell_agent/rails/dlp.rb +208 -107
- data/lib/tcell_agent/rails/dlp/process_request.rb +37 -47
- data/lib/tcell_agent/rails/dlp_handler.rb +9 -11
- data/lib/tcell_agent/rails/js_agent_insert.rb +11 -14
- data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +8 -7
- data/lib/tcell_agent/rails/middleware/context_middleware.rb +4 -5
- data/lib/tcell_agent/rails/middleware/global_middleware.rb +5 -8
- data/lib/tcell_agent/rails/middleware/headers_middleware.rb +24 -27
- data/lib/tcell_agent/rails/on_start.rb +5 -5
- data/lib/tcell_agent/rails/responses.rb +7 -9
- data/lib/tcell_agent/rails/routes.rb +62 -81
- data/lib/tcell_agent/rails/routes/grape.rb +25 -30
- data/lib/tcell_agent/rails/routes/route_id.rb +9 -14
- data/lib/tcell_agent/rails/settings_reporter.rb +44 -33
- data/lib/tcell_agent/rails/tcell_body_proxy.rb +15 -18
- data/lib/tcell_agent/routes/table.rb +31 -33
- data/lib/tcell_agent/rust/{libtcellagent-1.3.0.dylib → libtcellagent-1.3.1.dylib} +0 -0
- data/lib/tcell_agent/rust/{libtcellagent-1.3.0.so → libtcellagent-1.3.1.so} +0 -0
- data/lib/tcell_agent/rust/{libtcellagent-alpine-1.3.0.so → libtcellagent-alpine-1.3.1.so} +0 -0
- data/lib/tcell_agent/rust/models.rb +32 -37
- data/lib/tcell_agent/rust/tcellagent-1.3.1.dll +0 -0
- data/lib/tcell_agent/rust/whisperer.rb +101 -104
- data/lib/tcell_agent/sensor_events/app_config.rb +7 -7
- data/lib/tcell_agent/sensor_events/appsensor_event.rb +26 -27
- data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +20 -88
- data/lib/tcell_agent/sensor_events/command_injection.rb +52 -80
- data/lib/tcell_agent/sensor_events/discovery.rb +27 -27
- data/lib/tcell_agent/sensor_events/dlp.rb +50 -56
- data/lib/tcell_agent/sensor_events/honeytokens.rb +9 -9
- data/lib/tcell_agent/sensor_events/metrics.rb +20 -21
- data/lib/tcell_agent/sensor_events/patches.rb +10 -12
- data/lib/tcell_agent/sensor_events/sensor.rb +32 -36
- data/lib/tcell_agent/sensor_events/server_agent.rb +130 -127
- data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +60 -80
- data/lib/tcell_agent/sensor_events/util/utils.rb +3 -5
- data/lib/tcell_agent/servers/passenger.rb +5 -9
- data/lib/tcell_agent/servers/puma.rb +18 -27
- data/lib/tcell_agent/servers/rails_server.rb +5 -9
- data/lib/tcell_agent/servers/thin.rb +2 -4
- data/lib/tcell_agent/servers/unicorn.rb +18 -27
- data/lib/tcell_agent/servers/webrick.rb +2 -4
- data/lib/tcell_agent/settings_reporter.rb +126 -0
- data/lib/tcell_agent/sinatra.rb +24 -26
- data/lib/tcell_agent/start_background_thread.rb +21 -142
- data/lib/tcell_agent/system_info.rb +4 -3
- data/lib/tcell_agent/tcell_context.rb +150 -0
- data/lib/tcell_agent/userinfo.rb +3 -3
- data/lib/tcell_agent/utils/io.rb +19 -24
- data/lib/tcell_agent/utils/params.rb +9 -15
- data/lib/tcell_agent/utils/queue_with_timeout.rb +26 -32
- data/lib/tcell_agent/utils/strings.rb +4 -6
- data/lib/tcell_agent/version.rb +1 -1
- data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +5 -5
- data/spec/lib/tcell_agent/agent/static_agent_spec.rb +7 -7
- data/spec/lib/tcell_agent/cmdi_spec.rb +21 -21
- data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +29 -24
- data/spec/lib/tcell_agent/instrumentation_spec.rb +4 -4
- data/spec/lib/tcell_agent/patches_spec.rb +8 -8
- data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +23 -23
- data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +2 -2
- data/spec/lib/tcell_agent/rails/csrf_exception_spec.rb +69 -0
- data/spec/lib/tcell_agent/rails/dlp_spec.rb +1039 -0
- data/spec/lib/tcell_agent/rails/js_agent_insert_spec.rb +271 -0
- data/spec/lib/tcell_agent/rails/logger_spec.rb +5 -5
- data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +3 -3
- data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +4 -4
- data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +5 -5
- data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +1 -1
- data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +11 -8
- data/spec/lib/tcell_agent/rails/responses_spec.rb +2 -2
- data/spec/lib/tcell_agent/rails/routes/grape_spec.rb +2 -2
- data/spec/lib/tcell_agent/rails/routes/route_id_spec.rb +1 -1
- data/spec/lib/tcell_agent/rails/routes/routes_spec.rb +4 -4
- data/spec/lib/tcell_agent/rust/models_spec.rb +83 -75
- data/spec/lib/tcell_agent/rust/whisperer_spec.rb +14 -14
- data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +19 -70
- data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +1 -1
- data/spec/lib/tcell_agent/settings_reporter_spec.rb +162 -0
- data/spec/lib/tcell_agent/tcell_context_spec.rb +154 -0
- data/spec/spec_helper.rb +5 -0
- metadata +18 -10
- data/lib/tcell_agent/appsensor/meta_data.rb +0 -132
- data/lib/tcell_agent/patches/meta_data.rb +0 -59
- data/lib/tcell_agent/rust/tcellagent-1.3.0.dll +0 -0
- data/spec/lib/tcell_agent/appsensor/meta_data_spec.rb +0 -71
@@ -14,7 +14,7 @@ if TCellAgent.configuration.should_instrument_doorkeeper?
|
|
14
14
|
TCellAgent::Instrumentation.safe_block('Doorkeeper Token Authorize') do
|
15
15
|
if TCellAgent.configuration.enabled &&
|
16
16
|
TCellAgent.configuration.should_intercept_requests?
|
17
|
-
login_fraud_policy = TCellAgent.policy(TCellAgent::PolicyTypes::
|
17
|
+
login_fraud_policy = TCellAgent.policy(TCellAgent::PolicyTypes::LOGINFRAUD)
|
18
18
|
if login_fraud_policy &&
|
19
19
|
login_fraud_policy.enabled &&
|
20
20
|
login_fraud_policy.login_failed_enabled
|
@@ -59,7 +59,7 @@ if TCellAgent.configuration.should_instrument_doorkeeper?
|
|
59
59
|
if TCellAgent.configuration.enabled &&
|
60
60
|
TCellAgent.configuration.should_intercept_requests?
|
61
61
|
if pre_auth.error
|
62
|
-
login_fraud_policy = TCellAgent.policy(TCellAgent::PolicyTypes::
|
62
|
+
login_fraud_policy = TCellAgent.policy(TCellAgent::PolicyTypes::LOGINFRAUD)
|
63
63
|
if login_fraud_policy &&
|
64
64
|
login_fraud_policy.enabled &&
|
65
65
|
login_fraud_policy.login_failed_enabled
|
@@ -1,28 +1,25 @@
|
|
1
|
-
require
|
1
|
+
require 'tcell_agent/utils/strings'
|
2
2
|
require 'tcell_agent/instrumentation'
|
3
3
|
|
4
|
-
|
5
4
|
module TCellAgent
|
6
5
|
module Utils
|
7
6
|
module Rails
|
8
|
-
|
9
7
|
def self.better_ip(request)
|
10
8
|
if TCellAgent.configuration.reverse_proxy
|
11
|
-
TCellAgent::Instrumentation.safe_block(
|
9
|
+
TCellAgent::Instrumentation.safe_block('Extracting reverse proxy IP') do
|
12
10
|
reverse_proxy_header = TCellAgent.configuration.reverse_proxy_ip_address_header
|
13
|
-
if TCellAgent::Utils::Strings.present?(reverse_proxy_header)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
reverse_proxy_header = if TCellAgent::Utils::Strings.present?(reverse_proxy_header)
|
12
|
+
'HTTP_' + reverse_proxy_header.upcase.tr('-', '_')
|
13
|
+
else
|
14
|
+
'HTTP_X_FORWARDED_FOR'
|
15
|
+
end
|
18
16
|
|
19
17
|
x_forwarded_for = request.env[reverse_proxy_header]
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
end
|
18
|
+
ip = if TCellAgent::Utils::Strings.present?(x_forwarded_for)
|
19
|
+
x_forwarded_for.split(',')[0].strip
|
20
|
+
else
|
21
|
+
request.ip
|
22
|
+
end
|
26
23
|
|
27
24
|
return ip
|
28
25
|
end
|
@@ -30,7 +27,6 @@ module TCellAgent
|
|
30
27
|
|
31
28
|
request.ip
|
32
29
|
end
|
33
|
-
|
34
30
|
end
|
35
31
|
end
|
36
32
|
end
|
@@ -1,15 +1,14 @@
|
|
1
1
|
require 'tcell_agent/instrumentation'
|
2
2
|
|
3
3
|
module TCellAgent
|
4
|
-
|
5
4
|
module CsrfExceptionReporter
|
6
5
|
def handle_unverified_request
|
7
|
-
TCellAgent::Instrumentation.safe_block(
|
8
|
-
rust_policies = TCellAgent.policy(TCellAgent::PolicyTypes::
|
6
|
+
TCellAgent::Instrumentation.safe_block('AppSensor CSRF Exception processing') do
|
7
|
+
rust_policies = TCellAgent.policy(TCellAgent::PolicyTypes::RUST)
|
9
8
|
if rust_policies && rust_policies.appfirewall_enabled
|
10
9
|
tcell_data = request.env[TCellAgent::Instrumentation::TCELL_ID]
|
11
10
|
if tcell_data
|
12
|
-
tcell_data.csrf_exception_name = ActionController::InvalidAuthenticityToken
|
11
|
+
tcell_data.csrf_exception_name = 'ActionController::InvalidAuthenticityToken'
|
13
12
|
end
|
14
13
|
end
|
15
14
|
end
|
@@ -19,12 +18,10 @@ module TCellAgent
|
|
19
18
|
end
|
20
19
|
|
21
20
|
class MyRailtie < Rails::Railtie
|
22
|
-
|
23
|
-
initializer "tcell.sensors" do |app|
|
21
|
+
initializer 'tcell.sensors' do |_app|
|
24
22
|
ActiveSupport.on_load :action_controller do
|
25
23
|
ActionController::Base.send(:include, TCellAgent::CsrfExceptionReporter)
|
26
24
|
end
|
27
25
|
end
|
28
|
-
|
29
26
|
end
|
30
27
|
end
|
@@ -29,75 +29,173 @@ require 'thread'
|
|
29
29
|
require 'tcell_agent/configuration'
|
30
30
|
require 'tcell_agent/rails/responses'
|
31
31
|
|
32
|
-
|
33
32
|
module TCellAgent
|
34
33
|
module DLP
|
35
|
-
def self.
|
36
|
-
if results.
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
34
|
+
def self.instrument_pluck(results, column_names, model)
|
35
|
+
return if results.empty?
|
36
|
+
|
37
|
+
if TCellAgent.configuration.enabled &&
|
38
|
+
TCellAgent.configuration.should_instrument? &&
|
39
|
+
TCellAgent.configuration.should_intercept_requests?
|
40
|
+
|
41
|
+
dlp_policy = TCellAgent.policy(TCellAgent::PolicyTypes::DATALOSS)
|
42
|
+
request_env = TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS.fetch(Thread.current.object_id, {})
|
43
|
+
tcell_context = request_env[TCellAgent::Instrumentation::TCELL_ID]
|
44
|
+
|
45
|
+
if tcell_context
|
46
|
+
tcell_context.database_result_sizes.push(results.size)
|
47
|
+
|
48
|
+
if dlp_policy && dlp_policy.enabled
|
49
|
+
database_name = model.connection_config.fetch(
|
50
|
+
:database, '*'
|
51
|
+
).split('/').last
|
52
|
+
table_name = model.table_name
|
53
|
+
column_names = if column_names.size.zero?
|
54
|
+
model.columns.map(&:name)
|
55
|
+
else
|
56
|
+
column_names.map(&:to_s)
|
57
|
+
end
|
58
|
+
|
59
|
+
if dlp_policy.database_discovery_enabled
|
60
|
+
TCellAgent.discover_database_fields(
|
61
|
+
tcell_context.route_id,
|
62
|
+
database_name,
|
63
|
+
'*',
|
64
|
+
table_name,
|
65
|
+
column_names
|
66
|
+
)
|
67
|
+
end
|
43
68
|
|
44
|
-
|
45
|
-
|
69
|
+
normalized_column_names = {}
|
70
|
+
column_name_to_rules = column_names.each_with_object({}) do |namespaced_column_name, memo|
|
71
|
+
namespace = nil
|
72
|
+
column_name = namespaced_column_name
|
73
|
+
if column_name =~ /\./
|
74
|
+
namespace, column_name = column_name.split(/\./)
|
75
|
+
end
|
76
|
+
normalized_column_names[namespaced_column_name] = column_name
|
77
|
+
|
78
|
+
next unless column_name && (!namespace || namespace == table_name)
|
79
|
+
rules = dlp_policy.get_actions_for_table(
|
80
|
+
database_name,
|
81
|
+
'*',
|
82
|
+
table_name,
|
83
|
+
column_name,
|
84
|
+
tcell_context.route_id
|
85
|
+
)
|
46
86
|
|
47
|
-
|
48
|
-
|
87
|
+
memo[namespaced_column_name] = rules if rules
|
88
|
+
end
|
49
89
|
|
50
|
-
if
|
51
|
-
|
52
|
-
|
53
|
-
model = first_record.class
|
54
|
-
column_names = model.columns.map { |col| col.name }
|
55
|
-
table_name = model.table_name
|
90
|
+
if results.size > TCellAgent.configuration.max_data_ex_db_records_per_request
|
91
|
+
TCellAgent.logger.warn("Route (#{tcell_context.route_id}) retrieved too many records")
|
92
|
+
end
|
56
93
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
94
|
+
return if column_name_to_rules.empty?
|
95
|
+
|
96
|
+
# column_names.size == 1
|
97
|
+
# results => [1, 2, 3, 4]
|
98
|
+
# column_names.size > 1
|
99
|
+
# results => [[1, 'email'], [2, 'email']]
|
100
|
+
if column_names.size == 1
|
101
|
+
results[0...TCellAgent.configuration.max_data_ex_db_records_per_request].each do |result|
|
102
|
+
namespaced_column_name = column_names[0]
|
103
|
+
rules = column_name_to_rules.fetch(namespaced_column_name, [])
|
104
|
+
rules.each do |rule|
|
105
|
+
tcell_context.add_response_db_filter(
|
106
|
+
result,
|
107
|
+
rule,
|
108
|
+
database_name,
|
109
|
+
'*',
|
110
|
+
table_name,
|
111
|
+
normalized_column_names[namespaced_column_name]
|
112
|
+
)
|
113
|
+
end
|
65
114
|
end
|
66
|
-
|
67
|
-
|
68
|
-
|
115
|
+
else
|
116
|
+
results[0...TCellAgent.configuration.max_data_ex_db_records_per_request].each do |result|
|
117
|
+
result.each_with_index do |val, index|
|
118
|
+
namespaced_column_name = column_names[index]
|
119
|
+
rules = column_name_to_rules.fetch(namespaced_column_name, [])
|
120
|
+
rules.each do |rule|
|
121
|
+
tcell_context.add_response_db_filter(
|
122
|
+
val,
|
123
|
+
rule,
|
124
|
+
database_name,
|
125
|
+
'*',
|
126
|
+
table_name,
|
127
|
+
normalized_column_names[namespaced_column_name]
|
128
|
+
)
|
129
|
+
end
|
130
|
+
end
|
69
131
|
end
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
70
137
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
138
|
+
def self.instrument_find_by_sql(results)
|
139
|
+
return if results.empty?
|
140
|
+
|
141
|
+
if TCellAgent.configuration.enabled &&
|
142
|
+
TCellAgent.configuration.should_instrument? &&
|
143
|
+
TCellAgent.configuration.should_intercept_requests?
|
144
|
+
|
145
|
+
dlp_policy = TCellAgent.policy(TCellAgent::PolicyTypes::DATALOSS)
|
146
|
+
request_env = TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS.fetch(Thread.current.object_id, {})
|
147
|
+
tcell_context = request_env[TCellAgent::Instrumentation::TCELL_ID]
|
148
|
+
|
149
|
+
if tcell_context
|
150
|
+
tcell_context.database_result_sizes.push(results.size)
|
151
|
+
|
152
|
+
if dlp_policy && dlp_policy.enabled
|
153
|
+
first_record = results.first
|
154
|
+
database_name = first_record.class.connection_config.fetch(:database, '*').split('/').last
|
155
|
+
model = first_record.class
|
156
|
+
column_names = model.columns.map(&:name)
|
157
|
+
table_name = model.table_name
|
158
|
+
|
159
|
+
if dlp_policy.database_discovery_enabled
|
160
|
+
TCellAgent.discover_database_fields(
|
161
|
+
tcell_context.route_id,
|
162
|
+
database_name,
|
163
|
+
'*',
|
164
|
+
table_name,
|
165
|
+
column_names
|
166
|
+
)
|
167
|
+
end
|
79
168
|
|
80
|
-
|
169
|
+
if results.size > TCellAgent.configuration.max_data_ex_db_records_per_request
|
170
|
+
TCellAgent.logger.warn("Route (#{tcell_context.route_id}) retrieved too many records")
|
171
|
+
end
|
81
172
|
|
82
|
-
|
83
|
-
|
173
|
+
column_name_to_rules = column_names.each_with_object({}) do |column_name, memo|
|
174
|
+
rules = dlp_policy.get_actions_for_table(
|
175
|
+
database_name,
|
176
|
+
'*',
|
177
|
+
table_name,
|
178
|
+
column_name,
|
179
|
+
tcell_context.route_id
|
180
|
+
)
|
84
181
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
182
|
+
memo[column_name] = rules if rules
|
183
|
+
end
|
184
|
+
|
185
|
+
return if column_name_to_rules.empty?
|
186
|
+
|
187
|
+
results[0...TCellAgent.configuration.max_data_ex_db_records_per_request].each do |record|
|
188
|
+
column_name_to_rules.each do |column_name, rules|
|
189
|
+
next unless rules
|
190
|
+
rules.each do |rule|
|
191
|
+
tcell_context.add_response_db_filter(
|
192
|
+
record[column_name.to_sym],
|
193
|
+
rule,
|
194
|
+
database_name,
|
195
|
+
'*',
|
196
|
+
table_name,
|
197
|
+
column_name
|
198
|
+
)
|
101
199
|
end
|
102
200
|
end
|
103
201
|
end
|
@@ -108,23 +206,24 @@ module TCellAgent
|
|
108
206
|
end
|
109
207
|
|
110
208
|
class MyRailtie < Rails::Railtie
|
111
|
-
initializer 'activeservice.autoload', :after => :set_autoload_paths do |
|
112
|
-
|
209
|
+
initializer 'activeservice.autoload', :after => :set_autoload_paths do |_app|
|
113
210
|
if defined?(ActiveRecord)
|
114
211
|
ActiveRecord::ConnectionAdapters::AbstractAdapter.class_eval do
|
115
212
|
alias_method :tcell_translate_exception, :translate_exception
|
116
|
-
def translate_exception(
|
117
|
-
result = tcell_translate_exception(
|
213
|
+
def translate_exception(exception, message)
|
214
|
+
result = tcell_translate_exception(exception, message)
|
118
215
|
|
119
|
-
TCellAgent::Instrumentation.safe_block(
|
120
|
-
rust_policies = TCellAgent.policy(TCellAgent::PolicyTypes::
|
216
|
+
TCellAgent::Instrumentation.safe_block('Set sql_exception_detected in meta') do
|
217
|
+
rust_policies = TCellAgent.policy(TCellAgent::PolicyTypes::RUST)
|
121
218
|
if rust_policies && rust_policies.appfirewall_enabled
|
122
|
-
request_env = TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS.fetch(
|
219
|
+
request_env = TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS.fetch(
|
220
|
+
Thread.current.object_id, {}
|
221
|
+
)
|
123
222
|
tcell_data = request_env[TCellAgent::Instrumentation::TCELL_ID]
|
124
223
|
if tcell_data && result.is_a?(ActiveRecord::StatementInvalid)
|
125
|
-
tcell_data.sql_exceptions.push(
|
126
|
-
|
127
|
-
|
224
|
+
tcell_data.sql_exceptions.push(
|
225
|
+
{ 'exception_name' => result.class.name, 'exception_payload' => message }
|
226
|
+
)
|
128
227
|
end
|
129
228
|
end
|
130
229
|
end
|
@@ -133,86 +232,90 @@ module TCellAgent
|
|
133
232
|
end
|
134
233
|
end
|
135
234
|
|
136
|
-
ActiveRecord::
|
235
|
+
ActiveRecord::Calculations.module_eval do
|
236
|
+
alias_method :tcell_pluck, :pluck
|
237
|
+
def pluck(*column_names)
|
238
|
+
results = tcell_pluck(*column_names)
|
137
239
|
|
138
|
-
|
240
|
+
TCellAgent::Instrumentation.safe_block('Running DLP on pluck') do
|
241
|
+
TCellAgent::DLP.instrument_pluck(results, column_names, model)
|
242
|
+
end
|
243
|
+
|
244
|
+
results
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
ActiveRecord::Querying.module_eval do
|
249
|
+
if ::Rails::VERSION::MAJOR == 5
|
139
250
|
alias_method :tcell_find_by_sql, :find_by_sql
|
140
251
|
def find_by_sql(*args)
|
141
252
|
results = tcell_find_by_sql(*args)
|
142
253
|
|
143
|
-
TCellAgent::Instrumentation.safe_block(
|
254
|
+
TCellAgent::Instrumentation.safe_block('Running DLP on find_by_sql') do
|
144
255
|
TCellAgent::DLP.instrument_find_by_sql(results)
|
145
256
|
end
|
146
257
|
|
147
258
|
results
|
148
259
|
end
|
149
260
|
|
150
|
-
elsif
|
261
|
+
elsif ::Rails::VERSION::MAJOR < 5
|
151
262
|
alias_method :tcell_find_by_sql, :find_by_sql
|
152
263
|
def find_by_sql(sql, binds = [])
|
153
264
|
results = tcell_find_by_sql(sql, binds)
|
154
265
|
|
155
|
-
TCellAgent::Instrumentation.safe_block(
|
266
|
+
TCellAgent::Instrumentation.safe_block('Running DLP on find_by_sql') do
|
156
267
|
TCellAgent::DLP.instrument_find_by_sql(results)
|
157
268
|
end
|
158
269
|
|
159
270
|
results
|
160
271
|
end
|
161
272
|
end
|
162
|
-
|
163
273
|
end
|
164
|
-
|
165
274
|
end
|
166
|
-
|
167
275
|
end
|
168
276
|
end
|
169
277
|
end
|
170
278
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
279
|
# - Request
|
176
280
|
# - Session Id event
|
177
281
|
# - Session Id redact
|
178
282
|
# - Session Id hash
|
179
283
|
# - Session Id mask
|
180
284
|
# - Database-Stuff - [event, redact]
|
181
|
-
#
|
285
|
+
#
|
182
286
|
# - Log
|
183
287
|
#
|
184
288
|
|
185
289
|
module TCellAgent
|
186
290
|
module Policies
|
187
291
|
class DataLossPolicy
|
188
|
-
|
189
292
|
def log_enforce(tcell_context, sanitize_string)
|
190
293
|
if TCellAgent.configuration.enabled &&
|
191
|
-
|
192
|
-
|
193
|
-
if
|
194
|
-
session_id_actions =
|
294
|
+
TCellAgent.configuration.should_instrument? &&
|
295
|
+
TCellAgent.configuration.should_intercept_requests?
|
296
|
+
if tcell_context && tcell_context.session_id
|
297
|
+
session_id_actions = get_actions_for_session_id
|
195
298
|
if session_id_actions
|
196
299
|
send_event = false
|
197
|
-
sanitize_string.gsub!(tcell_context.session_id)
|
300
|
+
sanitize_string.gsub!(tcell_context.session_id) do |m|
|
198
301
|
if session_id_actions.log_redact
|
199
302
|
send_event = true
|
200
|
-
m =
|
303
|
+
m = '[session_id]'
|
201
304
|
elsif session_id_actions.log_hash
|
202
305
|
send_event = true
|
203
|
-
m =
|
306
|
+
m = '[hash]'
|
204
307
|
elsif session_id_actions.log_event
|
205
308
|
send_event = true
|
206
309
|
end
|
207
310
|
m
|
208
|
-
|
311
|
+
end
|
209
312
|
if send_event
|
210
313
|
TCellAgent.send_event(
|
211
314
|
TCellAgent::SensorEvents::DlpEvent.new(
|
212
315
|
tcell_context.route_id,
|
213
316
|
tcell_context.uri,
|
214
317
|
TCellAgent::SensorEvents::DlpEvent::FOUND_IN_LOG
|
215
|
-
|
318
|
+
).for_framework(TCellAgent::SensorEvents::DlpEvent::FRAMEWORK_VARIABLE_SESSION_ID)
|
216
319
|
)
|
217
320
|
end
|
218
321
|
end
|
@@ -224,13 +327,13 @@ module TCellAgent
|
|
224
327
|
|
225
328
|
def response_body_enforce(tcell_context, sanitize_string)
|
226
329
|
if TCellAgent.configuration.enabled &&
|
227
|
-
|
228
|
-
|
229
|
-
if
|
230
|
-
session_id_actions =
|
330
|
+
TCellAgent.configuration.should_instrument? &&
|
331
|
+
TCellAgent.configuration.should_intercept_requests?
|
332
|
+
if tcell_context && tcell_context.session_id
|
333
|
+
session_id_actions = get_actions_for_session_id
|
231
334
|
if session_id_actions
|
232
335
|
send_event = false
|
233
|
-
sanitize_string.gsub!(tcell_context.session_id)
|
336
|
+
sanitize_string.gsub!(tcell_context.session_id) do |m|
|
234
337
|
if session_id_actions.body_redact
|
235
338
|
# m = "[session_id]"
|
236
339
|
send_event = true
|
@@ -241,7 +344,7 @@ module TCellAgent
|
|
241
344
|
send_event = true
|
242
345
|
end
|
243
346
|
m
|
244
|
-
|
347
|
+
end
|
245
348
|
end
|
246
349
|
if send_event
|
247
350
|
TCellAgent.send_event(
|
@@ -249,7 +352,7 @@ module TCellAgent
|
|
249
352
|
tcell_context.route_id,
|
250
353
|
tcell_context.uri,
|
251
354
|
TCellAgent::SensorEvents::DlpEvent::FOUND_IN_BODY
|
252
|
-
|
355
|
+
).for_framework(TCellAgent::SensorEvents::DlpEvent::FRAMEWORK_VARIABLE_SESSION_ID)
|
253
356
|
)
|
254
357
|
end
|
255
358
|
end
|
@@ -263,11 +366,11 @@ end
|
|
263
366
|
|
264
367
|
class Logger
|
265
368
|
alias_method :tcell_old_add, :add
|
266
|
-
def add(severity, message = nil, progname = nil
|
369
|
+
def add(severity, message = nil, progname = nil)
|
267
370
|
if TCellAgent.configuration.enabled &&
|
268
|
-
|
269
|
-
|
270
|
-
|
371
|
+
TCellAgent.configuration.should_instrument? &&
|
372
|
+
TCellAgent.configuration.should_intercept_requests? &&
|
373
|
+
severity >= level
|
271
374
|
|
272
375
|
progname ||= @progname
|
273
376
|
if message.nil?
|
@@ -279,16 +382,14 @@ class Logger
|
|
279
382
|
end
|
280
383
|
end
|
281
384
|
|
282
|
-
TCellAgent::Instrumentation.safe_block_no_log(
|
283
|
-
dlp_policy = TCellAgent.policy(TCellAgent::PolicyTypes::
|
385
|
+
TCellAgent::Instrumentation.safe_block_no_log('Handling DLP log message filtering') do
|
386
|
+
dlp_policy = TCellAgent.policy(TCellAgent::PolicyTypes::DATALOSS)
|
284
387
|
request_env = TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS.fetch(Thread.current.object_id, nil)
|
285
388
|
if message && dlp_policy && request_env
|
286
389
|
tcell_context = request_env[TCellAgent::Instrumentation::TCELL_ID]
|
287
|
-
if tcell_context
|
288
|
-
tcell_context.filter_log(message)
|
289
|
-
end
|
390
|
+
tcell_context.filter_log(message) if tcell_context
|
290
391
|
end
|
291
|
-
|
392
|
+
end
|
292
393
|
end
|
293
394
|
|
294
395
|
tcell_old_add(severity, message, progname)
|