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
@@ -1,133 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module TCellAgent
4
- module SensorEvents
5
- describe Agent do
6
- describe '.increment_session_info' do
7
- context 'when running the parent process' do
8
- it 'should increment the session info' do
9
- expect(TCellAgent::Agent).to receive(:parent_process?).and_return(true)
10
- expect(TCellAgent).to_not receive(:queue_metric)
11
- expect_any_instance_of(SessionsMetric).to receive(:add_session_info).with(
12
- 'hmac_session_id', 'user_id', 'ip_address', 'user_agent'
13
- )
14
- expect_any_instance_of(SessionsMetric).to receive(:flush).and_return(false)
15
- expect(TCellAgent).to_not receive(:send_event)
16
-
17
- TCellAgent.increment_session_info('hmac_session_id', 'user_id', 'ip_address', 'user_agent')
18
- end
19
-
20
- context 'and the session becomes full' do
21
- it 'should increment the session info and send the flush dummy event' do
22
- expect(TCellAgent::Agent).to receive(:parent_process?).and_return(true)
23
- expect(TCellAgent).to_not receive(:queue_metric)
24
- expect_any_instance_of(SessionsMetric).to receive(:add_session_info).with(
25
- 'hmac_session_id', 'user_id', 'ip_address', 'user_agent'
26
- )
27
- expect_any_instance_of(SessionsMetric).to receive(:flush).and_return(true)
28
- expect(TCellAgent).to receive(:send_event).with(
29
- instance_of(TCellAgent::SensorEvents::FlushDummyEvent)
30
- )
31
-
32
- TCellAgent.increment_session_info('hmac_session_id', 'user_id', 'ip_address', 'user_agent')
33
- end
34
- end
35
- end
36
-
37
- context 'when NOT running the parent process' do
38
- it 'should queue the metric' do
39
- expect(TCellAgent::Agent).to receive(:parent_process?).and_return(false)
40
- expect(TCellAgent).to receive(:queue_metric).with(
41
- {
42
- '_type' => 'increment_session_info',
43
- 'hmac_session_id' => 'hmac_session_id',
44
- 'user_id' => 'user_id',
45
- 'ip_address' => 'ip_address',
46
- 'user_agent' => 'user_agent'
47
- }
48
- )
49
- expect_any_instance_of(SessionsMetric).to_not receive(:add_session_info)
50
- expect_any_instance_of(SessionsMetric).to_not receive(:flush)
51
- expect(TCellAgent).to_not receive(:send_event)
52
-
53
- TCellAgent.increment_session_info('hmac_session_id', 'user_id', 'ip_address', 'user_agent')
54
- end
55
- end
56
- end
57
-
58
- describe '.increment_route' do
59
- context 'when running the parent process' do
60
- before(:each) do
61
- TCellAgent.thread_agent.response_time_table = {}
62
- end
63
- after(:each) do
64
- TCellAgent.thread_agent.response_time_table = {}
65
- end
66
-
67
- context 'with a route present' do
68
- it 'should increment the route info' do
69
- expect(TCellAgent::Agent).to receive(:parent_process?).and_return(true)
70
- expect(TCellAgent).to_not receive(:queue_metric)
71
-
72
- TCellAgent.increment_route('/ma_route', 20)
73
-
74
- expect(TCellAgent.thread_agent.response_time_table).to eq(
75
- { '/ma_route' => { 'c' => 1, 'mx' => 20, 'mn' => 20, 't' => 20 } }
76
- )
77
- end
78
- end
79
-
80
- context 'with an empty route' do
81
- it 'should increment the route info' do
82
- expect(TCellAgent::Agent).to receive(:parent_process?).and_return(true)
83
- expect(TCellAgent).to_not receive(:queue_metric)
84
-
85
- TCellAgent.increment_route('', 20)
86
-
87
- expect(TCellAgent.thread_agent.response_time_table).to eq(
88
- { '?' => { 'c' => 1, 'mx' => 20, 'mn' => 20, 't' => 20 } }
89
- )
90
- end
91
- end
92
-
93
- context 'with a nil route' do
94
- it 'should increment the route info' do
95
- expect(TCellAgent::Agent).to receive(:parent_process?).and_return(true)
96
- expect(TCellAgent).to_not receive(:queue_metric)
97
-
98
- TCellAgent.increment_route(nil, 20)
99
-
100
- expect(TCellAgent.thread_agent.response_time_table).to eq(
101
- { '?' => { 'c' => 1, 'mx' => 20, 'mn' => 20, 't' => 20 } }
102
- )
103
- end
104
- end
105
- end
106
-
107
- context 'when NOT running the parent process' do
108
- before(:each) do
109
- TCellAgent.thread_agent.response_time_table = {}
110
- end
111
- after(:each) do
112
- TCellAgent.thread_agent.response_time_table = {}
113
- end
114
-
115
- it 'should queue the metric' do
116
- expect(TCellAgent::Agent).to receive(:parent_process?).and_return(false)
117
- expect(TCellAgent).to receive(:queue_metric).with(
118
- {
119
- '_type' => 'increment_route',
120
- 'route_id' => '/ma_route',
121
- 'response_time' => 20
122
- }
123
- )
124
-
125
- TCellAgent.increment_route('/ma_route', 20)
126
-
127
- expect(TCellAgent.thread_agent.response_time_table).to eq({})
128
- end
129
- end
130
- end
131
- end
132
- end
133
- end
@@ -1,39 +0,0 @@
1
- require 'spec_helper'
2
- require 'addressable/template'
3
-
4
- module TCellAgent
5
- class TCellApi
6
- describe 'successful POST on /user/create' do
7
- it 'should redirect to dashboard' do
8
- tapi = TCellApi.new
9
- TCellAgent.configuration.app_id = 'test-appid'
10
- TCellAgent.configuration.api_key = 'test-apikey'
11
-
12
- def checkreq(_req)
13
- '{"result":{"csp-headers":{"app_id":"testapp-Becwu","policy_id":' \
14
- '"acf60560-4e76-11e5-874c-7d71d425b275","headers":[{"name":"Content-Security-Policy-Report-Only",' \
15
- '"value":"font-src \'none\'; script-src \'self\'; reflected-xss block; ' \
16
- 'style-src \'self\'; connect-src' \
17
- ' \'none\'" ,"report-uri":"http://localhost:3000/csp/cab5e750e66d614bd46fd07a7078db1e74b4f427b2a135b2c96eca684a642707"}]}}}'
18
- end
19
- uri_template =
20
- Addressable::Template.new 'https://api.tcell.io/agents/api/v1/apps/test-appid/policies/latest?type=patches:v1'
21
-
22
- stub_request(:any, uri_template).to_return(
23
- lambda { |request|
24
- {
25
- :body => checkreq(request),
26
- :status => 200,
27
- :headers => { 'Content-Type' => 'application/json' }
28
- }
29
- }
30
- )
31
-
32
- result = tapi.poll_api
33
- TCellAgent.configuration.app_id = nil
34
- TCellAgent.configuration.api_key = nil
35
- expect(result['result']['csp-headers']['app_id']).to eq('testapp-Becwu')
36
- end
37
- end
38
- end
39
- end
@@ -1,187 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module TCellAgent
4
- module AppSensor
5
- describe InjectionsReporter do
6
- describe '.report_and_log' do
7
- context 'with nil events' do
8
- it 'should do nothing' do
9
- expect(TCellAgent).to_not receive(:send_event)
10
- expect(TCellAgent).to_not receive(:logger)
11
-
12
- InjectionsReporter.report_and_log(nil)
13
- end
14
- end
15
-
16
- context 'with empty events' do
17
- it 'should do nothing' do
18
- expect(TCellAgent).to_not receive(:send_event)
19
- expect(TCellAgent).to_not receive(:logger)
20
-
21
- InjectionsReporter.report_and_log([])
22
- end
23
- end
24
-
25
- context 'with one event' do
26
- it 'should send the event' do
27
- events = [
28
- {
29
- 'pattern' => '1',
30
- 'method' => 'request_method',
31
- 'uri' => 'abosolute_uri',
32
- 'parameter' => 'avatar',
33
- 'meta' => { 'l' => 'body' },
34
- 'session_id' => 'session_id',
35
- 'route_id' => 'route_id',
36
- 'detection_point' => 'xss',
37
- 'user_id' => 'user_id'
38
- }
39
- ]
40
-
41
- expect(TCellAgent).to_not receive(:logger)
42
-
43
- expect(TCellAgent).to receive(:send_event).with(
44
- {
45
- 'event_type' => 'as',
46
- 'dp' => 'xss',
47
- 'param' => 'avatar',
48
- 'm' => 'request_method',
49
- 'pattern' => '1',
50
- 'meta' => { 'l' => 'body' },
51
- 'rid' => 'route_id',
52
- 'uri' => 'abosolute_uri',
53
- 'uid' => 'user_id',
54
- 'sid' => 'session_id'
55
- }
56
- )
57
-
58
- InjectionsReporter.report_and_log(events)
59
- end
60
- end
61
-
62
- context 'with one event with full payload' do
63
- it 'should send and log the event' do
64
- events = [
65
- {
66
- 'pattern' => '1',
67
- 'method' => 'request_method',
68
- 'uri' => 'abosolute_uri',
69
- 'parameter' => 'avatar',
70
- 'meta' => { 'l' => 'body' },
71
- 'session_id' => 'session_id',
72
- 'route_id' => 'route_id',
73
- 'detection_point' => 'xss',
74
- 'user_id' => 'user_id',
75
- 'full_payload' => 'full_payload'
76
- }
77
- ]
78
-
79
- logger = double('logger')
80
-
81
- expect(TCellAgent).to receive(:logger).and_return(logger)
82
- expect(logger).to receive(:info).with(/"payload":"full_payload"/)
83
-
84
- expect(TCellAgent).to receive(:send_event).with(
85
- {
86
- 'event_type' => 'as',
87
- 'dp' => 'xss',
88
- 'param' => 'avatar',
89
- 'm' => 'request_method',
90
- 'pattern' => '1',
91
- 'meta' => { 'l' => 'body' },
92
- 'rid' => 'route_id',
93
- 'uri' => 'abosolute_uri',
94
- 'uid' => 'user_id',
95
- 'sid' => 'session_id'
96
- }
97
- )
98
-
99
- InjectionsReporter.report_and_log(events)
100
- end
101
- end
102
-
103
- context 'with one event with payload' do
104
- it 'should send the event' do
105
- events = [
106
- {
107
- 'pattern' => '1',
108
- 'method' => 'request_method',
109
- 'uri' => 'abosolute_uri',
110
- 'parameter' => 'avatar',
111
- 'meta' => { 'l' => 'body' },
112
- 'session_id' => 'session_id',
113
- 'route_id' => 'route_id',
114
- 'detection_point' => 'xss',
115
- 'user_id' => 'user_id',
116
- 'payload' => 'payload'
117
- }
118
- ]
119
-
120
- expect(TCellAgent).to_not receive(:logger)
121
-
122
- expect(TCellAgent).to receive(:send_event).with(
123
- {
124
- 'event_type' => 'as',
125
- 'dp' => 'xss',
126
- 'param' => 'avatar',
127
- 'm' => 'request_method',
128
- 'pattern' => '1',
129
- 'meta' => { 'l' => 'body' },
130
- 'rid' => 'route_id',
131
- 'uri' => 'abosolute_uri',
132
- 'uid' => 'user_id',
133
- 'sid' => 'session_id',
134
- 'payload' => 'payload'
135
- }
136
- )
137
-
138
- InjectionsReporter.report_and_log(events)
139
- end
140
- end
141
-
142
- context 'with one event with payload and full payload' do
143
- it 'should send and log the event' do
144
- events = [
145
- {
146
- 'pattern' => '1',
147
- 'method' => 'request_method',
148
- 'uri' => 'abosolute_uri',
149
- 'parameter' => 'avatar',
150
- 'meta' => { 'l' => 'body' },
151
- 'session_id' => 'session_id',
152
- 'route_id' => 'route_id',
153
- 'detection_point' => 'xss',
154
- 'user_id' => 'user_id',
155
- 'payload' => 'payload',
156
- 'full_payload' => 'full_payload'
157
- }
158
- ]
159
-
160
- logger = double('logger')
161
-
162
- expect(TCellAgent).to receive(:logger).and_return(logger)
163
- expect(logger).to receive(:info).with(/"payload":"full_payload"/)
164
-
165
- expect(TCellAgent).to receive(:send_event).with(
166
- {
167
- 'event_type' => 'as',
168
- 'dp' => 'xss',
169
- 'param' => 'avatar',
170
- 'm' => 'request_method',
171
- 'pattern' => '1',
172
- 'meta' => { 'l' => 'body' },
173
- 'rid' => 'route_id',
174
- 'uri' => 'abosolute_uri',
175
- 'uid' => 'user_id',
176
- 'sid' => 'session_id',
177
- 'payload' => 'payload'
178
- }
179
- )
180
-
181
- InjectionsReporter.report_and_log(events)
182
- end
183
- end
184
- end
185
- end
186
- end
187
- end
@@ -1,225 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module TCellAgent
4
- class MockAgent < Agent
5
- end
6
- end
7
-
8
- module TCellAgent
9
- module Instrumentation
10
- describe Instrumentation do
11
- before(:each) do
12
- configuration = double(
13
- 'configuration',
14
- {
15
- 'app_id' => 'app_id',
16
- 'api_key' => 'api_key',
17
- 'allow_payloads' => true,
18
- 'js_agent_api_base_url' => 'http://api.tcell.com/',
19
- 'js_agent_url' => 'https://jsagent.tcell.io/tcellagent.min.js',
20
- 'max_csp_header_bytes' => nil,
21
- 'event_time_limit_seconds' => 15,
22
- 'event_batch_size_limit' => 50,
23
- 'preload_policy_filename' => nil,
24
- 'cache_filename_with_app_id' => '/tcellagent_src/tcell/cache/tcell_agent.cache',
25
- 'agent_home_owner' => nil
26
- }
27
- )
28
- expect(TCellAgent).to receive(:configuration).and_return(configuration).at_most(10)
29
- end
30
-
31
- context 'Body - SessionId Filters' do
32
- it 'Tests Redaction and Events in Body' do
33
- action = TCellAgent::Policies::DataLossPolicy::FilterActions.new
34
- action.body_redact = true
35
- action.action_id = 5
36
- policy_json_two = {
37
- 'policy_id' => 'x1a1',
38
- 'data' => {
39
- 'session_id_protections' => { 'body' => ['redact'], 'log' => ['event'] }
40
- }
41
- }
42
- session_id_policy = TCellAgent::Policies::DataLossPolicy.from_json(policy_json_two)
43
- mock_agent = MockAgent.new(-1)
44
- mock_agent.policies[TCellAgent::PolicyTypes::DATALOSS] = session_id_policy
45
- TCellAgent.set_thread_agent(mock_agent)
46
-
47
- context = TCellData.new
48
- context.session_id = 'tim123123my'
49
-
50
- body = 'this is about tim123123my 3123123.'
51
- TCellAgent.empty_event_queue
52
- context.filter_body!(body)
53
- expect(body).to eq('this is about [redacted] 3123123.')
54
- expect(TCellAgent.event_queue.length).to eq(1)
55
- TCellAgent.set_thread_agent(nil)
56
- end
57
- it 'Tests Events in Body' do
58
- action = TCellAgent::Policies::DataLossPolicy::FilterActions.new
59
- action.body_redact = true
60
- action.action_id = 5
61
- policy_json_two = {
62
- 'policy_id' => 'x1a1',
63
- 'data' => {
64
- 'session_id_protections' => { 'body' => ['event'], 'log' => ['redact'] }
65
- }
66
- }
67
- session_id_policy = TCellAgent::Policies::DataLossPolicy.from_json(policy_json_two)
68
- mock_agent = MockAgent.new(-1)
69
- mock_agent.policies[TCellAgent::PolicyTypes::DATALOSS] = session_id_policy
70
- TCellAgent.set_thread_agent(mock_agent)
71
-
72
- context = TCellData.new
73
- context.session_id = 'tim123123my'
74
-
75
- body = 'this is about tim123123my 3123123.'
76
- TCellAgent.empty_event_queue
77
- context.filter_body!(body)
78
- expect(body).to eq('this is about tim123123my 3123123.')
79
- expect(TCellAgent.event_queue.length).to eq(1)
80
- TCellAgent.set_thread_agent(nil)
81
- end
82
- end
83
- context 'Log - SessionId Filters' do
84
- it 'Tests Redaction and Events in Body' do
85
- action = TCellAgent::Policies::DataLossPolicy::FilterActions.new
86
- action.body_redact = true
87
- action.action_id = 5
88
- policy_json_two = {
89
- 'policy_id' => 'x1a1',
90
- 'data' => {
91
- 'session_id_protections' => { 'body' => ['redact'], 'log' => ['redact'] }
92
- }
93
- }
94
- session_id_policy = TCellAgent::Policies::DataLossPolicy.from_json(policy_json_two)
95
- mock_agent = MockAgent.new(-1)
96
- mock_agent.policies[TCellAgent::PolicyTypes::DATALOSS] = session_id_policy
97
- TCellAgent.set_thread_agent(mock_agent)
98
-
99
- context = TCellData.new
100
- context.session_id = 'tim123123my'
101
-
102
- body = 'this is about tim123123my 3123123.'
103
- TCellAgent.empty_event_queue
104
- context.filter_log(body)
105
- expect(body).to eq('this is about [redacted] 3123123.')
106
- expect(TCellAgent.event_queue.length).to eq(1)
107
- TCellAgent.set_thread_agent(nil)
108
- end
109
- it 'Tests Events Only' do
110
- action = TCellAgent::Policies::DataLossPolicy::FilterActions.new
111
- action.body_redact = true
112
- action.action_id = 5
113
- policy_json_two = {
114
- 'policy_id' => 'x1a1',
115
- 'data' => {
116
- 'session_id_protections' => { 'body' => ['redact'], 'log' => ['event'] }
117
- }
118
- }
119
- session_id_policy = TCellAgent::Policies::DataLossPolicy.from_json(policy_json_two)
120
- mock_agent = MockAgent.new(-1)
121
- mock_agent.policies[TCellAgent::PolicyTypes::DATALOSS] = session_id_policy
122
- TCellAgent.set_thread_agent(mock_agent)
123
-
124
- context = TCellData.new
125
- context.session_id = 'tim123123my'
126
-
127
- body = 'this is about tim123123my 3123123.'
128
- TCellAgent.empty_event_queue
129
- context.filter_log(body)
130
- expect(body).to eq('this is about tim123123my 3123123.')
131
- expect(TCellAgent.event_queue.length).to eq(1)
132
- TCellAgent.set_thread_agent(nil)
133
- end
134
- end
135
- context 'Body - Database Filters' do
136
- it 'Tests Redaction and Events in Body' do
137
- action = TCellAgent::Policies::DataLossPolicy::FilterActions.new
138
- action.body_redact = true
139
- action.action_id = 5
140
- context = TCellData.new
141
- context.add_response_db_filter('timmy', action, 'don', 'sam', 'tim', 'fred')
142
- context.add_response_db_filter('timmy23', action, 'don', 'sam', 'tim', 'fred')
143
- context.add_response_db_filter('3123123', action, 'don', 'sam', 'tim', 'fred')
144
- context.add_response_db_filter('tim123my', action, 'don', 'sam', 'tim', 'fred')
145
- context.add_response_db_filter('timmy1', action, 'don', 'sam', 'tim', 'fred')
146
- context.add_response_db_filter('tim123123my', action, 'don', 'sam', 'tim', 'fred')
147
- context.add_response_db_filter('ti21312mmy', action, 'don', 'sam', 'tim', 'fred')
148
- context.add_response_db_filter('ti123123mmy', action, 'don', 'sam', 'tim', 'fred')
149
- context.add_response_db_filter(10_233_234, action, 'don', 'sam', 'tim', 'fred')
150
- context.add_response_db_filter(true, action, 'don', 'sam', 'tim', 'fred')
151
- body = 'this is about timmy1 3123123.'
152
- TCellAgent.empty_event_queue
153
- context.filter_body!(body)
154
- expect(body).to eq('this is about [redacted] [redacted].')
155
- expect(TCellAgent.event_queue.length).to eq(2)
156
- end
157
- it 'Tests Event Only Match in Body' do
158
- action = TCellAgent::Policies::DataLossPolicy::FilterActions.new
159
- action.body_event = true
160
- action.action_id = 5
161
- context = TCellData.new
162
- context.add_response_db_filter('timmy', action, 'don', 'sam', 'tim', 'fred')
163
- context.add_response_db_filter('timmy23', action, 'don', 'sam', 'tim', 'fred')
164
- context.add_response_db_filter('3123123', action, 'don', 'sam', 'tim', 'fred')
165
- context.add_response_db_filter('tim123my', action, 'don', 'sam', 'tim', 'fred')
166
- context.add_response_db_filter('timmy1', action, 'don', 'sam', 'tim', 'fred')
167
- context.add_response_db_filter('tim123123my', action, 'don', 'sam', 'tim', 'fred')
168
- context.add_response_db_filter('ti21312mmy', action, 'don', 'sam', 'tim', 'fred')
169
- context.add_response_db_filter('ti123123mmy', action, 'don', 'sam', 'tim', 'fred')
170
- context.add_response_db_filter(10_233_234, action, 'don', 'sam', 'tim', 'fred')
171
- context.add_response_db_filter(true, action, 'don', 'sam', 'tim', 'fred')
172
- body = 'this is about timmy1 3123123.'
173
- TCellAgent.empty_event_queue
174
- context.filter_body!(body)
175
- expect(body).to eq('this is about timmy1 3123123.')
176
- expect(TCellAgent.event_queue.length).to eq(3) # timmy, timmy1, 3123123
177
- end
178
- end
179
- context 'Log - Database Filters' do
180
- it 'Tests Redaction and Events' do
181
- action = TCellAgent::Policies::DataLossPolicy::FilterActions.new
182
- action.log_redact = true
183
- action.action_id = 5
184
- context = TCellData.new
185
- context.add_response_db_filter('timmy', action, 'don', 'sam', 'tim', 'fred')
186
- context.add_response_db_filter('timmy23', action, 'don', 'sam', 'tim', 'fred')
187
- context.add_response_db_filter('3123123', action, 'don', 'sam', 'tim', 'fred')
188
- context.add_response_db_filter('tim123my', action, 'don', 'sam', 'tim', 'fred')
189
- context.add_response_db_filter('timmy1', action, 'don', 'sam', 'tim', 'fred')
190
- context.add_response_db_filter('tim123123my', action, 'don', 'sam', 'tim', 'fred')
191
- context.add_response_db_filter('ti21312mmy', action, 'don', 'sam', 'tim', 'fred')
192
- context.add_response_db_filter('ti123123mmy', action, 'don', 'sam', 'tim', 'fred')
193
- context.add_response_db_filter(10_233_234, action, 'don', 'sam', 'tim', 'fred')
194
- context.add_response_db_filter(true, action, 'don', 'sam', 'tim', 'fred')
195
- body = 'this is about timmy1 3123123.'
196
- TCellAgent.empty_event_queue
197
- context.filter_log(body)
198
- expect(body).to eq('this is about [redacted] [redacted].')
199
- expect(TCellAgent.event_queue.length).to eq(2)
200
- end
201
- it 'Tests Report-Only and Events' do
202
- action = TCellAgent::Policies::DataLossPolicy::FilterActions.new
203
- action.log_event = true
204
- action.action_id = 5
205
- context = TCellData.new
206
- context.add_response_db_filter('timmy', action, 'don', 'sam', 'tim', 'fred')
207
- context.add_response_db_filter('timmy23', action, 'don', 'sam', 'tim', 'fred')
208
- context.add_response_db_filter('3123123', action, 'don', 'sam', 'tim', 'fred')
209
- context.add_response_db_filter('tim123my', action, 'don', 'sam', 'tim', 'fred')
210
- context.add_response_db_filter('timmy1', action, 'don', 'sam', 'tim', 'fred')
211
- context.add_response_db_filter('tim123123my', action, 'don', 'sam', 'tim', 'fred')
212
- context.add_response_db_filter('ti21312mmy', action, 'don', 'sam', 'tim', 'fred')
213
- context.add_response_db_filter('ti123123mmy', action, 'don', 'sam', 'tim', 'fred')
214
- context.add_response_db_filter(10_233_234, action, 'don', 'sam', 'tim', 'fred')
215
- context.add_response_db_filter(true, action, 'don', 'sam', 'tim', 'fred')
216
- body = 'this is about timmy1 3123123.'
217
- TCellAgent.empty_event_queue
218
- context.filter_log(body)
219
- expect(body).to eq('this is about timmy1 3123123.')
220
- expect(TCellAgent.event_queue.length).to eq(3) # timmy, timmy1, 3123123
221
- end
222
- end
223
- end
224
- end
225
- end