tcell_agent 2.1.2 → 2.4.1

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 (110) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE +2 -2
  3. data/bin/tcell_agent +41 -150
  4. data/lib/tcell_agent.rb +8 -16
  5. data/lib/tcell_agent/agent.rb +87 -52
  6. data/lib/tcell_agent/config_initializer.rb +62 -0
  7. data/lib/tcell_agent/configuration.rb +72 -267
  8. data/lib/tcell_agent/hooks/login_fraud.rb +1 -1
  9. data/lib/tcell_agent/instrument_servers.rb +14 -18
  10. data/lib/tcell_agent/instrumentation.rb +14 -6
  11. data/lib/tcell_agent/instrumentation/cmdi.rb +32 -0
  12. data/lib/tcell_agent/instrumentation/lfi.rb +55 -9
  13. data/lib/tcell_agent/instrumentation/monkey_patches/ruby_2/file.rb +21 -0
  14. data/lib/tcell_agent/instrumentation/monkey_patches/ruby_2/io.rb +75 -0
  15. data/lib/tcell_agent/instrumentation/monkey_patches/ruby_2/kernel.rb +80 -0
  16. data/lib/tcell_agent/instrumentation/monkey_patches/ruby_3/file.rb +21 -0
  17. data/lib/tcell_agent/instrumentation/monkey_patches/ruby_3/io.rb +75 -0
  18. data/lib/tcell_agent/instrumentation/monkey_patches/ruby_3/kernel.rb +80 -0
  19. data/lib/tcell_agent/logger.rb +3 -4
  20. data/lib/tcell_agent/policies/dataloss_policy.rb +15 -8
  21. data/lib/tcell_agent/policies/headers_policy.rb +2 -2
  22. data/lib/tcell_agent/policies/patches_policy.rb +8 -4
  23. data/lib/tcell_agent/policies/policies_manager.rb +1 -0
  24. data/lib/tcell_agent/policies/policy_polling.rb +4 -3
  25. data/lib/tcell_agent/rails/auth/authlogic.rb +49 -44
  26. data/lib/tcell_agent/rails/auth/authlogic_helper.rb +20 -0
  27. data/lib/tcell_agent/rails/auth/devise.rb +103 -102
  28. data/lib/tcell_agent/rails/auth/devise_helper.rb +29 -0
  29. data/lib/tcell_agent/rails/auth/doorkeeper.rb +54 -57
  30. data/lib/tcell_agent/{userinfo.rb → rails/auth/userinfo.rb} +0 -0
  31. data/lib/tcell_agent/rails/better_ip.rb +7 -19
  32. data/lib/tcell_agent/rails/csrf_exception.rb +0 -8
  33. data/lib/tcell_agent/rails/dlp.rb +48 -52
  34. data/lib/tcell_agent/rails/dlp/process_request.rb +5 -0
  35. data/lib/tcell_agent/rails/dlp_handler.rb +9 -10
  36. data/lib/tcell_agent/rails/js_agent_insert.rb +2 -3
  37. data/lib/tcell_agent/rails/middleware/context_middleware.rb +2 -1
  38. data/lib/tcell_agent/rails/middleware/global_middleware.rb +3 -4
  39. data/lib/tcell_agent/rails/middleware/headers_middleware.rb +1 -0
  40. data/lib/tcell_agent/rails/{on_start.rb → railties/tcell_agent_railties.rb} +9 -16
  41. data/lib/tcell_agent/rails/railties/tcell_agent_unicorn_railties.rb +8 -0
  42. data/lib/tcell_agent/rails/routes.rb +3 -6
  43. data/lib/tcell_agent/rails/routes/grape.rb +3 -4
  44. data/lib/tcell_agent/rails/settings_reporter.rb +3 -6
  45. data/lib/tcell_agent/rails/tcell_body_proxy.rb +4 -7
  46. data/lib/tcell_agent/routes/table.rb +3 -0
  47. data/lib/tcell_agent/rust/agent_config.rb +59 -33
  48. data/lib/tcell_agent/rust/{libtcellagent-4.18.0.so → libtcellagent-alpine.so} +0 -0
  49. data/lib/tcell_agent/rust/libtcellagent-x64.dll +0 -0
  50. data/lib/tcell_agent/rust/{libtcellagent-4.18.0.dylib → libtcellagent.dylib} +0 -0
  51. data/lib/tcell_agent/rust/{libtcellagent-alpine-4.18.0.so → libtcellagent.so} +0 -0
  52. data/lib/tcell_agent/rust/models.rb +9 -0
  53. data/lib/tcell_agent/rust/native_agent.rb +58 -50
  54. data/lib/tcell_agent/rust/native_library.rb +8 -10
  55. data/lib/tcell_agent/sensor_events/server_agent.rb +3 -100
  56. data/lib/tcell_agent/sensor_events/util/sanitizer_utilities.rb +1 -0
  57. data/lib/tcell_agent/servers/puma.rb +30 -13
  58. data/lib/tcell_agent/servers/rack_puma_handler.rb +33 -0
  59. data/lib/tcell_agent/servers/rails_server.rb +4 -4
  60. data/lib/tcell_agent/servers/unicorn.rb +1 -1
  61. data/lib/tcell_agent/servers/webrick.rb +12 -3
  62. data/lib/tcell_agent/settings_reporter.rb +0 -93
  63. data/lib/tcell_agent/sinatra.rb +1 -0
  64. data/lib/tcell_agent/tcell_context.rb +16 -7
  65. data/lib/tcell_agent/utils/headers.rb +0 -1
  66. data/lib/tcell_agent/utils/strings.rb +2 -2
  67. data/lib/tcell_agent/version.rb +1 -1
  68. data/spec/cruby_spec_helper.rb +26 -0
  69. data/spec/lib/tcell_agent/configuration_spec.rb +62 -212
  70. data/spec/lib/tcell_agent/instrument_servers_spec.rb +95 -0
  71. data/spec/lib/tcell_agent/instrumentation/cmdi/io_cmdi_spec.rb +2 -2
  72. data/spec/lib/tcell_agent/instrumentation/lfi/file_lfi_spec.rb +211 -272
  73. data/spec/lib/tcell_agent/instrumentation/lfi/io_lfi_spec.rb +207 -223
  74. data/spec/lib/tcell_agent/instrumentation/lfi/kernel_lfi_spec.rb +89 -70
  75. data/spec/lib/tcell_agent/instrumentation/lfi_spec.rb +73 -0
  76. data/spec/lib/tcell_agent/patches_spec.rb +2 -1
  77. data/spec/lib/tcell_agent/policies/clickjacking_policy_spec.rb +1 -2
  78. data/spec/lib/tcell_agent/policies/content_security_policy_spec.rb +5 -6
  79. data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +21 -2
  80. data/spec/lib/tcell_agent/policies/policies_manager_spec.rb +1 -1
  81. data/spec/lib/tcell_agent/policies/secure_headers_policy_spec.rb +14 -8
  82. data/spec/lib/tcell_agent/rails/better_ip_spec.rb +9 -11
  83. data/spec/lib/tcell_agent/rails/csrf_exception_spec.rb +6 -6
  84. data/spec/lib/tcell_agent/rails/dlp_spec.rb +1 -0
  85. data/spec/lib/tcell_agent/rails/js_agent_insert_spec.rb +10 -2
  86. data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +2 -1
  87. data/spec/lib/tcell_agent/rails/routes/route_id_spec.rb +4 -4
  88. data/spec/lib/tcell_agent/rust/agent_config_spec.rb +27 -0
  89. data/spec/lib/tcell_agent/settings_reporter_spec.rb +2 -89
  90. data/spec/lib/tcell_agent/tcell_context_spec.rb +6 -5
  91. data/spec/spec_helper.rb +9 -1
  92. data/spec/support/builders.rb +8 -7
  93. data/spec/support/server_mocks/passenger_mock.rb +7 -0
  94. data/spec/support/server_mocks/puma_mock.rb +21 -0
  95. data/spec/support/server_mocks/rails_mock.rb +7 -0
  96. data/spec/support/server_mocks/thin_mock.rb +7 -0
  97. data/spec/support/server_mocks/unicorn_mock.rb +11 -0
  98. data/spec/support/shared_spec.rb +29 -0
  99. data/tcell_agent.gemspec +14 -14
  100. metadata +44 -27
  101. data/Rakefile +0 -18
  102. data/lib/tcell_agent/authlogic.rb +0 -23
  103. data/lib/tcell_agent/config/unknown_options.rb +0 -119
  104. data/lib/tcell_agent/devise.rb +0 -33
  105. data/lib/tcell_agent/instrumentation/monkey_patches/file.rb +0 -25
  106. data/lib/tcell_agent/instrumentation/monkey_patches/io.rb +0 -131
  107. data/lib/tcell_agent/instrumentation/monkey_patches/kernel.rb +0 -102
  108. data/lib/tcell_agent/rails/start_agent_after_initializers.rb +0 -12
  109. data/lib/tcell_agent/rust/tcellagent-4.18.0.dll +0 -0
  110. data/spec/lib/tcell_agent/config/unknown_options_spec.rb +0 -195
@@ -1,127 +1,128 @@
1
- if TCellAgent.configuration.should_instrument_devise? && defined?(Devise)
2
- module TCellAgent
3
- require 'base64'
4
- require 'tcell_agent/agent'
5
-
6
- module DeviseInstrumentation
7
- module TCellFailureAppRespond
8
- def respond
9
- TCellAgent::Instrumentation.safe_block('Devise Failure App Respond') do
10
- if TCellAgent.configuration.should_intercept_requests?
11
- tcell_data = request.env[TCellAgent::Instrumentation::TCELL_ID]
12
- if tcell_data
13
- # in the case of http auth, user_id is set in
14
- # Devise::Strategies::Authenticatable.valid_for_http_auth?
15
- user_id = tcell_data.user_id
16
- user_id ||= _get_tcell_username
17
-
18
- # in the case of http auth, password is set in
19
- # Devise::Strategies::Authenticatable.valid_for_http_auth?
20
- password = tcell_data.password
21
- password ||= _get_tcell_password
22
-
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
- )
32
- end
1
+ module TCellAgent
2
+ require 'base64'
3
+ require 'tcell_agent/agent'
4
+
5
+ module DeviseInstrumentation
6
+ module TCellFailureAppRespond
7
+ def respond
8
+ TCellAgent::Instrumentation.safe_block('Devise Failure App Respond') do
9
+ if TCellAgent.configuration.should_intercept_requests?
10
+ tcell_data = request.env[TCellAgent::Instrumentation::TCELL_ID]
11
+ if tcell_data
12
+ # in the case of http auth, user_id is set in
13
+ # Devise::Strategies::Authenticatable.valid_for_http_auth?
14
+ user_id = tcell_data.user_id
15
+ user_id ||= _get_tcell_username
16
+
17
+ # in the case of http auth, password is set in
18
+ # Devise::Strategies::Authenticatable.valid_for_http_auth?
19
+ password = tcell_data.password
20
+ password ||= _get_tcell_password
21
+
22
+ user_valid = warden_message != :not_found_in_database if defined?(warden_message)
23
+
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
+ )
33
32
  end
34
33
  end
35
-
36
- super if defined?(super)
37
34
  end
38
35
 
39
- def _get_tcell_username
40
- tcell_username = nil
41
- TCellAgent::Instrumentation.safe_block('Devise Get TCell Username') do
42
- keys = scope_class.authentication_keys.dup
43
- user_params = request.POST.fetch('user', {})
44
- keys.each do |key|
45
- next_usename = user_params.fetch(key, nil)
46
- if next_usename
47
- tcell_username ||= ''
48
- tcell_username += next_usename
49
- end
36
+ super if defined?(super)
37
+ end
38
+
39
+ def _get_tcell_username
40
+ tcell_username = nil
41
+ TCellAgent::Instrumentation.safe_block('Devise Get TCell Username') do
42
+ keys = scope_class.authentication_keys.dup
43
+ user_params = request.POST.fetch('user', {})
44
+ keys.each do |key|
45
+ next_usename = user_params.fetch(key, nil)
46
+ if next_usename
47
+ tcell_username ||= ''
48
+ tcell_username += next_usename
50
49
  end
51
50
  end
52
- tcell_username
53
51
  end
52
+ tcell_username
53
+ end
54
54
 
55
- def _get_tcell_password
56
- tcell_password = nil
57
- TCellAgent::Instrumentation.safe_block('Devise Get TCell Password') do
58
- user_params = request.POST.fetch('user', {})
59
- tcell_password = user_params['password']
60
- end
61
- tcell_password
55
+ def _get_tcell_password
56
+ tcell_password = nil
57
+ TCellAgent::Instrumentation.safe_block('Devise Get TCell Password') do
58
+ user_params = request.POST.fetch('user', {})
59
+ tcell_password = user_params['password']
62
60
  end
61
+ tcell_password
63
62
  end
64
63
  end
64
+ end
65
65
 
66
- # prepend is ruby 2+ feature
67
- Devise::FailureApp.send(:prepend, DeviseInstrumentation::TCellFailureAppRespond)
66
+ # prepend is ruby 2+ feature
67
+ Devise::FailureApp.send(:prepend, DeviseInstrumentation::TCellFailureAppRespond)
68
+
69
+ Devise::Strategies::Authenticatable.class_eval do
70
+ alias_method :tcell_valid_for_http_auth?, :valid_for_http_auth?
71
+ def valid_for_http_auth?
72
+ is_valid = tcell_valid_for_http_auth?
73
+
74
+ TCellAgent::Instrumentation.safe_block('Devise set username for http basic auth') do
75
+ tcell_data = request.env[TCellAgent::Instrumentation::TCELL_ID]
76
+ if http_auth_hash && tcell_data
77
+ username = http_auth_hash[http_authentication_key]
78
+ password = http_auth_hash[:password]
79
+ tcell_data.user_id = username if username && !tcell_data.user_id
80
+ tcell_data.password = password if password && !tcell_data.password
81
+ end
82
+ end
68
83
 
69
- Devise::Strategies::Authenticatable.class_eval do
70
- alias_method :tcell_valid_for_http_auth?, :valid_for_http_auth?
71
- def valid_for_http_auth?
72
- is_valid = tcell_valid_for_http_auth?
84
+ is_valid
85
+ end
73
86
 
74
- TCellAgent::Instrumentation.safe_block('Devise set username for http basic auth') do
75
- tcell_data = request.env[TCellAgent::Instrumentation::TCELL_ID]
76
- if http_auth_hash && tcell_data
77
- username = http_auth_hash[http_authentication_key]
78
- password = http_auth_hash[:password]
79
- tcell_data.user_id = username if username && !tcell_data.user_id
80
- tcell_data.password = password if password && !tcell_data.password
81
- end
82
- end
87
+ alias_method :tcell_validate, :validate
88
+ def validate(resource, &block)
89
+ is_valid = tcell_validate(resource, &block)
90
+ send_event = is_valid
83
91
 
84
- is_valid
92
+ # gets the first entry in the current backtrace
93
+ # syntax suggested by rubocop to improve performance
94
+ if caller(1..1).first.include? 'two_factor_authenticatable'
95
+ TCellAgent.logger.debug('Not sending login success event for Devise::Strategies::TwoFactorAuthenticatable since 2fa is unsupported', 'TCellAgent::DeviseInstrumentation')
96
+ send_event = false
85
97
  end
86
98
 
87
- alias_method :tcell_validate, :validate
88
- def validate(resource, &block)
89
- is_valid = tcell_validate(resource, &block)
90
- send_event = is_valid
91
-
92
- # gets the first entry in the current backtrace
93
- # syntax suggested by rubocop to improve performance
94
- if caller(1..1).first.include? 'two_factor_authenticatable'
95
- TCellAgent.logger.debug('Not sending login success event for Devise::Strategies::TwoFactorAuthenticatable since 2fa is unsupported', 'TCellAgent::DeviseInstrumentation')
96
- send_event = false
97
- end
99
+ TCellAgent::Instrumentation.safe_block('Devise Authenticatable Validate') do
100
+ if send_event && TCellAgent.configuration.should_intercept_requests?
101
+ username = nil
102
+ (authentication_keys || []).each do |auth_key|
103
+ attr = authentication_hash[auth_key] unless authentication_hash.nil?
98
104
 
99
- TCellAgent::Instrumentation.safe_block('Devise Authenticatable Validate') do
100
- if send_event && TCellAgent.configuration.enabled &&
101
- TCellAgent.configuration.should_intercept_requests?
102
- username = nil
103
- (authentication_keys || []).each do |auth_key|
104
- attr = authentication_hash[auth_key]
105
- if attr
106
- username ||= ''
107
- username += attr
108
- end
105
+ if attr
106
+ username ||= ''
107
+ username += attr
109
108
  end
110
-
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
- )
120
109
  end
121
- end
122
110
 
123
- is_valid
111
+ tcell_data = request.env[TCellAgent::Instrumentation::TCELL_ID]
112
+ return is_valid unless tcell_data
113
+
114
+ tcell_data.user_id = username if username && tcell_data.user_id.nil?
115
+
116
+ login_policy = TCellAgent.policy(TCellAgent::PolicyTypes::LOGINFRAUD)
117
+ login_policy.report_login_success(
118
+ username,
119
+ request.env,
120
+ tcell_data
121
+ )
122
+ end
124
123
  end
124
+
125
+ is_valid
125
126
  end
126
127
  end
127
128
  end
@@ -0,0 +1,29 @@
1
+ require 'devise'
2
+ require 'devise/rails'
3
+ require 'devise/strategies/database_authenticatable'
4
+ require 'tcell_agent/rails/auth/userinfo'
5
+
6
+ module TCellAgent
7
+ TCellAgent::UserInformation.class_eval do
8
+ class << self
9
+ alias_method :original_get_user_from_request, :get_user_from_request
10
+ def get_user_from_request(request)
11
+ orig_user_id = original_get_user_from_request(request)
12
+ begin
13
+ if request.session && request.session.key?('warden.user.user.key')
14
+ userkey = request.session['warden.user.user.key']
15
+ user_id = if userkey.length == 2
16
+ userkey[0][0]
17
+ else
18
+ userkey[1][0]
19
+ end
20
+ return user_id.to_s if user_id.is_a? Integer
21
+ end
22
+ rescue StandardError
23
+ return orig_user_id
24
+ end
25
+ orig_user_id
26
+ end
27
+ end
28
+ end
29
+ end
@@ -1,65 +1,32 @@
1
- if TCellAgent.configuration.should_instrument_doorkeeper? && defined?(Doorkeeper)
1
+ require 'tcell_agent/agent'
2
2
 
3
- require 'tcell_agent/agent'
4
- require 'tcell_agent/sensor_events/login_fraud'
3
+ module TCellAgent
4
+ module DoorkeeperInstrumentation
5
+ Doorkeeper::TokensController.class_eval do
6
+ alias_method :tcell_authorize_response, :authorize_response
7
+ def authorize_response
8
+ result = tcell_authorize_response
5
9
 
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
10
+ TCellAgent::Instrumentation.safe_block('Doorkeeper Token Authorize') do
11
+ return result unless TCellAgent.configuration.should_intercept_requests?
12
12
 
13
- TCellAgent::Instrumentation.safe_block('Doorkeeper Token Authorize') do
14
- return result unless TCellAgent.configuration.should_intercept_requests?
13
+ login_policy = TCellAgent.policy(TCellAgent::PolicyTypes::LOGINFRAUD)
14
+ tcell_data = request.env[TCellAgent::Instrumentation::TCELL_ID]
15
15
 
16
- login_policy = TCellAgent.policy(TCellAgent::PolicyTypes::LOGINFRAUD)
17
- tcell_data = request.env[TCellAgent::Instrumentation::TCELL_ID]
16
+ return unless tcell_data
18
17
 
19
- return unless tcell_data
20
- headers = request.env
18
+ headers = request.env
21
19
 
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
41
- end
42
-
43
- result
44
- end
45
- end
46
-
47
- module TCellAuthorizationsNew
48
- def new
49
- super if defined?(super)
50
-
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
20
+ if result.is_a?(Doorkeeper::OAuth::TokenResponse)
21
+ user_id = result.token.resource_owner_id
22
+ login_policy.report_login_success(
23
+ user_id,
24
+ headers,
25
+ tcell_data
26
+ )
27
+ elsif result.is_a?(Doorkeeper::OAuth::ErrorResponse)
28
+ user_id = request.POST['client_id']
61
29
  password = nil
62
- headers = request.env
63
30
  user_valid = nil
64
31
  login_policy.report_login_failure(
65
32
  user_id,
@@ -70,10 +37,40 @@ if TCellAgent.configuration.should_instrument_doorkeeper? && defined?(Doorkeeper
70
37
  )
71
38
  end
72
39
  end
40
+
41
+ result
73
42
  end
43
+ end
44
+
45
+ module TCellAuthorizationsNew
46
+ def new
47
+ super if defined?(super)
48
+
49
+ TCellAgent::Instrumentation.safe_block('Doorkeeper Token Authorize') do
50
+ return unless TCellAgent.configuration.should_intercept_requests?
51
+ return unless pre_auth.error
74
52
 
75
- # prepend is ruby 2+ feature
76
- Doorkeeper::AuthorizationsController.send(:prepend, TCellAuthorizationsNew)
53
+ login_policy = TCellAgent.policy(TCellAgent::PolicyTypes::LOGINFRAUD)
54
+ tcell_data = request.env[TCellAgent::Instrumentation::TCELL_ID]
55
+
56
+ return unless tcell_data
57
+
58
+ user_id = current_resource_owner.id
59
+ password = nil
60
+ headers = request.env
61
+ user_valid = nil
62
+ login_policy.report_login_failure(
63
+ user_id,
64
+ password,
65
+ headers,
66
+ user_valid,
67
+ tcell_data
68
+ )
69
+ end
70
+ end
77
71
  end
72
+
73
+ # prepend is ruby 2+ feature
74
+ Doorkeeper::AuthorizationsController.send(:prepend, TCellAuthorizationsNew)
78
75
  end
79
76
  end
@@ -4,28 +4,16 @@ require 'tcell_agent/instrumentation'
4
4
  module TCellAgent
5
5
  module Utils
6
6
  module Rails
7
- def self.better_ip(request)
8
- if TCellAgent.configuration.reverse_proxy
9
- TCellAgent::Instrumentation.safe_block('Extracting reverse proxy IP') do
10
- reverse_proxy_header = TCellAgent.configuration.reverse_proxy_ip_address_header
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
7
+ def self.reverse_proxy_header(request)
8
+ return unless TCellAgent.configuration.reverse_proxy
16
9
 
17
- x_forwarded_for = request.env[reverse_proxy_header]
18
- ip = if TCellAgent::Utils::Strings.present?(x_forwarded_for)
19
- x_forwarded_for.split(',')[0].strip
20
- else
21
- request.ip
22
- end
10
+ TCellAgent::Instrumentation.safe_block('Extracting reverse proxy header') do
11
+ reverse_proxy_header = TCellAgent.configuration.reverse_proxy_ip_address_header
23
12
 
24
- return ip
25
- end
26
- end
13
+ return if reverse_proxy_header.nil? || reverse_proxy_header.empty?
27
14
 
28
- request.ip
15
+ return request.env["HTTP_#{reverse_proxy_header.upcase.tr('-', '_')}"]
16
+ end
29
17
  end
30
18
  end
31
19
  end
@@ -16,12 +16,4 @@ module TCellAgent
16
16
  super if defined?(super)
17
17
  end
18
18
  end
19
-
20
- class MyRailtie < Rails::Railtie
21
- initializer 'tcell.sensors' do |_app|
22
- ActiveSupport.on_load :action_controller do
23
- ActionController::Base.send(:include, TCellAgent::CsrfExceptionReporter)
24
- end
25
- end
26
- end
27
19
  end
@@ -1,8 +1,5 @@
1
1
  # See the file "LICENSE" for the full license governing this code.
2
2
 
3
- require 'tcell_agent/authlogic' if defined?(Authlogic)
4
- require 'tcell_agent/devise' if defined?(Devise)
5
-
6
3
  require 'rails'
7
4
  require 'uri'
8
5
  require 'tcell_agent/agent'
@@ -21,7 +18,6 @@ require 'tcell_agent/rails/settings_reporter'
21
18
 
22
19
  require 'tcell_agent/instrumentation'
23
20
 
24
- require 'tcell_agent/userinfo'
25
21
  require 'cgi'
26
22
  require 'thread'
27
23
 
@@ -84,6 +80,7 @@ module TCellAgent
84
80
  normalized_column_names[namespaced_column_name] = column_name
85
81
 
86
82
  next unless column_name && (!namespace || namespace == table_name)
83
+
87
84
  rules = dlp_policy.get_actions_for_table(
88
85
  database_name,
89
86
  '*',
@@ -194,6 +191,7 @@ module TCellAgent
194
191
  results[0...TCellAgent.configuration.max_data_ex_db_records_per_request].each do |record|
195
192
  column_name_to_rules.each do |column_name, rules|
196
193
  next unless rules
194
+
197
195
  rules.each do |rule|
198
196
  tcell_context.add_response_db_filter(
199
197
  record[column_name.to_sym],
@@ -305,31 +303,29 @@ module TCellAgent
305
303
  def log_enforce(tcell_context, sanitize_string)
306
304
  if TCellAgent.configuration.should_instrument? &&
307
305
  TCellAgent.configuration.should_intercept_requests?
308
- if tcell_context && tcell_context.session_id
309
- session_id_actions = get_actions_for_session_id
310
- if session_id_actions
311
- send_event = false
312
- sanitize_string.gsub!(tcell_context.session_id) do |m|
313
- if session_id_actions.log_redact
314
- send_event = true
315
- m = '[session_id]'
316
- elsif session_id_actions.log_hash
317
- send_event = true
318
- m = '[hash]'
319
- elsif session_id_actions.log_event
320
- send_event = true
321
- end
322
- m
323
- end
324
- if send_event
325
- TCellAgent.send_event(
326
- TCellAgent::SensorEvents::DlpEvent.new(
327
- tcell_context.route_id,
328
- tcell_context.uri,
329
- TCellAgent::SensorEvents::DlpEvent::FOUND_IN_LOG
330
- ).for_framework(TCellAgent::SensorEvents::DlpEvent::FRAMEWORK_VARIABLE_SESSION_ID)
331
- )
306
+ session_id_actions = get_actions_for_session_id
307
+ if tcell_context && tcell_context.session_id && session_id_actions
308
+ send_event = false
309
+ sanitize_string.gsub!(tcell_context.session_id) do |m|
310
+ if session_id_actions.log_redact
311
+ send_event = true
312
+ m = '[session_id]'
313
+ elsif session_id_actions.log_hash
314
+ send_event = true
315
+ m = '[hash]'
316
+ elsif session_id_actions.log_event
317
+ send_event = true
332
318
  end
319
+ m
320
+ end
321
+ if send_event
322
+ TCellAgent.send_event(
323
+ TCellAgent::SensorEvents::DlpEvent.new(
324
+ tcell_context.route_id,
325
+ tcell_context.uri,
326
+ TCellAgent::SensorEvents::DlpEvent::FOUND_IN_LOG
327
+ ).for_framework(TCellAgent::SensorEvents::DlpEvent::FRAMEWORK_VARIABLE_SESSION_ID)
328
+ )
333
329
  end
334
330
  end
335
331
  end
@@ -340,32 +336,32 @@ module TCellAgent
340
336
  def response_body_enforce(tcell_context, sanitize_string)
341
337
  if TCellAgent.configuration.should_instrument? &&
342
338
  TCellAgent.configuration.should_intercept_requests?
343
- if tcell_context && tcell_context.session_id
344
- session_id_actions = get_actions_for_session_id
345
- if session_id_actions
346
- send_event = false
347
- sanitize_string.gsub!(tcell_context.session_id) do |m|
348
- if session_id_actions.body_redact
349
- # m = "[session_id]"
350
- send_event = true
351
- elsif session_id_actions.body_hash
352
- # m = "[hash]"
353
- send_event = true
354
- elsif session_id_actions.body_event
355
- send_event = true
356
- end
357
- m
339
+ session_id_actions = get_actions_for_session_id
340
+ if tcell_context && tcell_context.session_id && session_id_actions
341
+ send_event = false
342
+ sanitize_string.gsub!(tcell_context.session_id) do |m|
343
+ # rubocop:disable Lint/DuplicateBranch
344
+ if session_id_actions.body_redact
345
+ # m = "[session_id]"
346
+ send_event = true
347
+ elsif session_id_actions.body_hash
348
+ # m = "[hash]"
349
+ send_event = true
350
+ elsif session_id_actions.body_event
351
+ send_event = true
358
352
  end
353
+ # rubocop:enable Lint/DuplicateBranch
354
+ m
359
355
  end
360
- if send_event
361
- TCellAgent.send_event(
362
- TCellAgent::SensorEvents::DlpEvent.new(
363
- tcell_context.route_id,
364
- tcell_context.uri,
365
- TCellAgent::SensorEvents::DlpEvent::FOUND_IN_BODY
366
- ).for_framework(TCellAgent::SensorEvents::DlpEvent::FRAMEWORK_VARIABLE_SESSION_ID)
367
- )
368
- end
356
+ end
357
+ if send_event
358
+ TCellAgent.send_event(
359
+ TCellAgent::SensorEvents::DlpEvent.new(
360
+ tcell_context.route_id,
361
+ tcell_context.uri,
362
+ TCellAgent::SensorEvents::DlpEvent::FOUND_IN_BODY
363
+ ).for_framework(TCellAgent::SensorEvents::DlpEvent::FRAMEWORK_VARIABLE_SESSION_ID)
364
+ )
369
365
  end
370
366
  end
371
367