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
@@ -8,60 +8,53 @@ module TCellAgent
|
|
8
8
|
module Instrumentation
|
9
9
|
module Rails
|
10
10
|
module Middleware
|
11
|
-
|
12
|
-
|
13
11
|
class MockDLPRackApp
|
14
|
-
|
15
12
|
attr_reader :request_body
|
16
13
|
|
17
|
-
def initialize(body=
|
14
|
+
def initialize(body = 'OK', route_id = nil, session_id = nil)
|
18
15
|
@route_id = route_id
|
19
16
|
@session_id = session_id
|
20
17
|
@request_headers = {}
|
21
18
|
@body = body
|
22
19
|
end
|
23
20
|
|
24
|
-
def loop_params_hash(method, param_hash,
|
21
|
+
def loop_params_hash(method, param_hash, _prefix, &block)
|
25
22
|
param_hash.each do |param_name, param_value|
|
26
23
|
if param_value && param_value.is_a?(Hash)
|
27
24
|
loop_params_hash(method, param_value, 'hash', &block)
|
28
|
-
elsif !param_value || !param_value.instance_of?(String) || param_value ==
|
25
|
+
elsif !param_value || !param_value.instance_of?(String) || param_value == ''
|
29
26
|
next
|
30
27
|
else
|
31
|
-
|
28
|
+
yield(method, param_name, param_value)
|
32
29
|
end
|
33
30
|
end
|
34
31
|
end
|
35
32
|
|
36
33
|
def for_params(request, &block)
|
37
34
|
get_params = request.GET
|
38
|
-
if get_params
|
39
|
-
self.loop_params_hash('get', get_params, nil, &block)
|
40
|
-
end
|
35
|
+
loop_params_hash('get', get_params, nil, &block) if get_params
|
41
36
|
post_params = request.POST
|
42
|
-
if post_params
|
43
|
-
|
44
|
-
end
|
45
|
-
end
|
37
|
+
loop_params_hash('post', post_params, nil, &block) if post_params
|
38
|
+
end
|
46
39
|
|
47
40
|
def call(env)
|
48
41
|
@env = env
|
49
42
|
rack_request = Rack::Request.new(env)
|
50
|
-
response_headers = {'Content-Type' => 'text/html'}
|
51
|
-
env[
|
52
|
-
env[
|
53
|
-
env[
|
54
|
-
tcell_context = env[
|
43
|
+
response_headers = { 'Content-Type' => 'text/html' }
|
44
|
+
env['tcell.request_data'].transaction_id = 'a-b-c-d-e-f'
|
45
|
+
env['tcell.request_data'].session_id = @session_id
|
46
|
+
env['tcell.request_data'].route_id = @route_id
|
47
|
+
tcell_context = env['tcell.request_data']
|
55
48
|
dlp_policy = TCellAgent.policy(TCellAgent::PolicyTypes::DataLoss)
|
56
49
|
if dlp_policy
|
57
|
-
action_objs = dlp_policy.get_actions_for_table(
|
50
|
+
action_objs = dlp_policy.get_actions_for_table('*', '*', 'tablex', 'columnb', tcell_context.route_id)
|
58
51
|
if action_objs
|
59
52
|
action_objs.each do |action_obj|
|
60
|
-
tcell_context.add_response_db_filter(
|
53
|
+
tcell_context.add_response_db_filter('secretvalue', action_obj, 'databx', '*', 'tablex', 'columnb')
|
61
54
|
end
|
62
55
|
end
|
63
56
|
TCellAgent::DLP.handle_request_dlp_parameters(rack_request)
|
64
|
-
#if tcell_context && dlp_policy && dlp_policy.has_actions_for_form_parameter?
|
57
|
+
# if tcell_context && dlp_policy && dlp_policy.has_actions_for_form_parameter?
|
65
58
|
# for_params(rack_request) { |method, param_name, param_value|
|
66
59
|
# actions = dlp_policy.get_actions_for_form_parameter(param_name, tcell_context.route_id)
|
67
60
|
# if actions
|
@@ -71,7 +64,7 @@ module TCellAgent
|
|
71
64
|
# }
|
72
65
|
# end
|
73
66
|
# }
|
74
|
-
#end
|
67
|
+
# end
|
75
68
|
end
|
76
69
|
tcell_context.filter_body!(@body)
|
77
70
|
[200, response_headers, [@body]]
|
@@ -80,92 +73,125 @@ module TCellAgent
|
|
80
73
|
def [](key)
|
81
74
|
@env[key]
|
82
75
|
end
|
83
|
-
|
84
76
|
end
|
85
77
|
|
86
78
|
describe HeadersMiddleware do
|
87
|
-
|
88
79
|
let(:app) { MockDLPRackApp.new }
|
89
|
-
let(:app2) { MockDLPRackApp.new(
|
80
|
+
let(:app2) { MockDLPRackApp.new('My secretvalue othervalue test', 'myrouteid', 'plainsessionid') }
|
90
81
|
|
91
|
-
subject {
|
82
|
+
subject { with_tcell_middleware(app) }
|
92
83
|
|
93
|
-
context
|
84
|
+
context 'DLP Middleware' do
|
94
85
|
before(:each) do
|
95
86
|
TCellAgent.configuration = TCellAgent::Configuration.new
|
96
|
-
TCellAgent.configuration.read_config_from_file(get_test_resource_path(
|
87
|
+
TCellAgent.configuration.read_config_from_file(get_test_resource_path('normal_config.json'))
|
97
88
|
end
|
98
89
|
let(:request) { Rack::MockRequest.new(subject) }
|
99
|
-
let(:request2) { Rack::MockRequest.new(
|
90
|
+
let(:request2) { Rack::MockRequest.new(with_tcell_middleware(app2)) }
|
100
91
|
let(:agent) { ::TCellAgent::Agent.new }
|
101
|
-
context
|
92
|
+
context 'Event' do
|
102
93
|
before(:each) do
|
103
|
-
TCellAgent.thread_agent.processPolicyJson(
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
94
|
+
TCellAgent.thread_agent.processPolicyJson(
|
95
|
+
{
|
96
|
+
'dlp' => {
|
97
|
+
'policy_id' => 'x1a1',
|
98
|
+
'data' => {
|
99
|
+
'db_protections' => [
|
100
|
+
{
|
101
|
+
'scope' => 'route',
|
102
|
+
'route_ids' => ['myrouteid'],
|
103
|
+
'databases' => ['*'],
|
104
|
+
'schemas' => ['*'],
|
105
|
+
'tables' => ['tablex'],
|
106
|
+
'fields' => ['columnb'],
|
107
|
+
'id' => '323213',
|
108
|
+
'actions' => {
|
109
|
+
'log' => ['redact'],
|
110
|
+
'body' => ['redact']
|
111
|
+
}
|
118
112
|
}
|
119
|
-
|
120
|
-
|
113
|
+
]
|
114
|
+
}
|
121
115
|
}
|
122
|
-
}
|
116
|
+
},
|
117
|
+
false
|
118
|
+
)
|
123
119
|
TCellAgent.empty_event_queue
|
124
120
|
end
|
125
|
-
it
|
126
|
-
response = request2.get(
|
127
|
-
|
128
|
-
|
129
|
-
|
121
|
+
it 'redacts body' do
|
122
|
+
response = request2.get(
|
123
|
+
'/some/path2?x=abc',
|
124
|
+
'CONTENT_TYPE' => 'text/html',
|
125
|
+
'REMOTE_ADDR' => '1.3.3.4,3.4.5.6'
|
126
|
+
)
|
127
|
+
expect(response.body).to eq('My [redacted] othervalue test')
|
128
|
+
# expect(response['Location']).to eq("https://www.google.com")
|
129
|
+
expected_as = {
|
130
|
+
'event_type' => 'dlp',
|
131
|
+
'rid' => 'myrouteid',
|
132
|
+
'found_in' => 'body',
|
133
|
+
'rule' => '323213',
|
134
|
+
'type' => 'db',
|
135
|
+
'db' => 'databx',
|
136
|
+
'schema' => '*',
|
137
|
+
'table' => 'tablex',
|
138
|
+
'field' => 'columnb',
|
139
|
+
'uri' => 'http://example.org/some/path2?x='
|
140
|
+
}
|
130
141
|
expect(TCellAgent.event_queue).to include(expected_as)
|
131
142
|
end
|
132
|
-
end
|
133
|
-
|
143
|
+
end
|
134
144
|
|
135
|
-
context
|
145
|
+
context 'Event for request dlp' do
|
136
146
|
before(:each) do
|
137
|
-
TCellAgent.thread_agent.processPolicyJson(
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
{
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
147
|
+
TCellAgent.thread_agent.processPolicyJson(
|
148
|
+
{
|
149
|
+
'dlp' => {
|
150
|
+
'policy_id' => 'x1a1',
|
151
|
+
'data' => {
|
152
|
+
'request_protections' => [
|
153
|
+
{
|
154
|
+
'variable_context' => 'form',
|
155
|
+
'scope' => 'route',
|
156
|
+
'route_ids' => ['myrouteid'],
|
157
|
+
'variables' => ['test333'],
|
158
|
+
'id' => '08080808',
|
159
|
+
'actions' => {
|
160
|
+
'log' => ['redact'],
|
161
|
+
'body' => ['event']
|
162
|
+
}
|
163
|
+
}
|
164
|
+
]
|
151
165
|
}
|
152
|
-
|
153
|
-
}
|
154
|
-
|
166
|
+
}
|
167
|
+
},
|
168
|
+
false
|
169
|
+
)
|
155
170
|
TCellAgent.empty_event_queue
|
156
171
|
end
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
172
|
+
|
173
|
+
it 'redacts body' do
|
174
|
+
response = request2.get(
|
175
|
+
'/some/path2?test333=othervalue',
|
176
|
+
'CONTENT_TYPE' => 'text/html',
|
177
|
+
'REMOTE_ADDR' => '1.3.3.4,3.4.5.6'
|
178
|
+
)
|
179
|
+
expect(response.body).to eq('My secretvalue othervalue test')
|
180
|
+
expected_as = {
|
181
|
+
'event_type' => 'dlp',
|
182
|
+
'rid' => 'myrouteid',
|
183
|
+
'found_in' => 'body',
|
184
|
+
'rule' => '08080808',
|
185
|
+
'type' => 'req',
|
186
|
+
'context' => 'form',
|
187
|
+
'variable' => 'test333',
|
188
|
+
'uri' => 'http://example.org/some/path2?test333='
|
189
|
+
}
|
161
190
|
expect(TCellAgent.event_queue).to include(expected_as)
|
162
191
|
end
|
163
|
-
end
|
164
|
-
|
165
|
-
|
166
|
-
end #/describe
|
167
|
-
|
168
|
-
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
169
195
|
end
|
170
196
|
end
|
171
197
|
end
|
@@ -6,9 +6,7 @@ module TCellAgent
|
|
6
6
|
module Instrumentation
|
7
7
|
module Rails
|
8
8
|
module Middleware
|
9
|
-
|
10
9
|
class MockRackApp
|
11
|
-
|
12
10
|
attr_reader :request_body
|
13
11
|
|
14
12
|
def initialize
|
@@ -19,138 +17,163 @@ module TCellAgent
|
|
19
17
|
@env = env
|
20
18
|
@request_body = env['rack.input'].read
|
21
19
|
rack_request = Rack::Request.new(env)
|
22
|
-
response_headers = {'Content-Type' => 'text/html'}
|
23
|
-
if
|
24
|
-
response_headers[
|
20
|
+
response_headers = { 'Content-Type' => 'text/html' }
|
21
|
+
if rack_request.params['rv']
|
22
|
+
response_headers['Location'] = rack_request.params['rv']
|
25
23
|
end
|
26
|
-
env[
|
27
|
-
#env["tcell.request_data"].route_id = "x-b-c-d-e-f"
|
24
|
+
env['tcell.request_data'].transaction_id = 'a-b-c-d-e-f'
|
25
|
+
# env["tcell.request_data"].route_id = "x-b-c-d-e-f"
|
28
26
|
[200, response_headers, ['OK']]
|
29
27
|
end
|
30
28
|
|
31
29
|
def [](key)
|
32
30
|
@env[key]
|
33
31
|
end
|
34
|
-
|
35
32
|
end
|
36
33
|
|
37
34
|
describe HeadersMiddleware do
|
38
|
-
|
39
35
|
let(:app) { MockRackApp.new }
|
40
|
-
subject {
|
36
|
+
subject { with_tcell_middleware(app) }
|
41
37
|
|
42
|
-
context
|
38
|
+
context 'Redirect Middleware' do
|
43
39
|
let(:request) { Rack::MockRequest.new(subject) }
|
44
40
|
let(:agent) { ::TCellAgent::Agent.new(Process.pid) }
|
45
41
|
before(:each) do
|
46
42
|
TCellAgent.configuration = TCellAgent::Configuration.new
|
47
|
-
TCellAgent.configuration.read_config_from_file(get_test_resource_path(
|
43
|
+
TCellAgent.configuration.read_config_from_file(get_test_resource_path('normal_config.json'))
|
48
44
|
|
49
45
|
# avoid running start_policy_polling for these specs
|
50
|
-
expect(agent).to receive(:
|
46
|
+
expect(agent).to receive(:start_policy_polling_loop).at_most(50)
|
51
47
|
|
52
48
|
agent.start
|
53
49
|
TCellAgent.thread_agent = agent
|
54
50
|
end
|
55
51
|
|
56
|
-
context
|
57
|
-
it
|
58
|
-
agent.processPolicyJson(
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
52
|
+
context 'not enabled' do
|
53
|
+
it 'passes through unchanged' do
|
54
|
+
agent.processPolicyJson(
|
55
|
+
{
|
56
|
+
'http-redirect' => {
|
57
|
+
'policy_id' => '153ed270-7481-11e5-9194-95dad9b9dec3',
|
58
|
+
'data' => {
|
59
|
+
'enabled' => false,
|
60
|
+
'block' => true,
|
61
|
+
'whitelist' => []
|
62
|
+
}
|
63
|
+
}
|
64
|
+
},
|
65
|
+
false
|
66
|
+
)
|
67
|
+
response = request.get('/some/path?rv=https://www.google.com', 'CONTENT_TYPE' => 'text/html')
|
68
|
+
expect(response['Location']).to eq('https://www.google.com')
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
72
|
context "doesn't block simple whitelist" do
|
73
|
-
it
|
74
|
-
agent.processPolicyJson(
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
73
|
+
it 'passes through unchanged' do
|
74
|
+
agent.processPolicyJson(
|
75
|
+
{
|
76
|
+
'http-redirect' => {
|
77
|
+
'policy_id' => '153ed270-7481-11e5-9194-95dad9b9dec3',
|
78
|
+
'data' => {
|
79
|
+
'enabled' => true,
|
80
|
+
'block' => true,
|
81
|
+
'whitelist' => ['www.google.com']
|
82
|
+
}
|
83
|
+
}
|
84
|
+
},
|
85
|
+
false
|
86
|
+
)
|
87
|
+
|
88
|
+
response = request.get('/some/path?rv=https://www.google.com', 'CONTENT_TYPE' => 'text/html')
|
89
|
+
expect(response['Location']).to eq('https://www.google.com')
|
86
90
|
end
|
87
91
|
end
|
88
92
|
|
89
93
|
context "doesn't block wildcard whitelist" do
|
90
|
-
it
|
91
|
-
agent.processPolicyJson(
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
94
|
+
it 'passes through unchanged' do
|
95
|
+
agent.processPolicyJson(
|
96
|
+
{
|
97
|
+
'http-redirect' => {
|
98
|
+
'policy_id' => '153ed270-7481-11e5-9194-95dad9b9dec3',
|
99
|
+
'data' => {
|
100
|
+
'enabled' => true,
|
101
|
+
'block' => true,
|
102
|
+
'whitelist' => ['*.google.com']
|
103
|
+
}
|
104
|
+
}
|
105
|
+
},
|
106
|
+
false
|
107
|
+
)
|
108
|
+
response = request.get('/some/path?rv=https://www.google.com', 'CONTENT_TYPE' => 'text/html')
|
109
|
+
expect(response['Location']).to eq('https://www.google.com')
|
101
110
|
end
|
102
111
|
end
|
103
112
|
|
104
|
-
context
|
105
|
-
it
|
106
|
-
agent.processPolicyJson(
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
113
|
+
context 'DOES block wildcard whitelist' do
|
114
|
+
it 'replaces the value with /' do
|
115
|
+
agent.processPolicyJson(
|
116
|
+
{
|
117
|
+
'http-redirect' => {
|
118
|
+
'policy_id' => '153ed270-7481-11e5-9194-95dad9b9dec3',
|
119
|
+
'data' => {
|
120
|
+
'enabled' => true,
|
121
|
+
'block' => true,
|
122
|
+
'whitelist' => ['*.google-test.com']
|
123
|
+
}
|
124
|
+
}
|
125
|
+
},
|
126
|
+
false
|
127
|
+
)
|
128
|
+
|
129
|
+
response = request.get('/some/path?rv=https://www.google.com', 'CONTENT_TYPE' => 'text/html')
|
130
|
+
expect(response['Location']).to eq('/')
|
118
131
|
end
|
119
132
|
end
|
120
|
-
|
121
133
|
end
|
122
134
|
|
123
|
-
context
|
135
|
+
context 'CSP Middleware' do
|
124
136
|
let(:request) { Rack::MockRequest.new(subject) }
|
125
137
|
let(:agent) { ::TCellAgent::Agent.new(Process.pid) }
|
126
138
|
|
127
139
|
before(:each) do
|
128
140
|
TCellAgent.configuration = TCellAgent::Configuration.new
|
129
|
-
TCellAgent.configuration.read_config_from_file(get_test_resource_path(
|
141
|
+
TCellAgent.configuration.read_config_from_file(get_test_resource_path('normal_config.json'))
|
130
142
|
|
131
143
|
# avoid running start_policy_polling for these specs
|
132
|
-
expect(agent).to receive(:
|
144
|
+
expect(agent).to receive(:start_policy_polling_loop).at_most(50)
|
133
145
|
|
134
146
|
agent.start
|
135
147
|
TCellAgent.thread_agent = agent
|
136
148
|
end
|
137
149
|
|
138
|
-
context
|
139
|
-
it
|
140
|
-
agent.processPolicyJson(
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
150
|
+
context 'Standard CSP Header' do
|
151
|
+
it 'CSP Header is Added' do
|
152
|
+
agent.processPolicyJson(
|
153
|
+
{
|
154
|
+
'csp-headers' => {
|
155
|
+
'policy_id' => '153ed270-7481-11e5-9194-95dad9b9dec3',
|
156
|
+
'headers' => [
|
157
|
+
{
|
158
|
+
'name' => 'Content-Security-Policy-Report-Only',
|
159
|
+
'value' => "script-src 'unsafe-inline'",
|
160
|
+
'report-uri' => 'http://test.tcell.io/report'
|
161
|
+
}
|
162
|
+
]
|
163
|
+
}
|
164
|
+
},
|
165
|
+
false
|
166
|
+
)
|
167
|
+
response = request.get(
|
168
|
+
'/some/path',
|
169
|
+
'CONTENT_TYPE' => 'text/plain',
|
170
|
+
'action_dispatch.request_id' => '35281717-247e-44e6-bd42-0fb1417e80d'
|
171
|
+
)
|
172
|
+
expect(response['Content-Security-Policy-Report-Only']).to eq(
|
173
|
+
"script-src 'unsafe-inline'; report-uri http://test.tcell.io/report?tid=a-b-c-d-e-f&c=-654192056"
|
174
|
+
)
|
151
175
|
end
|
152
176
|
end
|
153
|
-
|
154
177
|
end
|
155
178
|
|
156
179
|
# context "when called with a POST request" do
|
@@ -172,10 +195,10 @@ module TCellAgent
|
|
172
195
|
# "value"=>"script-src 'unsafe-inline'",
|
173
196
|
# "report-uri"=>"http://test.tcell.io/report"
|
174
197
|
# }
|
175
|
-
# }})
|
198
|
+
# }})
|
176
199
|
|
177
200
|
# #noop = Proc.new {[200, {}, ["hello"]]}
|
178
|
-
# #middleware = ActionDispatch::Static.new(noop, "/my_rails_app/public")
|
201
|
+
# #middleware = ActionDispatch::Static.new(noop, "/my_rails_app/public")
|
179
202
|
# #request = Rack::MockRequest.new(middleware)
|
180
203
|
# #puts request.get("/path_i_want_to_hit")
|
181
204
|
|
@@ -188,7 +211,6 @@ module TCellAgent
|
|
188
211
|
# end
|
189
212
|
# end
|
190
213
|
end
|
191
|
-
|
192
214
|
end
|
193
215
|
end
|
194
216
|
end
|