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,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'
@@ -1,16 +1,3 @@
1
- # See the file "LICENSE" for the full license governing this code.
2
-
3
- require 'rails'
4
- require 'uri'
5
- require 'tcell_agent/agent'
6
- require 'tcell_agent/sensor_events/sensor'
7
- require 'tcell_agent/sensor_events/appsensor_meta_event'
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
1
  require 'tcell_agent/instrumentation'
15
2
  require 'tcell_agent/rails/responses'
16
3
  require 'tcell_agent/rails/js_agent_insert'
@@ -49,9 +36,9 @@ module TCellAgent
49
36
  def _set_headers(request, response)
50
37
  status, headers, active_response = response
51
38
 
52
- rust_policies = TCellAgent.policy(TCellAgent::PolicyTypes::RUST)
53
- if rust_policies
54
- policy_headers = rust_policies.get_headers(
39
+ TCellAgent::Instrumentation.safe_block('Handling headers') do
40
+ headers_policy = TCellAgent.policy(TCellAgent::PolicyTypes::HEADERS)
41
+ policy_headers = headers_policy.get_headers(
55
42
  request.env[TCellAgent::Instrumentation::TCELL_ID]
56
43
  )
57
44
  policy_headers.each do |header_info|
@@ -73,21 +60,14 @@ module TCellAgent
73
60
  def _handle_redirect(request, response)
74
61
  TCellAgent::Instrumentation.safe_block('Handling Redirect Headers') do
75
62
  status, headers, active_response = response
76
- http_redirect_policy = TCellAgent.policy(TCellAgent::PolicyTypes::HTTPREDIRECT)
77
- if http_redirect_policy && headers.key?('Location')
63
+ if headers.key?('Location')
64
+ http_redirect_policy = TCellAgent.policy(TCellAgent::PolicyTypes::HTTPREDIRECT)
78
65
  tcell_context = request.env[TCellAgent::Instrumentation::TCELL_ID]
79
- route_id = tcell_context.route_id
80
- hmac_session_id = tcell_context.hmac_session_id
81
- new_location = http_redirect_policy.enforce(
82
- headers['Location'],
83
- tcell_context.uri,
84
- tcell_context.fullpath,
85
- tcell_context.request_method,
86
- route_id,
87
- status,
88
- tcell_context.ip_address,
89
- hmac_session_id
66
+ from_domain = URI.parse(tcell_context.uri).host
67
+ new_location = http_redirect_policy.check_redirect(
68
+ headers['Location'], from_domain, status, tcell_context
90
69
  )
70
+
91
71
  # Enforcement
92
72
  headers['Location'] = new_location if new_location
93
73
  end
@@ -143,15 +123,15 @@ module TCellAgent
143
123
  defer_appfw_due_to_streaming = true
144
124
  end
145
125
 
146
- rust_policies = TCellAgent.policy(TCellAgent::PolicyTypes::RUST)
147
- if rust_policies && rust_policies.appfirewall_enabled
148
- event = TCellAgent::SensorEvents::AppSensorMetaEvent.build(
126
+ appfirewall_policy = TCellAgent.policy(TCellAgent::PolicyTypes::APPSENSOR)
127
+ if appfirewall_policy.enabled
128
+ meta_data = TCellAgent::MetaData.for_appfirewall(
149
129
  request, content_length, status_code, response_headers
150
130
  )
151
131
  if defer_appfw_due_to_streaming
152
- response_body.appsensor_meta_event = event
132
+ response_body.meta_data = meta_data
153
133
  else
154
- TCellAgent.send_event(event)
134
+ appfirewall_policy.check_appfirewall_injections(meta_data)
155
135
  end
156
136
  end
157
137
 
@@ -1,41 +1,42 @@
1
1
  # See the file "LICENSE" for the full license governing this code.
2
2
 
3
- # require 'tcell_agent/authlogic' if defined?(Authlogic)
4
-
5
3
  require 'rails'
6
4
 
7
- require 'tcell_agent/configuration'
8
-
9
5
  require 'tcell_agent/rails/routes'
10
- require 'tcell_agent/rails/dlp/process_request'
11
-
12
- TCellAgent::Instrumentation::Rails.send_language_info
13
- TCellAgent::Instrumentation::Rails.send_framework_info
14
6
 
15
- if Rails.application
16
- if TCellAgent.configuration.enabled && TCellAgent.configuration.should_instrument?
17
- TCellAgent::Instrumentation::Rails.send_settings(Rails.application)
18
- end
7
+ require 'tcell_agent/rails/middleware/global_middleware'
8
+ require 'tcell_agent/rails/middleware/body_filter_middleware'
9
+ require 'tcell_agent/rails/middleware/headers_middleware'
10
+ require 'tcell_agent/rails/middleware/context_middleware'
11
+
12
+ require 'tcell_agent/rails/settings_reporter'
13
+ require 'tcell_agent/rails/dlp'
14
+ require 'tcell_agent/rails/csrf_exception'
15
+
16
+ require 'tcell_agent/userinfo'
17
+ require 'cgi'
18
+ require 'thread'
19
+
20
+ module TCellAgent
21
+ class TCellAgentStartupRailtie < Rails::Railtie
22
+ # TCellAgent config can be specified thru
23
+ # Rails initializer's (https://guides.rubyonrails.org/v2.3/configuring.html#using-initializers)
24
+ # so those need to run first since this relies on configuration
25
+ initializer :tcell_instrument_auth_frameworks, :after => :load_config_initializers do |_app|
26
+ next unless TCellAgent.configuration.should_instrument?
27
+
28
+ require 'tcell_agent/devise'
29
+ require 'tcell_agent/rails/auth/devise'
30
+ require 'tcell_agent/authlogic'
31
+ require 'tcell_agent/rails/auth/authlogic'
32
+ require 'tcell_agent/rails/auth/doorkeeper'
33
+ end
19
34
 
20
- else
21
- module TCellAgent
22
- class MyRailtie < Rails::Railtie
23
- initializer 'activeservice.autoload', :after => :set_autoload_paths do |_app|
24
- Rails.application.config.to_prepare do
25
- require 'tcell_agent/devise' if defined?(Devise)
26
- require 'tcell_agent/rails/auth/devise' if defined?(Devise)
27
- require 'tcell_agent/authlogic' if defined?(Authlogic)
28
- require 'tcell_agent/rails/auth/authlogic' if defined?(Authlogic)
29
- require 'tcell_agent/rails/auth/doorkeeper'
30
- end
31
-
32
- # TODO: will this get run ever?
33
- if TCellAgent.configuration.enabled
34
- Rails.application.config.after_initialize do
35
- TCellAgent::Instrumentation::Rails.send_settings(Rails.application)
36
- end
37
- end
38
- end
35
+ initializer :tcell_insert_middleware, :before => :build_middleware_stack do |app|
36
+ app.config.middleware.insert_before(0, TCellAgent::Instrumentation::Rails::Middleware::ContextMiddleware)
37
+ app.config.middleware.insert_after(0, TCellAgent::Instrumentation::Rails::Middleware::HeadersMiddleware)
38
+ app.config.middleware.use TCellAgent::Instrumentation::Rails::Middleware::BodyFilterMiddleware
39
+ app.config.middleware.use TCellAgent::Instrumentation::Rails::Middleware::GlobalMiddleware
39
40
  end
40
41
  end
41
42
  end
@@ -1,7 +1,7 @@
1
- require 'tcell_agent/configuration'
2
1
  require 'tcell_agent/patches'
3
2
  require 'tcell_agent/rails/routes/grape'
4
3
  require 'tcell_agent/rails/routes/route_id'
4
+ require 'tcell_agent/rails/dlp/process_request'
5
5
 
6
6
  require 'json'
7
7
 
@@ -84,6 +84,8 @@ module TCellAgent
84
84
  end
85
85
 
86
86
  def self.instrument_routes
87
+ return unless TCellAgent.configuration.should_instrument?
88
+
87
89
  return unless ::Rails.application
88
90
 
89
91
  ::Rails.application.routes.routes.each do |route|
@@ -92,7 +94,7 @@ module TCellAgent
92
94
  end
93
95
 
94
96
  def self.instrument_route(route)
95
- return unless TCellAgent.configuration.enabled && TCellAgent.configuration.should_instrument?
97
+ return unless TCellAgent.configuration.should_instrument?
96
98
 
97
99
  tcell_route = create_tcell_route(route)
98
100
 
@@ -134,8 +136,7 @@ module TCellAgent
134
136
  prepend_around_filter :tcell_around_filter_routes
135
137
  end
136
138
  def tcell_around_filter_routes
137
- if TCellAgent.configuration.enabled &&
138
- TCellAgent.configuration.should_instrument? &&
139
+ if TCellAgent.configuration.should_instrument? &&
139
140
  TCellAgent.configuration.should_intercept_requests?
140
141
  TCellAgent::Instrumentation.safe_block('Determining Rails Route ID') do
141
142
  _match, parameters, route = ::Rails.application.routes.router.recognize(request) { |r, _| r }.first
@@ -191,7 +192,7 @@ module TCellAgent
191
192
  ActionDispatch::Journey::Router.class_eval do
192
193
  alias_method :tcell_serve, :serve
193
194
  def serve(req)
194
- if TCellAgent.configuration.enabled && TCellAgent.configuration.should_instrument? &&
195
+ if TCellAgent.configuration.should_instrument? &&
195
196
  TCellAgent.configuration.should_intercept_requests?
196
197
  TCellAgent::Instrumentation.safe_block('Determining Rails Route ID') do
197
198
  _match, parameters, route = find_routes(req).first
@@ -219,7 +220,7 @@ module TCellAgent
219
220
  def call(env)
220
221
  env['PATH_INFO'] = ActionDispatch::Journey::Router::Utils.normalize_path(env['PATH_INFO'])
221
222
 
222
- if TCellAgent.configuration.enabled && TCellAgent.configuration.should_instrument? &&
223
+ if TCellAgent.configuration.should_instrument? &&
223
224
  TCellAgent.configuration.should_intercept_requests?
224
225
  TCellAgent::Instrumentation.safe_block('Determining Rails Route ID') do
225
226
  _match, parameters, route = find_routes(env).first
@@ -76,8 +76,7 @@ module TCellAgent
76
76
  Grape::Endpoint.class_eval do
77
77
  alias_method :tcell_call!, :call!
78
78
  def call!(env)
79
- if TCellAgent.configuration.enabled &&
80
- TCellAgent.configuration.should_instrument? &&
79
+ if TCellAgent.configuration.should_instrument? &&
81
80
  TCellAgent.configuration.should_intercept_requests?
82
81
 
83
82
  TCellAgent::Instrumentation.safe_block('Determining Rails Route ID') do
@@ -102,7 +101,6 @@ module TCellAgent
102
101
  tcell_call!(env)
103
102
  end
104
103
  end
105
-
106
104
  end
107
105
  end
108
106
  end
@@ -16,7 +16,9 @@ module TCellAgent
16
16
  tcell_context.grape_mount_endpoint = grape_mount_endpoint
17
17
 
18
18
  else
19
- tcell_context.route_id = TCellAgent::SensorEvents::Util.calculate_route_id(tcell_context.request_method, route_path)
19
+ tcell_context.route_id = TCellAgent::SensorEvents::Util.calculate_route_id(
20
+ tcell_context.request_method, route_path
21
+ )
20
22
  end
21
23
  end
22
24
  end
@@ -1,15 +1,12 @@
1
1
  require 'rails'
2
2
  require 'tcell_agent'
3
- require 'tcell_agent/sensor_events/app_config'
3
+ require 'tcell_agent/sensor_events/app_config_setting_event'
4
4
  require 'tcell_agent/sensor_events/server_agent'
5
- require 'tcell_agent/system_info'
6
5
 
7
6
  module TCellAgent
8
7
  module Instrumentation
9
8
  module Rails
10
9
  def self.send_framework_info
11
- return unless TCellAgent.configuration.exp_config_settings
12
-
13
10
  TCellAgent.send_event(
14
11
  TCellAgent::SensorEvents::ServerAgentAppFrameworkEvent.new(
15
12
  'Rails', ::Rails.version
@@ -17,44 +14,34 @@ module TCellAgent
17
14
  )
18
15
  end
19
16
 
20
- def self.send_language_info
21
- return unless TCellAgent.configuration.exp_config_settings
17
+ def self.send_settings
18
+ TCellAgent::Instrumentation.safe_block('Reporting Rails settings') do
19
+ rails_config = ::Rails.application.config
22
20
 
23
- language = TCellAgent::SystemInfo.get_language
24
- language_version = TCellAgent::SystemInfo.get_language_version
25
- TCellAgent.send_event(
26
- TCellAgent::SensorEvents::ServerAgentDetailsLanguageEvent.new(
27
- language, language_version
21
+ # Defaults to true
22
+ csrf_protection = rails_config.action_controller.allow_forgery_protection || true
23
+ TCellAgent.send_event(
24
+ TCellAgent::SensorEvents::AppConfigSettingEvent.new(
25
+ 'Rails', 'core', '', 'csrf_protection', csrf_protection
26
+ )
28
27
  )
29
- )
30
- end
31
28
 
32
- def self.send_settings(application)
33
- return unless TCellAgent.configuration.exp_config_settings
34
-
35
- # Defaults to true
36
- csrf_protection = application.config.action_controller.allow_forgery_protection || true
37
- TCellAgent.send_event(
38
- TCellAgent::SensorEvents::AppConfigSettingEvent.new(
39
- 'Rails', 'core', '', 'csrf_protection', csrf_protection
29
+ # Defaults to false if nil
30
+ mass_assignment_allowed = rails_config.action_controller.permit_all_parameters || false
31
+ TCellAgent.send_event(
32
+ TCellAgent::SensorEvents::AppConfigSettingEvent.new(
33
+ 'Rails', 'core', '', 'mass_assignment_allowed', mass_assignment_allowed
34
+ )
40
35
  )
41
- )
42
36
 
43
- # Defaults to false if nil
44
- mass_assignment_allowed = application.config.action_controller.permit_all_parameters || false
45
- TCellAgent.send_event(
46
- TCellAgent::SensorEvents::AppConfigSettingEvent.new(
47
- 'Rails', 'core', '', 'mass_assignment_allowed', mass_assignment_allowed
48
- )
49
- )
50
-
51
- # Defaults to never
52
- session_expire = application.config.session_options[:expire_after] || -1
53
- TCellAgent.send_event(
54
- TCellAgent::SensorEvents::AppConfigSettingEvent.new(
55
- 'Rails', 'session', '', 'timeout', session_expire
37
+ # Defaults to never
38
+ session_expire = rails_config.session_options[:expire_after] || -1
39
+ TCellAgent.send_event(
40
+ TCellAgent::SensorEvents::AppConfigSettingEvent.new(
41
+ 'Rails', 'session', '', 'timeout', session_expire
42
+ )
56
43
  )
57
- )
44
+ end
58
45
  end
59
46
  end
60
47
  end
@@ -0,0 +1,12 @@
1
+ module TCellAgent
2
+ class TCellAgentStartupRailtie < Rails::Railtie
3
+ # TCellAgent config can be specified thru Rails initializer's
4
+ # (https://guides.rubyonrails.org/v2.3/configuring.html#using-initializers)
5
+ # so those need to run first before the agent is started
6
+ initializer :start_tcell_agent,
7
+ :after => :load_config_initializers,
8
+ :before => :tcell_instrument_auth_frameworks do |_app|
9
+ TCellAgent.thread_agent.start('Unicorn')
10
+ end
11
+ end
12
+ end
@@ -4,7 +4,7 @@ module TCellAgent
4
4
  module Instrumentation
5
5
  module Rails
6
6
  class TCellBodyProxy
7
- attr_accessor :appsensor_meta_event
7
+ attr_accessor :meta_data
8
8
 
9
9
  # for specs
10
10
  attr_accessor :content_length
@@ -29,9 +29,11 @@ module TCellAgent
29
29
 
30
30
  def close
31
31
  TCellAgent::Instrumentation.safe_block('Running AppSensor deferred due to streaming') do
32
- if @appsensor_meta_event
33
- @appsensor_meta_event.meta_data.response_content_bytes_len = @content_length
34
- TCellAgent.send_event(@appsensor_meta_event)
32
+ if @meta_data
33
+ @meta_data.response_content_bytes_len = @content_length
34
+
35
+ appfirewall_policy = TCellAgent.policy(TCellAgent::PolicyTypes::APPSENSOR)
36
+ appfirewall_policy.check_appfirewall_injections(@meta_data)
35
37
  end
36
38
  end
37
39
 
@@ -0,0 +1,49 @@
1
+ require 'tcell_agent/version'
2
+
3
+ module TCellAgent
4
+ module Rust
5
+ class AgentConfig < Hash
6
+ def initialize(configuration)
7
+ send_mode = 'Normal'
8
+ send_mode = 'Demo' if configuration.demomode
9
+
10
+ logging_options = configuration.clean_logging_options
11
+ unless configuration.js_agent_api_base_url
12
+ parsed_uri = URI.parse(configuration.tcell_api_url)
13
+ api_url = [parsed_uri.scheme, '://', parsed_uri.host]
14
+ api_url.push(":#{parsed_uri.port}") unless [80, 443].include?(parsed_uri.port)
15
+ configuration.js_agent_api_base_url = "#{api_url.join('')}/api/v1"
16
+ end
17
+
18
+ self['disable_event_sending'] = !configuration.should_start_event_manager?
19
+ self['send_mode'] = send_mode
20
+ self['agent_type'] = 'Ruby'
21
+ self['agent_version'] = TCellAgent::VERSION
22
+ self['diagnostics_enabled'] = false
23
+ self['application'] = {
24
+ :app_id => configuration.app_id,
25
+ :api_key => configuration.api_key,
26
+ :tcell_api_url => configuration.tcell_api_url,
27
+ :tcell_input_url => configuration.tcell_input_url,
28
+ :hmac_key => configuration.hmac_key,
29
+ :password_hmac_key => configuration.password_hmac_key,
30
+ :allow_payloads => configuration.allow_payloads,
31
+ :js_agent_api_base_url => configuration.js_agent_api_base_url,
32
+ :js_agent_url => configuration.js_agent_url,
33
+ :cache_dir => configuration.cache_folder,
34
+ :log_dir => configuration.agent_log_dir,
35
+ :logging_options => logging_options,
36
+ :host_identifier => configuration.host_identifier,
37
+ :reverse_proxy_ip_address_header => configuration.reverse_proxy_ip_address_header,
38
+ :fetch_policies_from_tcell => configuration.should_start_policy_poll?,
39
+ :preload_policy_filename => configuration.preload_policy_filename
40
+ }
41
+ self['appfirewall'] = {
42
+ :enable_body_json_inspection => true,
43
+ :allow_log_payloads => true
44
+ }
45
+ self['max_header_size'] = configuration.max_csp_header_bytes || (1024 * 1024)
46
+ end
47
+ end
48
+ end
49
+ end
@@ -13,61 +13,6 @@ module TCellAgent
13
13
 
14
14
  flattened_params
15
15
  end
16
-
17
- def self.create_request_response(appsensor_meta)
18
- post_params = convert_params(appsensor_meta.flattened_post_dict)
19
-
20
- request_response = {
21
- 'method' => appsensor_meta.method,
22
- 'status_code' => appsensor_meta.response_code.to_i,
23
- 'route_id' => appsensor_meta.route_id,
24
- 'path' => appsensor_meta.path,
25
- 'query_params' => convert_params(appsensor_meta.flattened_get_dict),
26
- 'post_params' => post_params,
27
- 'headers' => convert_params(appsensor_meta.flattened_headers_dict),
28
- 'cookies' => convert_params(appsensor_meta.flattened_cookie_dict),
29
- 'path_params' => convert_params(appsensor_meta.flattened_path_parameters),
30
- 'remote_address' => appsensor_meta.remote_address,
31
- 'full_uri' => appsensor_meta.location,
32
- 'session_id' => appsensor_meta.session_id,
33
- 'user_id' => appsensor_meta.user_id,
34
- 'user_agent' => appsensor_meta.user_agent,
35
- :content_type => appsensor_meta.content_type,
36
- :request_body => appsensor_meta.raw_request_body,
37
- 'request_bytes_length' => appsensor_meta.request_content_bytes_len,
38
- 'response_bytes_length' => appsensor_meta.response_content_bytes_len
39
- }
40
-
41
- if TCellAgent::Utils::Strings.present?(appsensor_meta.csrf_exception_name)
42
- request_response['csrf_exception'] = { 'exception_name' => appsensor_meta.csrf_exception_name }
43
- end
44
-
45
- if appsensor_meta.sql_exceptions
46
- request_response['sql_exceptions'] = appsensor_meta.sql_exceptions
47
- end
48
-
49
- if appsensor_meta.database_result_sizes
50
- request_response['database_result_sizes'] = appsensor_meta.database_result_sizes
51
- end
52
-
53
- request_response
54
- end
55
-
56
- def self.create_patches_request(appsensor_meta)
57
- post_params = convert_params(appsensor_meta.flattened_post_dict)
58
-
59
- {
60
- 'method' => appsensor_meta.method,
61
- 'path' => appsensor_meta.path,
62
- 'remote_address' => appsensor_meta.remote_address,
63
- 'request_bytes_length' => appsensor_meta.request_content_bytes_len,
64
- 'query_params' => convert_params(appsensor_meta.flattened_get_dict),
65
- 'post_params' => post_params,
66
- 'headers' => convert_params(appsensor_meta.flattened_headers_dict),
67
- 'cookies' => convert_params(appsensor_meta.flattened_cookie_dict),
68
- :content_type => appsensor_meta.content_type
69
- }
70
- end
71
16
  end
72
17
  end
73
18
  end