tcell_agent 0.4.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +9 -22
- data/bin/tcell_agent +127 -132
- data/lib/tcell_agent/agent/event_processor.rb +23 -22
- data/lib/tcell_agent/agent/fork_pipe_manager.rb +7 -7
- data/lib/tcell_agent/agent/policy_manager.rb +20 -15
- data/lib/tcell_agent/agent/policy_types.rb +5 -11
- data/lib/tcell_agent/agent/static_agent.rb +5 -1
- data/lib/tcell_agent/agent.rb +6 -4
- data/lib/tcell_agent/api.rb +7 -9
- data/lib/tcell_agent/appsensor/meta_data.rb +11 -4
- data/lib/tcell_agent/authlogic.rb +3 -3
- data/lib/tcell_agent/cmdi.rb +6 -4
- data/lib/tcell_agent/config/unknown_options.rb +3 -1
- data/lib/tcell_agent/configuration.rb +47 -49
- data/lib/tcell_agent/devise.rb +2 -2
- data/lib/tcell_agent/hooks/login_fraud.rb +58 -29
- data/lib/tcell_agent/instrumentation.rb +11 -10
- data/lib/tcell_agent/logger.rb +2 -2
- data/lib/tcell_agent/patches/meta_data.rb +9 -13
- data/lib/tcell_agent/patches.rb +7 -10
- data/lib/tcell_agent/policies/clickjacking_policy.rb +4 -5
- data/lib/tcell_agent/policies/content_security_policy.rb +6 -12
- data/lib/tcell_agent/policies/dataloss_policy.rb +2 -2
- data/lib/tcell_agent/policies/http_redirect_policy.rb +2 -2
- data/lib/tcell_agent/policies/policy.rb +0 -2
- data/lib/tcell_agent/policies/rust_policies.rb +90 -0
- data/lib/tcell_agent/policies/secure_headers_policy.rb +2 -2
- data/lib/tcell_agent/rails/auth/authlogic.rb +42 -24
- data/lib/tcell_agent/rails/auth/devise.rb +44 -23
- data/lib/tcell_agent/rails/auth/doorkeeper.rb +33 -15
- data/lib/tcell_agent/rails/better_ip.rb +1 -1
- data/lib/tcell_agent/rails/csrf_exception.rb +2 -2
- data/lib/tcell_agent/rails/dlp/process_request.rb +1 -1
- data/lib/tcell_agent/rails/dlp.rb +6 -6
- data/lib/tcell_agent/rails/dlp_handler.rb +1 -1
- data/lib/tcell_agent/rails/js_agent_insert.rb +1 -1
- data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +1 -1
- data/lib/tcell_agent/rails/middleware/context_middleware.rb +3 -2
- data/lib/tcell_agent/rails/middleware/headers_middleware.rb +10 -9
- data/lib/tcell_agent/rails/routes/grape.rb +6 -6
- data/lib/tcell_agent/rails/routes.rb +8 -11
- data/lib/tcell_agent/rust/libtcellagent-0.11.1.dylib +0 -0
- data/lib/tcell_agent/rust/{libtcellagent-0.6.1.so → libtcellagent-0.11.1.so} +0 -0
- data/lib/tcell_agent/rust/models.rb +16 -0
- data/lib/tcell_agent/rust/tcellagent-0.11.1.dll +0 -0
- data/lib/tcell_agent/rust/whisperer.rb +119 -48
- data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +17 -20
- data/lib/tcell_agent/sensor_events/command_injection.rb +50 -5
- data/lib/tcell_agent/sensor_events/login_fraud.rb +34 -18
- data/lib/tcell_agent/sensor_events/patches.rb +21 -0
- data/lib/tcell_agent/sensor_events/server_agent.rb +3 -3
- data/lib/tcell_agent/sensor_events/util/utils.rb +4 -3
- data/lib/tcell_agent/servers/puma.rb +2 -2
- data/lib/tcell_agent/servers/unicorn.rb +1 -1
- data/lib/tcell_agent/utils/passwords.rb +28 -0
- data/lib/tcell_agent/version.rb +1 -1
- data/lib/tcell_agent.rb +1 -5
- data/spec/apps/rails-3.2/config/tcell_agent.config +15 -0
- data/spec/apps/rails-3.2/log/development.log +0 -0
- data/spec/apps/rails-3.2/log/test.log +12 -0
- data/spec/apps/rails-4.1/log/test.log +0 -0
- data/spec/lib/tcell_agent/agent/fork_pipe_manager_spec.rb +46 -45
- data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +276 -164
- data/spec/lib/tcell_agent/agent/static_agent_spec.rb +44 -47
- data/spec/lib/tcell_agent/api/api_spec.rb +16 -16
- data/spec/lib/tcell_agent/appsensor/injections_reporter_spec.rb +131 -116
- data/spec/lib/tcell_agent/appsensor/meta_data_spec.rb +55 -51
- data/spec/lib/tcell_agent/cmdi_spec.rb +413 -436
- data/spec/lib/tcell_agent/config/unknown_options_spec.rb +145 -128
- data/spec/lib/tcell_agent/configuration_spec.rb +165 -169
- data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +144 -153
- data/spec/lib/tcell_agent/instrumentation_spec.rb +84 -85
- data/spec/lib/tcell_agent/patches_spec.rb +70 -111
- data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +313 -244
- data/spec/lib/tcell_agent/policies/clickjacking_policy_spec.rb +28 -28
- data/spec/lib/tcell_agent/policies/command_injection_policy_spec.rb +643 -513
- data/spec/lib/tcell_agent/policies/content_security_policy_spec.rb +55 -102
- data/spec/lib/tcell_agent/policies/dataloss_policy_spec.rb +111 -134
- data/spec/lib/tcell_agent/policies/http_redirect_policy_spec.rb +141 -146
- data/spec/lib/tcell_agent/policies/http_tx_policy_spec.rb +8 -8
- data/spec/lib/tcell_agent/policies/login_policy_spec.rb +15 -17
- data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +231 -559
- data/spec/lib/tcell_agent/policies/secure_headers_policy_spec.rb +27 -27
- data/spec/lib/tcell_agent/rails/better_ip_spec.rb +30 -34
- data/spec/lib/tcell_agent/rails/logger_spec.rb +50 -49
- data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +182 -199
- data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +110 -84
- data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +107 -85
- data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +68 -40
- data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +81 -67
- data/spec/lib/tcell_agent/rails/responses_spec.rb +33 -37
- data/spec/lib/tcell_agent/rails/routes/grape_spec.rb +116 -121
- data/spec/lib/tcell_agent/rails/routes/route_id_spec.rb +25 -28
- data/spec/lib/tcell_agent/rails/routes/routes_spec.rb +87 -85
- data/spec/lib/tcell_agent/rails_spec.rb +1 -6
- data/spec/lib/tcell_agent/rust/models_spec.rb +112 -0
- data/spec/lib/tcell_agent/rust/whisperer_spec.rb +502 -179
- data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +44 -33
- data/spec/lib/tcell_agent/sensor_events/dlp_spec.rb +4 -4
- data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +183 -169
- data/spec/lib/tcell_agent/sensor_events/util/sanitizer_utilities_spec.rb +25 -25
- data/spec/lib/tcell_agent/utils/bounded_queue_spec.rb +17 -20
- data/spec/lib/tcell_agent/utils/params_spec.rb +28 -28
- data/spec/lib/tcell_agent/utils/passwords_spec.rb +143 -0
- data/spec/lib/tcell_agent/utils/strings_spec.rb +35 -35
- data/spec/lib/tcell_agent_spec.rb +8 -8
- data/spec/spec_helper.rb +4 -4
- data/spec/support/middleware_helper.rb +10 -10
- data/spec/support/static_agent_overrides.rb +16 -12
- data/tcell_agent.gemspec +17 -33
- metadata +43 -198
- data/LICENSE_libinjection +0 -32
- data/Readme.txt +0 -7
- data/ext/libinjection/extconf.rb +0 -3
- data/ext/libinjection/libinjection.h +0 -65
- data/ext/libinjection/libinjection_html5.c +0 -847
- data/ext/libinjection/libinjection_html5.h +0 -54
- data/ext/libinjection/libinjection_sqli.c +0 -2317
- data/ext/libinjection/libinjection_sqli.h +0 -295
- data/ext/libinjection/libinjection_sqli_data.h +0 -9004
- data/ext/libinjection/libinjection_wrap.c +0 -3525
- data/ext/libinjection/libinjection_xss.c +0 -531
- data/ext/libinjection/libinjection_xss.h +0 -21
- data/lib/tcell_agent/appsensor/injections_matcher.rb +0 -155
- data/lib/tcell_agent/appsensor/rules/appsensor_rule_manager.rb +0 -49
- data/lib/tcell_agent/appsensor/rules/appsensor_rule_set.rb +0 -67
- data/lib/tcell_agent/appsensor/rules/baserules.json +0 -467
- data/lib/tcell_agent/patches/block_rule.rb +0 -93
- data/lib/tcell_agent/patches/sensors_matcher.rb +0 -31
- data/lib/tcell_agent/policies/appsensor/cmdi_sensor.rb +0 -23
- data/lib/tcell_agent/policies/appsensor/fpt_sensor.rb +0 -23
- data/lib/tcell_agent/policies/appsensor/injection_sensor.rb +0 -117
- data/lib/tcell_agent/policies/appsensor/nullbyte_sensor.rb +0 -26
- data/lib/tcell_agent/policies/appsensor/retr_sensor.rb +0 -22
- data/lib/tcell_agent/policies/appsensor/sqli_sensor.rb +0 -34
- data/lib/tcell_agent/policies/appsensor/xss_sensor.rb +0 -34
- data/lib/tcell_agent/policies/appsensor_policy.rb +0 -49
- data/lib/tcell_agent/policies/command_injection_policy.rb +0 -196
- data/lib/tcell_agent/policies/honeytokens_policy.rb +0 -69
- data/lib/tcell_agent/policies/patches_policy.rb +0 -84
- data/lib/tcell_agent/rust/libtcellagent-0.6.1.dylib +0 -0
- data/lib/tcell_agent/rust/tcellagent-0.6.1.dll +0 -0
- data/spec/apps/rails-3.2/Gemfile +0 -25
- data/spec/apps/rails-3.2/Gemfile.lock +0 -126
- data/spec/apps/rails-3.2/Rakefile +0 -7
- data/spec/apps/rails-3.2/app/assets/images/rails.png +0 -0
- data/spec/apps/rails-3.2/app/assets/javascripts/application.js +0 -15
- data/spec/apps/rails-3.2/app/assets/stylesheets/application.css +0 -13
- data/spec/apps/rails-3.2/app/controllers/application_controller.rb +0 -3
- data/spec/apps/rails-3.2/app/controllers/t_cell_app_controller.rb +0 -5
- data/spec/apps/rails-3.2/app/helpers/application_helper.rb +0 -2
- data/spec/apps/rails-3.2/app/views/layouts/application.html.erb +0 -14
- data/spec/apps/rails-3.2/app/views/t_cell_app/index.html.erb +0 -1
- data/spec/apps/rails-3.2/config/application.rb +0 -63
- data/spec/apps/rails-3.2/config/boot.rb +0 -6
- data/spec/apps/rails-3.2/config/environment.rb +0 -5
- data/spec/apps/rails-3.2/config/environments/test.rb +0 -37
- data/spec/apps/rails-3.2/config/routes.rb +0 -11
- data/spec/apps/rails-3.2/config.ru +0 -4
- data/spec/apps/rails-4.1/Gemfile +0 -7
- data/spec/apps/rails-4.1/Gemfile.lock +0 -114
- data/spec/apps/rails-4.1/Rakefile +0 -6
- data/spec/apps/rails-4.1/app/assets/javascripts/application.js +0 -16
- data/spec/apps/rails-4.1/app/assets/stylesheets/application.css +0 -15
- data/spec/apps/rails-4.1/app/controllers/application_controller.rb +0 -5
- data/spec/apps/rails-4.1/app/controllers/t_cell_app_controller.rb +0 -5
- data/spec/apps/rails-4.1/app/helpers/application_helper.rb +0 -2
- data/spec/apps/rails-4.1/app/views/layouts/application.html.erb +0 -14
- data/spec/apps/rails-4.1/app/views/t_cell_app/index.html.erb +0 -1
- data/spec/apps/rails-4.1/config/application.rb +0 -24
- data/spec/apps/rails-4.1/config/boot.rb +0 -4
- data/spec/apps/rails-4.1/config/environment.rb +0 -5
- data/spec/apps/rails-4.1/config/environments/test.rb +0 -41
- data/spec/apps/rails-4.1/config/initializers/assets.rb +0 -8
- data/spec/apps/rails-4.1/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/apps/rails-4.1/config/initializers/cookies_serializer.rb +0 -3
- data/spec/apps/rails-4.1/config/initializers/filter_parameter_logging.rb +0 -4
- data/spec/apps/rails-4.1/config/initializers/inflections.rb +0 -16
- data/spec/apps/rails-4.1/config/initializers/mime_types.rb +0 -4
- data/spec/apps/rails-4.1/config/initializers/session_store.rb +0 -3
- data/spec/apps/rails-4.1/config/initializers/wrap_parameters.rb +0 -14
- data/spec/apps/rails-4.1/config/locales/en.yml +0 -23
- data/spec/apps/rails-4.1/config/routes.rb +0 -12
- data/spec/apps/rails-4.1/config/secrets.yml +0 -22
- data/spec/apps/rails-4.1/config.ru +0 -4
- data/spec/controllers/application_controller.rb +0 -12
- data/spec/lib/tcell_agent/appsensor/injections_matcher_spec.rb +0 -522
- data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_manager_spec.rb +0 -23
- data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_set_spec.rb +0 -159
- data/spec/lib/tcell_agent/patches/block_rule_spec.rb +0 -458
- data/spec/lib/tcell_agent/patches/sensors_matcher_spec.rb +0 -35
- data/spec/lib/tcell_agent/policies/appsensor/cmdi_sensor_spec.rb +0 -139
- data/spec/lib/tcell_agent/policies/appsensor/fpt_sensor_spec.rb +0 -139
- data/spec/lib/tcell_agent/policies/appsensor/nullbyte_sensor_spec.rb +0 -167
- data/spec/lib/tcell_agent/policies/appsensor/retr_sensor_spec.rb +0 -139
- data/spec/lib/tcell_agent/policies/appsensor/sqli_sensor_spec.rb +0 -246
- data/spec/lib/tcell_agent/policies/appsensor/xss_sensor_spec.rb +0 -882
- data/spec/lib/tcell_agent/policies/honeytokens_policy_spec.rb +0 -22
@@ -5,19 +5,18 @@ module TCellAgent
|
|
5
5
|
end
|
6
6
|
end
|
7
7
|
|
8
|
-
|
9
8
|
module TCellAgent
|
10
9
|
module Instrumentation
|
11
10
|
describe Instrumentation do
|
12
|
-
context
|
13
|
-
it
|
11
|
+
context 'Body - SessionId Filters' do
|
12
|
+
it 'Tests Redaction and Events in Body' do
|
14
13
|
action = TCellAgent::Policies::DataLossPolicy::FilterActions.new
|
15
14
|
action.body_redact = true
|
16
15
|
action.action_id = 5
|
17
16
|
policy_json_two = {
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
'policy_id' => 'x1a1',
|
18
|
+
'data' => {
|
19
|
+
'session_id_protections' => { 'body' => ['redact'], 'log' => ['event'] }
|
21
20
|
}
|
22
21
|
}
|
23
22
|
session_id_policy = TCellAgent::Policies::DataLossPolicy.from_json(policy_json_two)
|
@@ -26,23 +25,23 @@ module TCellAgent
|
|
26
25
|
TCellAgent.set_thread_agent(mock_agent)
|
27
26
|
|
28
27
|
context = TCellData.new
|
29
|
-
context.session_id =
|
28
|
+
context.session_id = 'tim123123my'
|
30
29
|
|
31
|
-
body =
|
30
|
+
body = 'this is about tim123123my 3123123.'
|
32
31
|
TCellAgent.empty_event_queue
|
33
32
|
context.filter_body!(body)
|
34
|
-
expect(body).to eq(
|
33
|
+
expect(body).to eq('this is about [redacted] 3123123.')
|
35
34
|
expect(TCellAgent.event_queue.length).to eq(1)
|
36
35
|
TCellAgent.set_thread_agent(nil)
|
37
36
|
end
|
38
|
-
it
|
37
|
+
it 'Tests Events in Body' do
|
39
38
|
action = TCellAgent::Policies::DataLossPolicy::FilterActions.new
|
40
39
|
action.body_redact = true
|
41
40
|
action.action_id = 5
|
42
41
|
policy_json_two = {
|
43
|
-
|
44
|
-
|
45
|
-
|
42
|
+
'policy_id' => 'x1a1',
|
43
|
+
'data' => {
|
44
|
+
'session_id_protections' => { 'body' => ['event'], 'log' => ['redact'] }
|
46
45
|
}
|
47
46
|
}
|
48
47
|
session_id_policy = TCellAgent::Policies::DataLossPolicy.from_json(policy_json_two)
|
@@ -51,25 +50,25 @@ module TCellAgent
|
|
51
50
|
TCellAgent.set_thread_agent(mock_agent)
|
52
51
|
|
53
52
|
context = TCellData.new
|
54
|
-
context.session_id =
|
53
|
+
context.session_id = 'tim123123my'
|
55
54
|
|
56
|
-
body =
|
55
|
+
body = 'this is about tim123123my 3123123.'
|
57
56
|
TCellAgent.empty_event_queue
|
58
57
|
context.filter_body!(body)
|
59
|
-
expect(body).to eq(
|
58
|
+
expect(body).to eq('this is about tim123123my 3123123.')
|
60
59
|
expect(TCellAgent.event_queue.length).to eq(1)
|
61
60
|
TCellAgent.set_thread_agent(nil)
|
62
61
|
end
|
63
62
|
end
|
64
|
-
context
|
65
|
-
it
|
63
|
+
context 'Log - SessionId Filters' do
|
64
|
+
it 'Tests Redaction and Events in Body' do
|
66
65
|
action = TCellAgent::Policies::DataLossPolicy::FilterActions.new
|
67
66
|
action.body_redact = true
|
68
67
|
action.action_id = 5
|
69
68
|
policy_json_two = {
|
70
|
-
|
71
|
-
|
72
|
-
|
69
|
+
'policy_id' => 'x1a1',
|
70
|
+
'data' => {
|
71
|
+
'session_id_protections' => { 'body' => ['redact'], 'log' => ['redact'] }
|
73
72
|
}
|
74
73
|
}
|
75
74
|
session_id_policy = TCellAgent::Policies::DataLossPolicy.from_json(policy_json_two)
|
@@ -78,23 +77,23 @@ module TCellAgent
|
|
78
77
|
TCellAgent.set_thread_agent(mock_agent)
|
79
78
|
|
80
79
|
context = TCellData.new
|
81
|
-
context.session_id =
|
80
|
+
context.session_id = 'tim123123my'
|
82
81
|
|
83
|
-
body =
|
82
|
+
body = 'this is about tim123123my 3123123.'
|
84
83
|
TCellAgent.empty_event_queue
|
85
84
|
context.filter_log(body)
|
86
|
-
expect(body).to eq(
|
85
|
+
expect(body).to eq('this is about [redacted] 3123123.')
|
87
86
|
expect(TCellAgent.event_queue.length).to eq(1)
|
88
87
|
TCellAgent.set_thread_agent(nil)
|
89
88
|
end
|
90
|
-
it
|
89
|
+
it 'Tests Events Only' do
|
91
90
|
action = TCellAgent::Policies::DataLossPolicy::FilterActions.new
|
92
91
|
action.body_redact = true
|
93
92
|
action.action_id = 5
|
94
93
|
policy_json_two = {
|
95
|
-
|
96
|
-
|
97
|
-
|
94
|
+
'policy_id' => 'x1a1',
|
95
|
+
'data' => {
|
96
|
+
'session_id_protections' => { 'body' => ['redact'], 'log' => ['event'] }
|
98
97
|
}
|
99
98
|
}
|
100
99
|
session_id_policy = TCellAgent::Policies::DataLossPolicy.from_json(policy_json_two)
|
@@ -103,101 +102,101 @@ module TCellAgent
|
|
103
102
|
TCellAgent.set_thread_agent(mock_agent)
|
104
103
|
|
105
104
|
context = TCellData.new
|
106
|
-
context.session_id =
|
105
|
+
context.session_id = 'tim123123my'
|
107
106
|
|
108
|
-
body =
|
107
|
+
body = 'this is about tim123123my 3123123.'
|
109
108
|
TCellAgent.empty_event_queue
|
110
109
|
context.filter_log(body)
|
111
|
-
expect(body).to eq(
|
110
|
+
expect(body).to eq('this is about tim123123my 3123123.')
|
112
111
|
expect(TCellAgent.event_queue.length).to eq(1)
|
113
112
|
TCellAgent.set_thread_agent(nil)
|
114
113
|
end
|
115
114
|
end
|
116
|
-
context
|
117
|
-
it
|
115
|
+
context 'Body - Database Filters' do
|
116
|
+
it 'Tests Redaction and Events in Body' do
|
118
117
|
action = TCellAgent::Policies::DataLossPolicy::FilterActions.new
|
119
118
|
action.body_redact = true
|
120
119
|
action.action_id = 5
|
121
120
|
context = TCellData.new
|
122
|
-
context.add_response_db_filter(
|
123
|
-
context.add_response_db_filter(
|
124
|
-
context.add_response_db_filter(
|
125
|
-
context.add_response_db_filter(
|
126
|
-
context.add_response_db_filter(
|
127
|
-
context.add_response_db_filter(
|
128
|
-
context.add_response_db_filter(
|
129
|
-
context.add_response_db_filter(
|
130
|
-
context.add_response_db_filter(
|
131
|
-
context.add_response_db_filter(true, action,
|
132
|
-
body =
|
121
|
+
context.add_response_db_filter('timmy', action, 'don', 'sam', 'tim', 'fred')
|
122
|
+
context.add_response_db_filter('timmy23', action, 'don', 'sam', 'tim', 'fred')
|
123
|
+
context.add_response_db_filter('3123123', action, 'don', 'sam', 'tim', 'fred')
|
124
|
+
context.add_response_db_filter('tim123my', action, 'don', 'sam', 'tim', 'fred')
|
125
|
+
context.add_response_db_filter('timmy1', action, 'don', 'sam', 'tim', 'fred')
|
126
|
+
context.add_response_db_filter('tim123123my', action, 'don', 'sam', 'tim', 'fred')
|
127
|
+
context.add_response_db_filter('ti21312mmy', action, 'don', 'sam', 'tim', 'fred')
|
128
|
+
context.add_response_db_filter('ti123123mmy', action, 'don', 'sam', 'tim', 'fred')
|
129
|
+
context.add_response_db_filter(10_233_234, action, 'don', 'sam', 'tim', 'fred')
|
130
|
+
context.add_response_db_filter(true, action, 'don', 'sam', 'tim', 'fred')
|
131
|
+
body = 'this is about timmy1 3123123.'
|
133
132
|
TCellAgent.empty_event_queue
|
134
133
|
context.filter_body!(body)
|
135
|
-
expect(body).to eq(
|
134
|
+
expect(body).to eq('this is about [redacted] [redacted].')
|
136
135
|
expect(TCellAgent.event_queue.length).to eq(2)
|
137
136
|
end
|
138
|
-
it
|
137
|
+
it 'Tests Event Only Match in Body' do
|
139
138
|
action = TCellAgent::Policies::DataLossPolicy::FilterActions.new
|
140
139
|
action.body_event = true
|
141
140
|
action.action_id = 5
|
142
141
|
context = TCellData.new
|
143
|
-
context.add_response_db_filter(
|
144
|
-
context.add_response_db_filter(
|
145
|
-
context.add_response_db_filter(
|
146
|
-
context.add_response_db_filter(
|
147
|
-
context.add_response_db_filter(
|
148
|
-
context.add_response_db_filter(
|
149
|
-
context.add_response_db_filter(
|
150
|
-
context.add_response_db_filter(
|
151
|
-
context.add_response_db_filter(
|
152
|
-
context.add_response_db_filter(true, action,
|
153
|
-
body =
|
142
|
+
context.add_response_db_filter('timmy', action, 'don', 'sam', 'tim', 'fred')
|
143
|
+
context.add_response_db_filter('timmy23', action, 'don', 'sam', 'tim', 'fred')
|
144
|
+
context.add_response_db_filter('3123123', action, 'don', 'sam', 'tim', 'fred')
|
145
|
+
context.add_response_db_filter('tim123my', action, 'don', 'sam', 'tim', 'fred')
|
146
|
+
context.add_response_db_filter('timmy1', action, 'don', 'sam', 'tim', 'fred')
|
147
|
+
context.add_response_db_filter('tim123123my', action, 'don', 'sam', 'tim', 'fred')
|
148
|
+
context.add_response_db_filter('ti21312mmy', action, 'don', 'sam', 'tim', 'fred')
|
149
|
+
context.add_response_db_filter('ti123123mmy', action, 'don', 'sam', 'tim', 'fred')
|
150
|
+
context.add_response_db_filter(10_233_234, action, 'don', 'sam', 'tim', 'fred')
|
151
|
+
context.add_response_db_filter(true, action, 'don', 'sam', 'tim', 'fred')
|
152
|
+
body = 'this is about timmy1 3123123.'
|
154
153
|
TCellAgent.empty_event_queue
|
155
154
|
context.filter_body!(body)
|
156
|
-
expect(body).to eq(
|
155
|
+
expect(body).to eq('this is about timmy1 3123123.')
|
157
156
|
expect(TCellAgent.event_queue.length).to eq(3) # timmy, timmy1, 3123123
|
158
157
|
end
|
159
158
|
end
|
160
|
-
context
|
161
|
-
it
|
159
|
+
context 'Log - Database Filters' do
|
160
|
+
it 'Tests Redaction and Events' do
|
162
161
|
action = TCellAgent::Policies::DataLossPolicy::FilterActions.new
|
163
162
|
action.log_redact = true
|
164
163
|
action.action_id = 5
|
165
164
|
context = TCellData.new
|
166
|
-
context.add_response_db_filter(
|
167
|
-
context.add_response_db_filter(
|
168
|
-
context.add_response_db_filter(
|
169
|
-
context.add_response_db_filter(
|
170
|
-
context.add_response_db_filter(
|
171
|
-
context.add_response_db_filter(
|
172
|
-
context.add_response_db_filter(
|
173
|
-
context.add_response_db_filter(
|
174
|
-
context.add_response_db_filter(
|
175
|
-
context.add_response_db_filter(true, action,
|
176
|
-
body =
|
165
|
+
context.add_response_db_filter('timmy', action, 'don', 'sam', 'tim', 'fred')
|
166
|
+
context.add_response_db_filter('timmy23', action, 'don', 'sam', 'tim', 'fred')
|
167
|
+
context.add_response_db_filter('3123123', action, 'don', 'sam', 'tim', 'fred')
|
168
|
+
context.add_response_db_filter('tim123my', action, 'don', 'sam', 'tim', 'fred')
|
169
|
+
context.add_response_db_filter('timmy1', action, 'don', 'sam', 'tim', 'fred')
|
170
|
+
context.add_response_db_filter('tim123123my', action, 'don', 'sam', 'tim', 'fred')
|
171
|
+
context.add_response_db_filter('ti21312mmy', action, 'don', 'sam', 'tim', 'fred')
|
172
|
+
context.add_response_db_filter('ti123123mmy', action, 'don', 'sam', 'tim', 'fred')
|
173
|
+
context.add_response_db_filter(10_233_234, action, 'don', 'sam', 'tim', 'fred')
|
174
|
+
context.add_response_db_filter(true, action, 'don', 'sam', 'tim', 'fred')
|
175
|
+
body = 'this is about timmy1 3123123.'
|
177
176
|
TCellAgent.empty_event_queue
|
178
177
|
context.filter_log(body)
|
179
|
-
expect(body).to eq(
|
178
|
+
expect(body).to eq('this is about [redacted] [redacted].')
|
180
179
|
expect(TCellAgent.event_queue.length).to eq(2)
|
181
180
|
end
|
182
|
-
it
|
181
|
+
it 'Tests Report-Only and Events' do
|
183
182
|
action = TCellAgent::Policies::DataLossPolicy::FilterActions.new
|
184
183
|
action.log_event = true
|
185
184
|
action.action_id = 5
|
186
185
|
context = TCellData.new
|
187
|
-
context.add_response_db_filter(
|
188
|
-
context.add_response_db_filter(
|
189
|
-
context.add_response_db_filter(
|
190
|
-
context.add_response_db_filter(
|
191
|
-
context.add_response_db_filter(
|
192
|
-
context.add_response_db_filter(
|
193
|
-
context.add_response_db_filter(
|
194
|
-
context.add_response_db_filter(
|
195
|
-
context.add_response_db_filter(
|
196
|
-
context.add_response_db_filter(true, action,
|
197
|
-
body =
|
186
|
+
context.add_response_db_filter('timmy', action, 'don', 'sam', 'tim', 'fred')
|
187
|
+
context.add_response_db_filter('timmy23', action, 'don', 'sam', 'tim', 'fred')
|
188
|
+
context.add_response_db_filter('3123123', action, 'don', 'sam', 'tim', 'fred')
|
189
|
+
context.add_response_db_filter('tim123my', action, 'don', 'sam', 'tim', 'fred')
|
190
|
+
context.add_response_db_filter('timmy1', action, 'don', 'sam', 'tim', 'fred')
|
191
|
+
context.add_response_db_filter('tim123123my', action, 'don', 'sam', 'tim', 'fred')
|
192
|
+
context.add_response_db_filter('ti21312mmy', action, 'don', 'sam', 'tim', 'fred')
|
193
|
+
context.add_response_db_filter('ti123123mmy', action, 'don', 'sam', 'tim', 'fred')
|
194
|
+
context.add_response_db_filter(10_233_234, action, 'don', 'sam', 'tim', 'fred')
|
195
|
+
context.add_response_db_filter(true, action, 'don', 'sam', 'tim', 'fred')
|
196
|
+
body = 'this is about timmy1 3123123.'
|
198
197
|
TCellAgent.empty_event_queue
|
199
198
|
context.filter_log(body)
|
200
|
-
expect(body).to eq(
|
199
|
+
expect(body).to eq('this is about timmy1 3123123.')
|
201
200
|
expect(TCellAgent.event_queue.length).to eq(3) # timmy, timmy1, 3123123
|
202
201
|
end
|
203
202
|
end
|
@@ -2,160 +2,119 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module TCellAgent
|
4
4
|
module Instrumentation
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
describe '.block?' do
|
6
|
+
context 'with an unexpected error' do
|
7
|
+
it 'should return false' do
|
8
|
+
request = double('request')
|
9
|
+
expect(TCellAgent).to receive(:policy).with(
|
10
|
+
TCellAgent::PolicyTypes::Rust
|
11
|
+
).and_raise(StandardError.new('UNEXPECTED'))
|
12
12
|
expect(TCellAgent::Patches::MetaData).to_not receive(:build)
|
13
13
|
|
14
|
-
expect(Patches.block?(request)).to eq(
|
14
|
+
expect(Patches.block?(request)).to eq(false)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
context
|
19
|
-
it
|
20
|
-
request = double(
|
18
|
+
context 'with an empty patches policy' do
|
19
|
+
it 'should return false' do
|
20
|
+
request = double('request')
|
21
21
|
expect(TCellAgent).to receive(:policy).and_return(nil)
|
22
22
|
expect(TCellAgent::Patches::MetaData).to_not receive(:build)
|
23
23
|
|
24
|
-
expect(Patches.block?(request)).to eq(
|
24
|
+
expect(Patches.block?(request)).to eq(false)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
context
|
29
|
-
it
|
30
|
-
request = double(
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
})
|
36
|
-
expect(patches.enabled).to eq(false)
|
37
|
-
|
38
|
-
expect(TCellAgent).to receive(:policy).and_return(patches)
|
28
|
+
context 'with a disabled patches policy' do
|
29
|
+
it 'should return false' do
|
30
|
+
request = double('request')
|
31
|
+
rust_policies = TCellAgent::Policies::RustPolicies.new
|
32
|
+
expect(rust_policies.patches_enabled).to eq(false)
|
33
|
+
|
34
|
+
expect(TCellAgent).to receive(:policy).and_return(rust_policies)
|
39
35
|
expect(TCellAgent::Patches::MetaData).to_not receive(:build)
|
40
36
|
|
41
|
-
expect(Patches.block?(request)).to eq(
|
37
|
+
expect(Patches.block?(request)).to eq(false)
|
42
38
|
end
|
43
39
|
end
|
44
40
|
|
45
|
-
context
|
46
|
-
it
|
47
|
-
request = double(
|
48
|
-
meta_data = double(
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
expect(
|
55
|
-
|
56
|
-
|
41
|
+
context 'with a patches policy that does not apply' do
|
42
|
+
it 'should return false' do
|
43
|
+
request = double('request')
|
44
|
+
meta_data = double('meta_data')
|
45
|
+
rust_policies = TCellAgent::Policies::RustPolicies.new
|
46
|
+
tcell_context = TCellAgent::Instrumentation::TCellData.new
|
47
|
+
|
48
|
+
expect(TCellAgent).to receive(:policy).and_return(rust_policies)
|
49
|
+
expect(rust_policies).to receive(:patches_enabled).and_return(true)
|
50
|
+
expect(rust_policies).to receive(:block_request?).and_return(false)
|
51
|
+
expect(request).to receive(:env).and_return(
|
52
|
+
{
|
53
|
+
TCellAgent::Instrumentation::TCELL_ID => tcell_context
|
54
|
+
}
|
55
|
+
)
|
57
56
|
expect(TCellAgent::Patches::MetaData).to receive(:build).and_return(
|
58
57
|
meta_data
|
59
58
|
)
|
60
|
-
expect(meta_data).to receive(:remote_address).and_return("2.2.2.2")
|
61
59
|
|
62
|
-
expect(Patches.block?(request)).to eq(
|
60
|
+
expect(Patches.block?(request)).to eq(false)
|
61
|
+
expect(tcell_context.patches_blocking_triggered).to eq(false)
|
63
62
|
end
|
64
63
|
end
|
65
64
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
meta_data = double("meta_data")
|
65
|
+
context 'with a patches policy that applies' do
|
66
|
+
it 'should return a response' do
|
67
|
+
request = double('request')
|
68
|
+
meta_data = double('meta_data')
|
71
69
|
tcell_context = TCellAgent::Instrumentation::TCellData.new
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
expect(
|
78
|
-
expect(tcell_context.ip_blocking_triggered).to eq(false)
|
79
|
-
|
80
|
-
expect(TCellAgent).to receive(:policy).and_return(patches)
|
70
|
+
rust_policies = TCellAgent::Policies::RustPolicies.new
|
71
|
+
expect(tcell_context.patches_blocking_triggered).to eq(false)
|
72
|
+
|
73
|
+
expect(TCellAgent).to receive(:policy).and_return(rust_policies)
|
74
|
+
expect(rust_policies).to receive(:patches_enabled).and_return(true)
|
75
|
+
expect(rust_policies).to receive(:block_request?).and_return(true)
|
81
76
|
expect(TCellAgent::Patches::MetaData).to receive(:build).and_return(
|
82
77
|
meta_data
|
83
78
|
)
|
84
|
-
expect(
|
85
|
-
expect(request).to receive(:env).and_return({TCellAgent::Instrumentation::TCELL_ID => tcell_context})
|
79
|
+
expect(request).to receive(:env).and_return({ TCellAgent::Instrumentation::TCELL_ID => tcell_context })
|
86
80
|
|
87
|
-
expect(Patches.block?(request)).to eq(
|
81
|
+
expect(Patches.block?(request)).to eq(true)
|
88
82
|
|
89
|
-
expect(tcell_context.
|
83
|
+
expect(tcell_context.patches_blocking_triggered).to eq(true)
|
90
84
|
end
|
91
85
|
|
92
86
|
context "and that's complex" do
|
93
|
-
it
|
94
|
-
request = double(
|
87
|
+
it 'should return a response' do
|
88
|
+
request = double('request')
|
95
89
|
meta_data = TCellAgent::Patches::MetaData.new(
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
tcell_context = TCellAgent::Instrumentation::TCellData.new
|
104
|
-
patches = TCellAgent::Policies::PatchesPolicy.from_json({
|
105
|
-
"policy_id" => "policy_id",
|
106
|
-
"version" => 1,
|
107
|
-
"data" => {
|
108
|
-
"blocked_ips" => [{"ip" => "8.8.8.8"}],
|
109
|
-
"block_rules" => [
|
110
|
-
{"ips" => ["8.8.8.8"]},
|
111
|
-
{
|
112
|
-
"ips" => ["2.3.4.5"],
|
113
|
-
"sensor_matches" => {
|
114
|
-
"xss" => {"patterns" => ["1", "2", "3", "4", "5", "6", "7", "8"]}
|
115
|
-
}
|
116
|
-
}
|
117
|
-
]
|
118
|
-
}
|
119
|
-
})
|
120
|
-
expect(patches.enabled).to eq(true)
|
121
|
-
expect(tcell_context.ip_blocking_triggered).to eq(false)
|
122
|
-
|
123
|
-
expect(TCellAgent).to receive(:policy).and_return(patches)
|
124
|
-
expect(TCellAgent::Patches::MetaData).to receive(:build).and_return(
|
125
|
-
meta_data
|
90
|
+
'get',
|
91
|
+
'2.3.4.5',
|
92
|
+
'route_id',
|
93
|
+
'session_id',
|
94
|
+
'user_id',
|
95
|
+
'transaction_id',
|
96
|
+
'http://test.com/'
|
126
97
|
)
|
127
|
-
|
98
|
+
meta_data.get_dict = { 'paramater' => '<script>' }
|
99
|
+
tcell_context = TCellAgent::Instrumentation::TCellData.new
|
100
|
+
rust_policies = TCellAgent::Policies::RustPolicies.new
|
128
101
|
|
129
|
-
expect(
|
102
|
+
expect(tcell_context.patches_blocking_triggered).to eq(false)
|
130
103
|
|
131
|
-
expect(
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
context "with an unexpected error" do
|
136
|
-
it "should return nil" do
|
137
|
-
request = double("request")
|
138
|
-
meta_data = double("meta_data")
|
139
|
-
patches = TCellAgent::Policies::PatchesPolicy.from_json({
|
140
|
-
"policy_id" => "policy_id",
|
141
|
-
"version" => 1,
|
142
|
-
"data" => {"blocked_ips" => [{"ip" => "1.1.1.1"}]}
|
143
|
-
})
|
144
|
-
expect(patches.enabled).to eq(true)
|
145
|
-
|
146
|
-
expect(TCellAgent).to receive(:policy).with(TCellAgent::PolicyTypes::Patches).and_return(patches)
|
104
|
+
expect(TCellAgent).to receive(:policy).and_return(rust_policies)
|
105
|
+
expect(rust_policies).to receive(:patches_enabled).and_return(true)
|
106
|
+
expect(rust_policies).to receive(:block_request?).and_return(true)
|
147
107
|
expect(TCellAgent::Patches::MetaData).to receive(:build).and_return(
|
148
108
|
meta_data
|
149
109
|
)
|
150
|
-
expect(
|
151
|
-
|
110
|
+
expect(request).to receive(:env).and_return({ TCellAgent::Instrumentation::TCELL_ID => tcell_context })
|
111
|
+
|
112
|
+
expect(Patches.block?(request)).to eq(true)
|
152
113
|
|
153
|
-
expect(
|
114
|
+
expect(tcell_context.patches_blocking_triggered).to eq(true)
|
154
115
|
end
|
155
116
|
end
|
156
117
|
end
|
157
|
-
|
158
118
|
end
|
159
|
-
|
160
119
|
end
|
161
120
|
end
|