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.
Files changed (163) hide show
  1. checksums.yaml +5 -5
  2. data/bin/tcell_agent +26 -14
  3. data/lib/tcell_agent.rb +16 -10
  4. data/lib/tcell_agent/agent.rb +78 -97
  5. data/lib/tcell_agent/agent/route_manager.rb +0 -16
  6. data/lib/tcell_agent/agent/static_agent.rb +9 -30
  7. data/lib/tcell_agent/authlogic.rb +3 -6
  8. data/lib/tcell_agent/config/unknown_options.rb +4 -8
  9. data/lib/tcell_agent/configuration.rb +38 -119
  10. data/lib/tcell_agent/devise.rb +25 -27
  11. data/lib/tcell_agent/hooks/login_fraud.rb +30 -33
  12. data/lib/tcell_agent/instrument_servers.rb +25 -0
  13. data/lib/tcell_agent/instrumentation.rb +12 -10
  14. data/lib/tcell_agent/instrumentation/cmdi.rb +19 -15
  15. data/lib/tcell_agent/instrumentation/lfi.rb +73 -0
  16. data/lib/tcell_agent/instrumentation/monkey_patches/file.rb +25 -0
  17. data/lib/tcell_agent/instrumentation/monkey_patches/io.rb +123 -0
  18. data/lib/tcell_agent/instrumentation/monkey_patches/kernel.rb +159 -0
  19. data/lib/tcell_agent/logger.rb +50 -114
  20. data/lib/tcell_agent/patches.rb +6 -7
  21. data/lib/tcell_agent/policies/appfirewall_policy.rb +26 -0
  22. data/lib/tcell_agent/policies/command_injection_policy.rb +28 -0
  23. data/lib/tcell_agent/policies/dataloss_policy.rb +44 -44
  24. data/lib/tcell_agent/policies/headers_policy.rb +25 -0
  25. data/lib/tcell_agent/policies/http_redirect_policy.rb +13 -79
  26. data/lib/tcell_agent/policies/js_agent_policy.rb +27 -0
  27. data/lib/tcell_agent/policies/local_file_access.rb +28 -0
  28. data/lib/tcell_agent/policies/login_policy.rb +43 -0
  29. data/lib/tcell_agent/policies/patches_policy.rb +27 -0
  30. data/lib/tcell_agent/policies/policies_manager.rb +68 -0
  31. data/lib/tcell_agent/policies/policy_polling.rb +58 -0
  32. data/lib/tcell_agent/policies/policy_types.rb +14 -0
  33. data/lib/tcell_agent/policies/system_enablements.rb +27 -0
  34. data/lib/tcell_agent/rails/auth/authlogic.rb +43 -68
  35. data/lib/tcell_agent/rails/auth/devise.rb +20 -23
  36. data/lib/tcell_agent/rails/auth/doorkeeper.rb +63 -74
  37. data/lib/tcell_agent/rails/csrf_exception.rb +2 -2
  38. data/lib/tcell_agent/rails/dlp.rb +25 -15
  39. data/lib/tcell_agent/rails/dlp_handler.rb +1 -2
  40. data/lib/tcell_agent/rails/js_agent_insert.rb +12 -13
  41. data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +4 -25
  42. data/lib/tcell_agent/rails/middleware/context_middleware.rb +2 -12
  43. data/lib/tcell_agent/rails/middleware/global_middleware.rb +0 -1
  44. data/lib/tcell_agent/rails/middleware/headers_middleware.rb +14 -34
  45. data/lib/tcell_agent/rails/on_start.rb +32 -31
  46. data/lib/tcell_agent/rails/routes.rb +7 -6
  47. data/lib/tcell_agent/rails/routes/grape.rb +1 -3
  48. data/lib/tcell_agent/rails/routes/route_id.rb +3 -1
  49. data/lib/tcell_agent/rails/settings_reporter.rb +23 -36
  50. data/lib/tcell_agent/rails/start_agent_after_initializers.rb +12 -0
  51. data/lib/tcell_agent/rails/tcell_body_proxy.rb +6 -4
  52. data/lib/tcell_agent/rust/agent_config.rb +49 -0
  53. data/lib/tcell_agent/rust/{libtcellagent-alpine-1.3.2.so → libtcellagent-4.14.0.dylib} +0 -0
  54. data/lib/tcell_agent/rust/libtcellagent-4.14.0.so +0 -0
  55. data/lib/tcell_agent/rust/{libtcellagent-1.3.2.so → libtcellagent-alpine-4.14.0.so} +0 -0
  56. data/lib/tcell_agent/rust/models.rb +0 -55
  57. data/lib/tcell_agent/rust/native_agent.rb +531 -0
  58. data/lib/tcell_agent/rust/native_agent_response.rb +42 -0
  59. data/lib/tcell_agent/rust/native_library.rb +68 -0
  60. data/lib/tcell_agent/rust/tcellagent-4.14.0.dll +0 -0
  61. data/lib/tcell_agent/sensor_events/agent_setting_event.rb +12 -0
  62. data/lib/tcell_agent/sensor_events/{app_config.rb → app_config_setting_event.rb} +0 -6
  63. data/lib/tcell_agent/sensor_events/dlp.rb +2 -6
  64. data/lib/tcell_agent/sensor_events/sensor.rb +0 -62
  65. data/lib/tcell_agent/sensor_events/server_agent.rb +13 -18
  66. data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +0 -108
  67. data/lib/tcell_agent/sensor_events/util/utils.rb +0 -2
  68. data/lib/tcell_agent/servers/passenger.rb +1 -28
  69. data/lib/tcell_agent/servers/puma.rb +3 -21
  70. data/lib/tcell_agent/servers/rails_server.rb +1 -1
  71. data/lib/tcell_agent/servers/thin.rb +2 -2
  72. data/lib/tcell_agent/servers/unicorn.rb +19 -80
  73. data/lib/tcell_agent/servers/webrick.rb +1 -1
  74. data/lib/tcell_agent/settings_reporter.rb +24 -24
  75. data/lib/tcell_agent/sinatra.rb +14 -16
  76. data/lib/tcell_agent/tcell_context.rb +40 -14
  77. data/lib/tcell_agent/utils/headers.rb +14 -0
  78. data/lib/tcell_agent/version.rb +1 -1
  79. data/spec/lib/tcell_agent/cmdi_spec.rb +0 -585
  80. data/spec/lib/tcell_agent/config/unknown_options_spec.rb +0 -18
  81. data/spec/lib/tcell_agent/configuration_spec.rb +4 -140
  82. data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +46 -173
  83. data/spec/lib/tcell_agent/instrumentation/cmdi/io_cmdi_spec.rb +504 -0
  84. data/spec/lib/tcell_agent/instrumentation/cmdi/kernel_cmdi_spec.rb +435 -0
  85. data/spec/lib/tcell_agent/instrumentation/lfi/file_lfi_spec.rb +326 -0
  86. data/spec/lib/tcell_agent/instrumentation/lfi/io_lfi_spec.rb +556 -0
  87. data/spec/lib/tcell_agent/instrumentation/lfi/kernel_lfi_spec.rb +249 -0
  88. data/spec/lib/tcell_agent/instrumentation/lfi_spec.rb +105 -0
  89. data/spec/lib/tcell_agent/patches_spec.rb +25 -43
  90. data/spec/lib/tcell_agent/policies/appfirewall_policy_spec.rb +183 -0
  91. data/spec/lib/tcell_agent/policies/clickjacking_policy_spec.rb +57 -0
  92. data/spec/lib/tcell_agent/policies/command_injection_policy_spec.rb +84 -773
  93. data/spec/lib/tcell_agent/policies/content_security_policy_spec.rb +161 -0
  94. data/spec/lib/tcell_agent/policies/dataloss_policy_spec.rb +9 -9
  95. data/spec/lib/tcell_agent/policies/http_redirect_policy_spec.rb +243 -198
  96. data/spec/lib/tcell_agent/policies/js_agent_policy_spec.rb +75 -0
  97. data/spec/lib/tcell_agent/policies/login_policy_spec.rb +165 -33
  98. data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +84 -277
  99. data/spec/lib/tcell_agent/policies/policies_manager_spec.rb +104 -0
  100. data/spec/lib/tcell_agent/policies/policy_polling_spec.rb +6 -0
  101. data/spec/lib/tcell_agent/policies/secure_headers_policy_spec.rb +56 -0
  102. data/spec/lib/tcell_agent/rails/csrf_exception_spec.rb +9 -18
  103. data/spec/lib/tcell_agent/rails/js_agent_insert_spec.rb +13 -30
  104. data/spec/lib/tcell_agent/rails/logger_spec.rb +27 -7
  105. data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +17 -12
  106. data/spec/lib/tcell_agent/rails/routes/routes_spec.rb +14 -14
  107. data/spec/lib/tcell_agent/sensor_events/util/sanitizer_utilities_spec.rb +0 -35
  108. data/spec/lib/tcell_agent/settings_reporter_spec.rb +127 -153
  109. data/spec/spec_helper.rb +1 -1
  110. data/spec/support/builders.rb +104 -0
  111. data/spec/support/force_logger_mocking.rb +38 -0
  112. data/spec/support/resources/lfi_sample_file.txt +2 -0
  113. data/spec/support/static_agent_overrides.rb +0 -15
  114. metadata +63 -74
  115. data/lib/tcell_agent/agent/event_processor.rb +0 -326
  116. data/lib/tcell_agent/agent/fork_pipe_manager.rb +0 -113
  117. data/lib/tcell_agent/agent/policy_manager.rb +0 -219
  118. data/lib/tcell_agent/agent/policy_types.rb +0 -30
  119. data/lib/tcell_agent/api.rb +0 -91
  120. data/lib/tcell_agent/appsensor/injections_reporter.rb +0 -24
  121. data/lib/tcell_agent/config/child_process_events.rb +0 -8
  122. data/lib/tcell_agent/instrumentation/cmdi/backtick.rb +0 -10
  123. data/lib/tcell_agent/instrumentation/cmdi/exec.rb +0 -14
  124. data/lib/tcell_agent/instrumentation/cmdi/popen.rb +0 -28
  125. data/lib/tcell_agent/instrumentation/cmdi/spawn.rb +0 -11
  126. data/lib/tcell_agent/instrumentation/cmdi/system.rb +0 -11
  127. data/lib/tcell_agent/policies/http_tx_policy.rb +0 -60
  128. data/lib/tcell_agent/policies/login_fraud_policy.rb +0 -45
  129. data/lib/tcell_agent/policies/rust_policies.rb +0 -110
  130. data/lib/tcell_agent/rails.rb +0 -40
  131. data/lib/tcell_agent/rust/libtcellagent-1.3.2.dylib +0 -0
  132. data/lib/tcell_agent/rust/tcellagent-1.3.2.dll +0 -0
  133. data/lib/tcell_agent/rust/whisperer.rb +0 -308
  134. data/lib/tcell_agent/sensor_events/appsensor_event.rb +0 -52
  135. data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +0 -45
  136. data/lib/tcell_agent/sensor_events/command_injection.rb +0 -75
  137. data/lib/tcell_agent/sensor_events/honeytokens.rb +0 -16
  138. data/lib/tcell_agent/sensor_events/login_fraud.rb +0 -60
  139. data/lib/tcell_agent/sensor_events/metrics.rb +0 -123
  140. data/lib/tcell_agent/sensor_events/patches.rb +0 -21
  141. data/lib/tcell_agent/start_background_thread.rb +0 -55
  142. data/lib/tcell_agent/system_info.rb +0 -11
  143. data/lib/tcell_agent/utils/io.rb +0 -38
  144. data/lib/tcell_agent/utils/passwords.rb +0 -28
  145. data/lib/tcell_agent/utils/queue_with_timeout.rb +0 -142
  146. data/spec/lib/tcell_agent/agent/fork_pipe_manager_spec.rb +0 -100
  147. data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +0 -535
  148. data/spec/lib/tcell_agent/agent/static_agent_spec.rb +0 -133
  149. data/spec/lib/tcell_agent/api/api_spec.rb +0 -39
  150. data/spec/lib/tcell_agent/appsensor/injections_reporter_spec.rb +0 -187
  151. data/spec/lib/tcell_agent/instrumentation_spec.rb +0 -225
  152. data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +0 -517
  153. data/spec/lib/tcell_agent/policies/http_tx_policy_spec.rb +0 -22
  154. data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +0 -293
  155. data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +0 -198
  156. data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +0 -180
  157. data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +0 -116
  158. data/spec/lib/tcell_agent/rust/models_spec.rb +0 -120
  159. data/spec/lib/tcell_agent/rust/whisperer_spec.rb +0 -704
  160. data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +0 -45
  161. data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +0 -272
  162. data/spec/lib/tcell_agent/utils/bounded_queue_spec.rb +0 -52
  163. 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.enabled &&
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
- login_fraud_policy = TCellAgent.policy(TCellAgent::PolicyTypes::LOGINFRAUD)
26
- if login_fraud_policy && login_fraud_policy.login_failed_enabled
27
- TCellAgent.send_event(
28
- TCellAgent::SensorEvents::LoginFailure.new(
29
- request.env,
30
- tcell_data,
31
- user_id,
32
- password
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
- login_fraud_policy = TCellAgent.policy(TCellAgent::PolicyTypes::LOGINFRAUD)
117
- if login_fraud_policy && login_fraud_policy.login_success_enabled
118
- tcell_data = request.env[TCellAgent::Instrumentation::TCELL_ID]
119
- if tcell_data
120
- TCellAgent.send_event(TCellAgent::SensorEvents::LoginSuccess.new(request.env, tcell_data, username, nil))
121
- end
122
- end
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
- if defined?(Doorkeeper)
4
- require 'tcell_agent/agent'
5
- require 'tcell_agent/sensor_events/login_fraud'
3
+ require 'tcell_agent/agent'
4
+ require 'tcell_agent/sensor_events/login_fraud'
6
5
 
7
- module TCellAgent
8
- module DoorkeeperInstrumentation
9
- Doorkeeper::TokensController.class_eval do
10
- alias_method :tcell_authorize_response, :authorize_response
11
- def authorize_response
12
- result = tcell_authorize_response
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
- TCellAgent::Instrumentation.safe_block('Doorkeeper Token Authorize') do
15
- if TCellAgent.configuration.enabled &&
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
- if tcell_data
24
- password = nil
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
- end
46
- end
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
- module TCellAuthorizationsNew
55
- def new
56
- super if defined?(super)
47
+ module TCellAuthorizationsNew
48
+ def new
49
+ super if defined?(super)
57
50
 
58
- TCellAgent::Instrumentation.safe_block('Doorkeeper Token Authorize') do
59
- if TCellAgent.configuration.enabled &&
60
- TCellAgent.configuration.should_intercept_requests?
61
- if pre_auth.error
62
- login_fraud_policy = TCellAgent.policy(TCellAgent::PolicyTypes::LOGINFRAUD)
63
- if login_fraud_policy &&
64
- login_fraud_policy.enabled &&
65
- login_fraud_policy.login_failed_enabled
66
- tcell_data = request.env[TCellAgent::Instrumentation::TCELL_ID]
67
- if tcell_data && pre_auth.error
68
- password = nil
69
- TCellAgent.send_event(
70
- TCellAgent::SensorEvents::LoginFailure.new(
71
- request.env,
72
- tcell_data,
73
- current_resource_owner.id,
74
- password
75
- )
76
- )
77
- end
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
- rust_policies = TCellAgent.policy(TCellAgent::PolicyTypes::RUST)
8
- if rust_policies && rust_policies.appfirewall_enabled
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.enabled &&
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
- TCellAgent.logger.warn("Route (#{tcell_context.route_id}) retrieved too many records")
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.enabled &&
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
- TCellAgent.logger.warn("Route (#{tcell_context.route_id}) retrieved too many records")
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
- rust_policies = TCellAgent.policy(TCellAgent::PolicyTypes::RUST)
218
- if rust_policies && rust_policies.appfirewall_enabled
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.enabled &&
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.enabled &&
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
- dlp_policy = TCellAgent.policy(TCellAgent::PolicyTypes::DATALOSS)
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
- if message && dlp_policy && request_env
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.enabled &&
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
- if (response_headers['Content-Type'] || '').start_with?('text/html')
48
- rust_policy = TCellAgent.policy(TCellAgent::PolicyTypes::RUST)
49
- if rust_policy
50
- script_insert = rust_policy.get_js_agent_script_tag(
51
- request.env[TCellAgent::Instrumentation::TCELL_ID]
52
- )
53
- if script_insert
54
- js_agent_handler = proc { |si, resp|
55
- handle_js_agent_insert(si, resp)
56
- }
57
- end
58
- end
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
- orig = (Time.now.to_f * 1000).to_i
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
- response_time = (Time.now.to_f * 1000).to_i - orig
31
- TCellAgent::Instrumentation.safe_block('Handling Route Time') do
32
- route_id = env[TCellAgent::Instrumentation::TCELL_ID].route_id
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/sensor_events/sensor'
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].ip_address = TCellAgent::Utils::Rails.better_ip(request)
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