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.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/bin/tcell_agent +10 -2
  3. data/lib/tcell_agent.rb +3 -3
  4. data/lib/tcell_agent/agent.rb +42 -52
  5. data/lib/tcell_agent/agent/event_processor.rb +129 -162
  6. data/lib/tcell_agent/agent/fork_pipe_manager.rb +57 -62
  7. data/lib/tcell_agent/agent/policy_manager.rb +83 -104
  8. data/lib/tcell_agent/agent/policy_types.rb +24 -29
  9. data/lib/tcell_agent/agent/route_manager.rb +36 -46
  10. data/lib/tcell_agent/agent/static_agent.rb +19 -21
  11. data/lib/tcell_agent/api.rb +23 -28
  12. data/lib/tcell_agent/appsensor/injections_reporter.rb +7 -11
  13. data/lib/tcell_agent/authlogic.rb +7 -7
  14. data/lib/tcell_agent/cmdi.rb +22 -23
  15. data/lib/tcell_agent/config/unknown_options.rb +71 -69
  16. data/lib/tcell_agent/configuration.rb +187 -191
  17. data/lib/tcell_agent/devise.rb +13 -15
  18. data/lib/tcell_agent/hooks/login_fraud.rb +1 -1
  19. data/lib/tcell_agent/instrumentation.rb +120 -124
  20. data/lib/tcell_agent/logger.rb +29 -45
  21. data/lib/tcell_agent/patches.rb +5 -5
  22. data/lib/tcell_agent/policies/dataloss_policy.rb +263 -288
  23. data/lib/tcell_agent/policies/http_redirect_policy.rb +25 -37
  24. data/lib/tcell_agent/policies/http_tx_policy.rb +48 -52
  25. data/lib/tcell_agent/policies/login_fraud_policy.rb +15 -20
  26. data/lib/tcell_agent/policies/policy.rb +0 -2
  27. data/lib/tcell_agent/policies/rust_policies.rb +24 -29
  28. data/lib/tcell_agent/rails.rb +2 -3
  29. data/lib/tcell_agent/rails/auth/authlogic.rb +2 -2
  30. data/lib/tcell_agent/rails/auth/devise.rb +2 -2
  31. data/lib/tcell_agent/rails/auth/doorkeeper.rb +2 -2
  32. data/lib/tcell_agent/rails/better_ip.rb +12 -16
  33. data/lib/tcell_agent/rails/csrf_exception.rb +4 -7
  34. data/lib/tcell_agent/rails/dlp.rb +208 -107
  35. data/lib/tcell_agent/rails/dlp/process_request.rb +37 -47
  36. data/lib/tcell_agent/rails/dlp_handler.rb +9 -11
  37. data/lib/tcell_agent/rails/js_agent_insert.rb +11 -14
  38. data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +8 -7
  39. data/lib/tcell_agent/rails/middleware/context_middleware.rb +4 -5
  40. data/lib/tcell_agent/rails/middleware/global_middleware.rb +5 -8
  41. data/lib/tcell_agent/rails/middleware/headers_middleware.rb +24 -27
  42. data/lib/tcell_agent/rails/on_start.rb +5 -5
  43. data/lib/tcell_agent/rails/responses.rb +7 -9
  44. data/lib/tcell_agent/rails/routes.rb +62 -81
  45. data/lib/tcell_agent/rails/routes/grape.rb +25 -30
  46. data/lib/tcell_agent/rails/routes/route_id.rb +9 -14
  47. data/lib/tcell_agent/rails/settings_reporter.rb +44 -33
  48. data/lib/tcell_agent/rails/tcell_body_proxy.rb +15 -18
  49. data/lib/tcell_agent/routes/table.rb +31 -33
  50. data/lib/tcell_agent/rust/{libtcellagent-1.3.0.dylib → libtcellagent-1.3.1.dylib} +0 -0
  51. data/lib/tcell_agent/rust/{libtcellagent-1.3.0.so → libtcellagent-1.3.1.so} +0 -0
  52. data/lib/tcell_agent/rust/{libtcellagent-alpine-1.3.0.so → libtcellagent-alpine-1.3.1.so} +0 -0
  53. data/lib/tcell_agent/rust/models.rb +32 -37
  54. data/lib/tcell_agent/rust/tcellagent-1.3.1.dll +0 -0
  55. data/lib/tcell_agent/rust/whisperer.rb +101 -104
  56. data/lib/tcell_agent/sensor_events/app_config.rb +7 -7
  57. data/lib/tcell_agent/sensor_events/appsensor_event.rb +26 -27
  58. data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +20 -88
  59. data/lib/tcell_agent/sensor_events/command_injection.rb +52 -80
  60. data/lib/tcell_agent/sensor_events/discovery.rb +27 -27
  61. data/lib/tcell_agent/sensor_events/dlp.rb +50 -56
  62. data/lib/tcell_agent/sensor_events/honeytokens.rb +9 -9
  63. data/lib/tcell_agent/sensor_events/metrics.rb +20 -21
  64. data/lib/tcell_agent/sensor_events/patches.rb +10 -12
  65. data/lib/tcell_agent/sensor_events/sensor.rb +32 -36
  66. data/lib/tcell_agent/sensor_events/server_agent.rb +130 -127
  67. data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +60 -80
  68. data/lib/tcell_agent/sensor_events/util/utils.rb +3 -5
  69. data/lib/tcell_agent/servers/passenger.rb +5 -9
  70. data/lib/tcell_agent/servers/puma.rb +18 -27
  71. data/lib/tcell_agent/servers/rails_server.rb +5 -9
  72. data/lib/tcell_agent/servers/thin.rb +2 -4
  73. data/lib/tcell_agent/servers/unicorn.rb +18 -27
  74. data/lib/tcell_agent/servers/webrick.rb +2 -4
  75. data/lib/tcell_agent/settings_reporter.rb +126 -0
  76. data/lib/tcell_agent/sinatra.rb +24 -26
  77. data/lib/tcell_agent/start_background_thread.rb +21 -142
  78. data/lib/tcell_agent/system_info.rb +4 -3
  79. data/lib/tcell_agent/tcell_context.rb +150 -0
  80. data/lib/tcell_agent/userinfo.rb +3 -3
  81. data/lib/tcell_agent/utils/io.rb +19 -24
  82. data/lib/tcell_agent/utils/params.rb +9 -15
  83. data/lib/tcell_agent/utils/queue_with_timeout.rb +26 -32
  84. data/lib/tcell_agent/utils/strings.rb +4 -6
  85. data/lib/tcell_agent/version.rb +1 -1
  86. data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +5 -5
  87. data/spec/lib/tcell_agent/agent/static_agent_spec.rb +7 -7
  88. data/spec/lib/tcell_agent/cmdi_spec.rb +21 -21
  89. data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +29 -24
  90. data/spec/lib/tcell_agent/instrumentation_spec.rb +4 -4
  91. data/spec/lib/tcell_agent/patches_spec.rb +8 -8
  92. data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +23 -23
  93. data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +2 -2
  94. data/spec/lib/tcell_agent/rails/csrf_exception_spec.rb +69 -0
  95. data/spec/lib/tcell_agent/rails/dlp_spec.rb +1039 -0
  96. data/spec/lib/tcell_agent/rails/js_agent_insert_spec.rb +271 -0
  97. data/spec/lib/tcell_agent/rails/logger_spec.rb +5 -5
  98. data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +3 -3
  99. data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +4 -4
  100. data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +5 -5
  101. data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +1 -1
  102. data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +11 -8
  103. data/spec/lib/tcell_agent/rails/responses_spec.rb +2 -2
  104. data/spec/lib/tcell_agent/rails/routes/grape_spec.rb +2 -2
  105. data/spec/lib/tcell_agent/rails/routes/route_id_spec.rb +1 -1
  106. data/spec/lib/tcell_agent/rails/routes/routes_spec.rb +4 -4
  107. data/spec/lib/tcell_agent/rust/models_spec.rb +83 -75
  108. data/spec/lib/tcell_agent/rust/whisperer_spec.rb +14 -14
  109. data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +19 -70
  110. data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +1 -1
  111. data/spec/lib/tcell_agent/settings_reporter_spec.rb +162 -0
  112. data/spec/lib/tcell_agent/tcell_context_spec.rb +154 -0
  113. data/spec/spec_helper.rb +5 -0
  114. metadata +18 -10
  115. data/lib/tcell_agent/appsensor/meta_data.rb +0 -132
  116. data/lib/tcell_agent/patches/meta_data.rb +0 -59
  117. data/lib/tcell_agent/rust/tcellagent-1.3.0.dll +0 -0
  118. 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::LoginFraud)
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::LoginFraud)
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 "tcell_agent/utils/strings"
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("Extracting reverse proxy IP") do
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
- reverse_proxy_header = "HTTP_" + reverse_proxy_header.upcase().tr('-','_')
15
- else
16
- reverse_proxy_header = "HTTP_X_FORWARDED_FOR"
17
- end
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
- if TCellAgent::Utils::Strings.present?(x_forwarded_for)
22
- ip = x_forwarded_for.split(',')[0].strip()
23
- else
24
- ip = request.ip
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("AppSensor CSRF Exception processing") do
8
- rust_policies = TCellAgent.policy(TCellAgent::PolicyTypes::Rust)
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.name
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.instrument_find_by_sql(results)
36
- if results.size > 0
37
-
38
- if TCellAgent.configuration.enabled &&
39
- TCellAgent.configuration.should_instrument? &&
40
- TCellAgent.configuration.should_intercept_requests?
41
-
42
- dlp_policy = TCellAgent.policy(TCellAgent::PolicyTypes::DataLoss)
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
- request_env = TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware::THREADS.fetch(Thread.current.object_id, {})
45
- tcell_context = request_env[TCellAgent::Instrumentation::TCELL_ID]
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
- if tcell_context
48
- tcell_context.database_result_sizes.push(results.size)
87
+ memo[namespaced_column_name] = rules if rules
88
+ end
49
89
 
50
- if dlp_policy && dlp_policy.enabled
51
- first_record = results.first
52
- database_name = first_record.class.connection_config().fetch(:database,"*").split('/').last
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
- if dlp_policy.database_discovery_enabled
58
- TCellAgent.discover_database_fields(
59
- tcell_context.route_id,
60
- database_name,
61
- "*",
62
- table_name,
63
- column_names
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
- if results.size > TCellAgent.configuration.max_data_ex_db_records_per_request
68
- TCellAgent.logger.warn("Route (#{tcell_context.route_id}) retrieved too many records")
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
- column_name_to_rules = column_names.inject({}) do |memo, column_name|
72
- rules = dlp_policy.get_actions_for_table(
73
- database_name,
74
- "*",
75
- table_name,
76
- column_name,
77
- tcell_context.route_id
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
- memo[column_name] = rules if rules
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
- memo
83
- end
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
- return if column_name_to_rules.empty?
86
-
87
- results[0...TCellAgent.configuration.max_data_ex_db_records_per_request].each do |record|
88
- column_name_to_rules.each do |column_name, rules|
89
- if rules
90
- rules.each do |rule|
91
- tcell_context.add_response_db_filter(
92
- record[column_name.to_sym],
93
- rule,
94
- database_name,
95
- "*",
96
- table_name,
97
- column_name
98
- )
99
- end
100
- end
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 |app|
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(e, message)
117
- result = tcell_translate_exception(e, message)
213
+ def translate_exception(exception, message)
214
+ result = tcell_translate_exception(exception, message)
118
215
 
119
- TCellAgent::Instrumentation.safe_block("Set sql_exception_detected in meta") do
120
- rust_policies = TCellAgent.policy(TCellAgent::PolicyTypes::Rust)
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(Thread.current.object_id, {})
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
- "exception_name" => result.class.name, "exception_payload" => message
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::Querying.module_eval do
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
- if (::Rails::VERSION::MAJOR == 5)
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("Running DLP on find_by_sql") do
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 (::Rails::VERSION::MAJOR < 5)
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("Running DLP on find_by_sql") do
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
- TCellAgent.configuration.should_instrument? &&
192
- TCellAgent.configuration.should_intercept_requests?
193
- if (tcell_context && tcell_context.session_id)
194
- session_id_actions = self.get_actions_for_session_id
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) {|m|
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 = "[session_id]"
303
+ m = '[session_id]'
201
304
  elsif session_id_actions.log_hash
202
305
  send_event = true
203
- m = "[hash]"
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
- ).for_framework(TCellAgent::SensorEvents::DlpEvent::FRAMEWORK_VARIABLE_SESSION_ID)
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
- TCellAgent.configuration.should_instrument? &&
228
- TCellAgent.configuration.should_intercept_requests?
229
- if (tcell_context && tcell_context.session_id)
230
- session_id_actions = self.get_actions_for_session_id
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) {|m|
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
- ).for_framework(TCellAgent::SensorEvents::DlpEvent::FRAMEWORK_VARIABLE_SESSION_ID)
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, &block)
369
+ def add(severity, message = nil, progname = nil)
267
370
  if TCellAgent.configuration.enabled &&
268
- TCellAgent.configuration.should_instrument? &&
269
- TCellAgent.configuration.should_intercept_requests? &&
270
- severity >= self.level
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("Handling DLP log message filtering") {
283
- dlp_policy = TCellAgent.policy(TCellAgent::PolicyTypes::DataLoss)
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)