tcell_agent 0.4.0 → 1.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 (199) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +9 -22
  3. data/bin/tcell_agent +127 -132
  4. data/lib/tcell_agent/agent/event_processor.rb +23 -22
  5. data/lib/tcell_agent/agent/fork_pipe_manager.rb +7 -7
  6. data/lib/tcell_agent/agent/policy_manager.rb +20 -15
  7. data/lib/tcell_agent/agent/policy_types.rb +5 -11
  8. data/lib/tcell_agent/agent/static_agent.rb +5 -1
  9. data/lib/tcell_agent/agent.rb +6 -4
  10. data/lib/tcell_agent/api.rb +7 -9
  11. data/lib/tcell_agent/appsensor/meta_data.rb +11 -4
  12. data/lib/tcell_agent/authlogic.rb +3 -3
  13. data/lib/tcell_agent/cmdi.rb +6 -4
  14. data/lib/tcell_agent/config/unknown_options.rb +3 -1
  15. data/lib/tcell_agent/configuration.rb +47 -49
  16. data/lib/tcell_agent/devise.rb +2 -2
  17. data/lib/tcell_agent/hooks/login_fraud.rb +58 -29
  18. data/lib/tcell_agent/instrumentation.rb +11 -10
  19. data/lib/tcell_agent/logger.rb +2 -2
  20. data/lib/tcell_agent/patches/meta_data.rb +9 -13
  21. data/lib/tcell_agent/patches.rb +7 -10
  22. data/lib/tcell_agent/policies/clickjacking_policy.rb +4 -5
  23. data/lib/tcell_agent/policies/content_security_policy.rb +6 -12
  24. data/lib/tcell_agent/policies/dataloss_policy.rb +2 -2
  25. data/lib/tcell_agent/policies/http_redirect_policy.rb +2 -2
  26. data/lib/tcell_agent/policies/policy.rb +0 -2
  27. data/lib/tcell_agent/policies/rust_policies.rb +90 -0
  28. data/lib/tcell_agent/policies/secure_headers_policy.rb +2 -2
  29. data/lib/tcell_agent/rails/auth/authlogic.rb +42 -24
  30. data/lib/tcell_agent/rails/auth/devise.rb +44 -23
  31. data/lib/tcell_agent/rails/auth/doorkeeper.rb +33 -15
  32. data/lib/tcell_agent/rails/better_ip.rb +1 -1
  33. data/lib/tcell_agent/rails/csrf_exception.rb +2 -2
  34. data/lib/tcell_agent/rails/dlp/process_request.rb +1 -1
  35. data/lib/tcell_agent/rails/dlp.rb +6 -6
  36. data/lib/tcell_agent/rails/dlp_handler.rb +1 -1
  37. data/lib/tcell_agent/rails/js_agent_insert.rb +1 -1
  38. data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +1 -1
  39. data/lib/tcell_agent/rails/middleware/context_middleware.rb +3 -2
  40. data/lib/tcell_agent/rails/middleware/headers_middleware.rb +10 -9
  41. data/lib/tcell_agent/rails/routes/grape.rb +6 -6
  42. data/lib/tcell_agent/rails/routes.rb +8 -11
  43. data/lib/tcell_agent/rust/libtcellagent-0.11.1.dylib +0 -0
  44. data/lib/tcell_agent/rust/{libtcellagent-0.6.1.so → libtcellagent-0.11.1.so} +0 -0
  45. data/lib/tcell_agent/rust/models.rb +16 -0
  46. data/lib/tcell_agent/rust/tcellagent-0.11.1.dll +0 -0
  47. data/lib/tcell_agent/rust/whisperer.rb +119 -48
  48. data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +17 -20
  49. data/lib/tcell_agent/sensor_events/command_injection.rb +50 -5
  50. data/lib/tcell_agent/sensor_events/login_fraud.rb +34 -18
  51. data/lib/tcell_agent/sensor_events/patches.rb +21 -0
  52. data/lib/tcell_agent/sensor_events/server_agent.rb +3 -3
  53. data/lib/tcell_agent/sensor_events/util/utils.rb +4 -3
  54. data/lib/tcell_agent/servers/puma.rb +2 -2
  55. data/lib/tcell_agent/servers/unicorn.rb +1 -1
  56. data/lib/tcell_agent/utils/passwords.rb +28 -0
  57. data/lib/tcell_agent/version.rb +1 -1
  58. data/lib/tcell_agent.rb +1 -5
  59. data/spec/apps/rails-3.2/config/tcell_agent.config +15 -0
  60. data/spec/apps/rails-3.2/log/development.log +0 -0
  61. data/spec/apps/rails-3.2/log/test.log +12 -0
  62. data/spec/apps/rails-4.1/log/test.log +0 -0
  63. data/spec/lib/tcell_agent/agent/fork_pipe_manager_spec.rb +46 -45
  64. data/spec/lib/tcell_agent/agent/policy_manager_spec.rb +276 -164
  65. data/spec/lib/tcell_agent/agent/static_agent_spec.rb +44 -47
  66. data/spec/lib/tcell_agent/api/api_spec.rb +16 -16
  67. data/spec/lib/tcell_agent/appsensor/injections_reporter_spec.rb +131 -116
  68. data/spec/lib/tcell_agent/appsensor/meta_data_spec.rb +55 -51
  69. data/spec/lib/tcell_agent/cmdi_spec.rb +413 -436
  70. data/spec/lib/tcell_agent/config/unknown_options_spec.rb +145 -128
  71. data/spec/lib/tcell_agent/configuration_spec.rb +165 -169
  72. data/spec/lib/tcell_agent/hooks/login_fraud_spec.rb +144 -153
  73. data/spec/lib/tcell_agent/instrumentation_spec.rb +84 -85
  74. data/spec/lib/tcell_agent/patches_spec.rb +70 -111
  75. data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +313 -244
  76. data/spec/lib/tcell_agent/policies/clickjacking_policy_spec.rb +28 -28
  77. data/spec/lib/tcell_agent/policies/command_injection_policy_spec.rb +643 -513
  78. data/spec/lib/tcell_agent/policies/content_security_policy_spec.rb +55 -102
  79. data/spec/lib/tcell_agent/policies/dataloss_policy_spec.rb +111 -134
  80. data/spec/lib/tcell_agent/policies/http_redirect_policy_spec.rb +141 -146
  81. data/spec/lib/tcell_agent/policies/http_tx_policy_spec.rb +8 -8
  82. data/spec/lib/tcell_agent/policies/login_policy_spec.rb +15 -17
  83. data/spec/lib/tcell_agent/policies/patches_policy_spec.rb +231 -559
  84. data/spec/lib/tcell_agent/policies/secure_headers_policy_spec.rb +27 -27
  85. data/spec/lib/tcell_agent/rails/better_ip_spec.rb +30 -34
  86. data/spec/lib/tcell_agent/rails/logger_spec.rb +50 -49
  87. data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +182 -199
  88. data/spec/lib/tcell_agent/rails/middleware/dlp_middleware_spec.rb +110 -84
  89. data/spec/lib/tcell_agent/rails/middleware/global_middleware_spec.rb +107 -85
  90. data/spec/lib/tcell_agent/rails/middleware/redirect_middleware_spec.rb +68 -40
  91. data/spec/lib/tcell_agent/rails/middleware/tcell_body_proxy_spec.rb +81 -67
  92. data/spec/lib/tcell_agent/rails/responses_spec.rb +33 -37
  93. data/spec/lib/tcell_agent/rails/routes/grape_spec.rb +116 -121
  94. data/spec/lib/tcell_agent/rails/routes/route_id_spec.rb +25 -28
  95. data/spec/lib/tcell_agent/rails/routes/routes_spec.rb +87 -85
  96. data/spec/lib/tcell_agent/rails_spec.rb +1 -6
  97. data/spec/lib/tcell_agent/rust/models_spec.rb +112 -0
  98. data/spec/lib/tcell_agent/rust/whisperer_spec.rb +502 -179
  99. data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +44 -33
  100. data/spec/lib/tcell_agent/sensor_events/dlp_spec.rb +4 -4
  101. data/spec/lib/tcell_agent/sensor_events/sessions_metric_spec.rb +183 -169
  102. data/spec/lib/tcell_agent/sensor_events/util/sanitizer_utilities_spec.rb +25 -25
  103. data/spec/lib/tcell_agent/utils/bounded_queue_spec.rb +17 -20
  104. data/spec/lib/tcell_agent/utils/params_spec.rb +28 -28
  105. data/spec/lib/tcell_agent/utils/passwords_spec.rb +143 -0
  106. data/spec/lib/tcell_agent/utils/strings_spec.rb +35 -35
  107. data/spec/lib/tcell_agent_spec.rb +8 -8
  108. data/spec/spec_helper.rb +4 -4
  109. data/spec/support/middleware_helper.rb +10 -10
  110. data/spec/support/static_agent_overrides.rb +16 -12
  111. data/tcell_agent.gemspec +17 -33
  112. metadata +43 -198
  113. data/LICENSE_libinjection +0 -32
  114. data/Readme.txt +0 -7
  115. data/ext/libinjection/extconf.rb +0 -3
  116. data/ext/libinjection/libinjection.h +0 -65
  117. data/ext/libinjection/libinjection_html5.c +0 -847
  118. data/ext/libinjection/libinjection_html5.h +0 -54
  119. data/ext/libinjection/libinjection_sqli.c +0 -2317
  120. data/ext/libinjection/libinjection_sqli.h +0 -295
  121. data/ext/libinjection/libinjection_sqli_data.h +0 -9004
  122. data/ext/libinjection/libinjection_wrap.c +0 -3525
  123. data/ext/libinjection/libinjection_xss.c +0 -531
  124. data/ext/libinjection/libinjection_xss.h +0 -21
  125. data/lib/tcell_agent/appsensor/injections_matcher.rb +0 -155
  126. data/lib/tcell_agent/appsensor/rules/appsensor_rule_manager.rb +0 -49
  127. data/lib/tcell_agent/appsensor/rules/appsensor_rule_set.rb +0 -67
  128. data/lib/tcell_agent/appsensor/rules/baserules.json +0 -467
  129. data/lib/tcell_agent/patches/block_rule.rb +0 -93
  130. data/lib/tcell_agent/patches/sensors_matcher.rb +0 -31
  131. data/lib/tcell_agent/policies/appsensor/cmdi_sensor.rb +0 -23
  132. data/lib/tcell_agent/policies/appsensor/fpt_sensor.rb +0 -23
  133. data/lib/tcell_agent/policies/appsensor/injection_sensor.rb +0 -117
  134. data/lib/tcell_agent/policies/appsensor/nullbyte_sensor.rb +0 -26
  135. data/lib/tcell_agent/policies/appsensor/retr_sensor.rb +0 -22
  136. data/lib/tcell_agent/policies/appsensor/sqli_sensor.rb +0 -34
  137. data/lib/tcell_agent/policies/appsensor/xss_sensor.rb +0 -34
  138. data/lib/tcell_agent/policies/appsensor_policy.rb +0 -49
  139. data/lib/tcell_agent/policies/command_injection_policy.rb +0 -196
  140. data/lib/tcell_agent/policies/honeytokens_policy.rb +0 -69
  141. data/lib/tcell_agent/policies/patches_policy.rb +0 -84
  142. data/lib/tcell_agent/rust/libtcellagent-0.6.1.dylib +0 -0
  143. data/lib/tcell_agent/rust/tcellagent-0.6.1.dll +0 -0
  144. data/spec/apps/rails-3.2/Gemfile +0 -25
  145. data/spec/apps/rails-3.2/Gemfile.lock +0 -126
  146. data/spec/apps/rails-3.2/Rakefile +0 -7
  147. data/spec/apps/rails-3.2/app/assets/images/rails.png +0 -0
  148. data/spec/apps/rails-3.2/app/assets/javascripts/application.js +0 -15
  149. data/spec/apps/rails-3.2/app/assets/stylesheets/application.css +0 -13
  150. data/spec/apps/rails-3.2/app/controllers/application_controller.rb +0 -3
  151. data/spec/apps/rails-3.2/app/controllers/t_cell_app_controller.rb +0 -5
  152. data/spec/apps/rails-3.2/app/helpers/application_helper.rb +0 -2
  153. data/spec/apps/rails-3.2/app/views/layouts/application.html.erb +0 -14
  154. data/spec/apps/rails-3.2/app/views/t_cell_app/index.html.erb +0 -1
  155. data/spec/apps/rails-3.2/config/application.rb +0 -63
  156. data/spec/apps/rails-3.2/config/boot.rb +0 -6
  157. data/spec/apps/rails-3.2/config/environment.rb +0 -5
  158. data/spec/apps/rails-3.2/config/environments/test.rb +0 -37
  159. data/spec/apps/rails-3.2/config/routes.rb +0 -11
  160. data/spec/apps/rails-3.2/config.ru +0 -4
  161. data/spec/apps/rails-4.1/Gemfile +0 -7
  162. data/spec/apps/rails-4.1/Gemfile.lock +0 -114
  163. data/spec/apps/rails-4.1/Rakefile +0 -6
  164. data/spec/apps/rails-4.1/app/assets/javascripts/application.js +0 -16
  165. data/spec/apps/rails-4.1/app/assets/stylesheets/application.css +0 -15
  166. data/spec/apps/rails-4.1/app/controllers/application_controller.rb +0 -5
  167. data/spec/apps/rails-4.1/app/controllers/t_cell_app_controller.rb +0 -5
  168. data/spec/apps/rails-4.1/app/helpers/application_helper.rb +0 -2
  169. data/spec/apps/rails-4.1/app/views/layouts/application.html.erb +0 -14
  170. data/spec/apps/rails-4.1/app/views/t_cell_app/index.html.erb +0 -1
  171. data/spec/apps/rails-4.1/config/application.rb +0 -24
  172. data/spec/apps/rails-4.1/config/boot.rb +0 -4
  173. data/spec/apps/rails-4.1/config/environment.rb +0 -5
  174. data/spec/apps/rails-4.1/config/environments/test.rb +0 -41
  175. data/spec/apps/rails-4.1/config/initializers/assets.rb +0 -8
  176. data/spec/apps/rails-4.1/config/initializers/backtrace_silencers.rb +0 -7
  177. data/spec/apps/rails-4.1/config/initializers/cookies_serializer.rb +0 -3
  178. data/spec/apps/rails-4.1/config/initializers/filter_parameter_logging.rb +0 -4
  179. data/spec/apps/rails-4.1/config/initializers/inflections.rb +0 -16
  180. data/spec/apps/rails-4.1/config/initializers/mime_types.rb +0 -4
  181. data/spec/apps/rails-4.1/config/initializers/session_store.rb +0 -3
  182. data/spec/apps/rails-4.1/config/initializers/wrap_parameters.rb +0 -14
  183. data/spec/apps/rails-4.1/config/locales/en.yml +0 -23
  184. data/spec/apps/rails-4.1/config/routes.rb +0 -12
  185. data/spec/apps/rails-4.1/config/secrets.yml +0 -22
  186. data/spec/apps/rails-4.1/config.ru +0 -4
  187. data/spec/controllers/application_controller.rb +0 -12
  188. data/spec/lib/tcell_agent/appsensor/injections_matcher_spec.rb +0 -522
  189. data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_manager_spec.rb +0 -23
  190. data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_set_spec.rb +0 -159
  191. data/spec/lib/tcell_agent/patches/block_rule_spec.rb +0 -458
  192. data/spec/lib/tcell_agent/patches/sensors_matcher_spec.rb +0 -35
  193. data/spec/lib/tcell_agent/policies/appsensor/cmdi_sensor_spec.rb +0 -139
  194. data/spec/lib/tcell_agent/policies/appsensor/fpt_sensor_spec.rb +0 -139
  195. data/spec/lib/tcell_agent/policies/appsensor/nullbyte_sensor_spec.rb +0 -167
  196. data/spec/lib/tcell_agent/policies/appsensor/retr_sensor_spec.rb +0 -139
  197. data/spec/lib/tcell_agent/policies/appsensor/sqli_sensor_spec.rb +0 -246
  198. data/spec/lib/tcell_agent/policies/appsensor/xss_sensor_spec.rb +0 -882
  199. data/spec/lib/tcell_agent/policies/honeytokens_policy_spec.rb +0 -22
@@ -1,159 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module TCellAgent
4
-
5
- describe AppSensorRuleSet do
6
-
7
- describe "#add_pattern_from_dict" do
8
- context "adding from nil dict" do
9
- it "should do nothing" do
10
- rule_set = AppSensorRuleSet.new
11
- rule_set.add_pattern_from_dict(nil)
12
- expect(rule_set.safe_pattern).to eq(nil)
13
- expect(rule_set.patterns).to eq([])
14
- end
15
- end
16
-
17
- context "adding from empty dict" do
18
- it "should do nothing" do
19
- rule_set = AppSensorRuleSet.new
20
- rule_set.add_pattern_from_dict({})
21
- expect(rule_set.safe_pattern).to eq(nil)
22
- expect(rule_set.patterns).to eq([])
23
- end
24
- end
25
-
26
- context "adding a ruby pattern" do
27
- it "should add the pattern" do
28
- rule_set = AppSensorRuleSet.new
29
- rule_set.add_pattern_from_dict({
30
- "id" => "1",
31
- "common" => "<(iframe)",
32
- "ruby" => "<(script)"
33
- })
34
-
35
- expect(rule_set.safe_pattern).to eq(nil)
36
- expect(rule_set.patterns.size).to eq(1)
37
-
38
- arp = rule_set.patterns[0]
39
- expect(arp.enabled).to eq(true)
40
- expect(arp.pattern_id).to eq("1")
41
- expect(arp.pattern_regex).to_not eq(nil)
42
- expect("<script".match(arp.pattern_regex).captures).to eq(["script"])
43
- end
44
- end
45
-
46
- context "adding a common pattern" do
47
- it "should add the pattern" do
48
- rule_set = AppSensorRuleSet.new
49
- rule_set.add_pattern_from_dict({
50
- "id" => "1",
51
- "common" => "<(script|iframe|embed|frame|frameset|object|img|applet|body|html|style|layer|link|ilayer|meta|bgsound)"
52
- })
53
-
54
- expect(rule_set.safe_pattern).to eq(nil)
55
- expect(rule_set.patterns.size).to eq(1)
56
-
57
- arp = rule_set.patterns[0]
58
- expect(arp.enabled).to eq(true)
59
- expect(arp.pattern_id).to eq("1")
60
- expect(arp.pattern_regex).to_not eq(nil)
61
- expect("<script".match(arp.pattern_regex).captures).to eq(["script"])
62
- end
63
- end
64
- end
65
-
66
- describe "#set_safe_pattern_from_string" do
67
- it "should set the safe pattern" do
68
- rule_set = AppSensorRuleSet.new
69
- rule_set.set_safe_pattern_from_string("^[a-zA-Z0-9_\s\r\n\t]*$")
70
-
71
- expect(rule_set.safe_pattern).to eq(Regexp.new("^[a-zA-Z0-9_\s\r\n\t]*$"))
72
- expect(rule_set.patterns.size).to eq(0)
73
- end
74
- end
75
-
76
- describe "#check_violation" do
77
- before(:each) do
78
- @rule_set = AppSensorRuleSet.new
79
- @rule_set.set_safe_pattern_from_string("super_safe")
80
- @rule_set.add_pattern_from_dict({
81
- "id" => "1",
82
- "common" => "<(script)"
83
- })
84
- @rule_set.add_pattern_from_dict({
85
- "id" => "2",
86
- "common" => "<(iframe)"
87
- })
88
- end
89
-
90
- context "param value is nil" do
91
- it "should return nil" do
92
- expect(@rule_set.check_violation(nil, nil, Set.new, true)).to eq(nil)
93
- end
94
- end
95
-
96
- context "param value is empty" do
97
- it "should return nil" do
98
- expect(@rule_set.check_violation(nil, nil, Set.new, true)).to eq(nil)
99
- end
100
- end
101
-
102
- context "param value is present" do
103
- context "param value matches safe pattern" do
104
- it "should return nil" do
105
- expect(@rule_set.check_violation("param_name", "super_safe", Set.new, true)).to eq(nil)
106
- end
107
- end
108
-
109
- context "param value does not match anything" do
110
- it "should return nil" do
111
- expect(@rule_set.check_violation("param_name", "weeee", Set.new, true)).to eq(nil)
112
- end
113
- end
114
-
115
- context "param value matches a pattern" do
116
- it "should return the match" do
117
- match_data = @rule_set.check_violation("param_name", "evil <script>", Set.new, true)
118
- expect(match_data).to eq({"param"=>"param_name", "value"=>"evil <script>", "pattern"=>"1"})
119
- end
120
-
121
- context "uppercasing param value still matches pattern" do
122
- it "should return the match" do
123
- match_data = @rule_set.check_violation("param_name", "evil <SCRIPT>", Set.new, true)
124
- expect(match_data).to eq({"param"=>"param_name", "value"=>"evil <SCRIPT>", "pattern"=>"1"})
125
- end
126
- end
127
- end
128
-
129
- context "v1_compatability is off" do
130
- context "all patterns are disabled" do
131
- context "param value contains evil pattern" do
132
- it "should return nil" do
133
- match_data = @rule_set.check_violation("param_name", "evil <script>", Set.new, false)
134
- expect(match_data).to eq(nil)
135
- end
136
- end
137
- end
138
-
139
- context "one pattern is disabled" do
140
- context "evil param_value matches disabled pattern" do
141
- it "should return nil" do
142
- match_data = @rule_set.check_violation("param_name", "evil <script>", Set.new(["2"]), false)
143
- expect(match_data).to eq(nil)
144
- end
145
- end
146
-
147
- context "evil param_value matches enabled pattern" do
148
- it "should return the match" do
149
- match_data = @rule_set.check_violation("param_name", "evil <iframe>", Set.new(["2"]), false)
150
- expect(match_data).to eq({"param"=>"param_name", "value"=>"evil <iframe>", "pattern"=>"2"})
151
- end
152
- end
153
- end
154
- end
155
- end
156
- end
157
- end
158
-
159
- end
@@ -1,458 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module TCellAgent
4
- module Patches
5
-
6
- describe "BlockRule" do
7
-
8
- describe ".from_json" do
9
- context "empty action provided" do
10
- it "should return nil" do
11
- logger = double("logger")
12
- expect(TCellAgent).to receive(:logger).and_return(logger)
13
- expect(logger).to receive(:error).with("Patches Policy action not supported: ")
14
-
15
- expect(BlockRule.from_json({"action" => nil})).to eq(nil)
16
- end
17
- end
18
-
19
- context "unknown action provided" do
20
- it "should return nil" do
21
- logger = double("logger")
22
- expect(TCellAgent).to receive(:logger).and_return(logger)
23
- expect(logger).to receive(:error).with("Patches Policy action not supported: bogus")
24
-
25
- expect(BlockRule.from_json({"action" => "bogus"})).to eq(nil)
26
- end
27
- end
28
-
29
- context "with no ips or rids provided" do
30
- it "should return nil" do
31
- logger = double("logger")
32
- expect(TCellAgent).to receive(:logger).and_return(logger)
33
- expect(logger).to receive(:error).with("Patches Policy block rule cannot be global. Specify either ips and/or route ids or blocked paths")
34
-
35
- expect(BlockRule.from_json({"action" => "block_403s"})).to eq(nil)
36
- end
37
- end
38
-
39
- context "with all the fields provided" do
40
- it "should create a block rule properly" do
41
- policy_json = {
42
- "ips" => ["1.1.1.1", "1.3.3.3"],
43
- "rids" => ["1396482959514716287","1396482959514716237"],
44
- "paths" => [{"exact" => "/index/"}, {"starts_with" => "/admin"}],
45
- "sensor_matches" => {
46
- "xss" => {}
47
- },
48
- "action" => "block_403s"
49
- }
50
-
51
- block_rule = BlockRule.from_json(policy_json)
52
-
53
- expect(block_rule.ips).to eq(Set.new(["1.1.1.1", "1.3.3.3"]))
54
- expect(block_rule.rids).to eq(Set.new(["1396482959514716287", "1396482959514716237"]))
55
- expect(block_rule.action).to eq("block_403s")
56
- expect(block_rule.sensors_matcher.injections_matcher.enabled).to eq(true)
57
- expect(block_rule.sensors_matcher.injections_matcher.sensors.size).to eq(1)
58
- expect(block_rule.sensors_matcher.injections_matcher.sensors[0].active_pattern_ids).to eq(Set.new)
59
- expect(block_rule.exact_blocked_paths).to eq(Set.new(["/index", "/index/"]))
60
- expect(block_rule.starts_with_blocked_paths).to eq(["/admin"])
61
- end
62
- end
63
- end
64
-
65
- describe "#block?" do
66
-
67
- context "with empty ips" do
68
- context "with empty rids" do
69
- # from_json prevents this case
70
- end
71
-
72
- context "with an rid" do
73
- context "that matches the request" do
74
- before(:each) do
75
- @meta_data = TCellAgent::Patches::MetaData.new(
76
- "get",
77
- "1.1.1.1",
78
- "route_id",
79
- "session_id",
80
- "user_id",
81
- "transaction_id")
82
- end
83
-
84
- context "with empty sensors" do
85
- it "should return true" do
86
- injections_matcher = double("injections_matcher")
87
-
88
- block_rule = BlockRule.new(
89
- Set.new,
90
- Set.new(["route_id"]),
91
- SensorsMatcher.new(injections_matcher),
92
- "block_403s",
93
- Set.new,
94
- []
95
- )
96
-
97
- expect(injections_matcher).to receive(:enabled).and_return(false)
98
-
99
- expect(block_rule.block?(@meta_data)).to eq(true)
100
- end
101
- end
102
-
103
- context "with sensors" do
104
- context "that don't have a match" do
105
- it "should return false" do
106
- injections_matcher = double("injections_matcher")
107
-
108
- block_rule = BlockRule.new(
109
- Set.new,
110
- Set.new(["route_id"]),
111
- SensorsMatcher.new(injections_matcher),
112
- "block_403s",
113
- Set.new,
114
- []
115
- )
116
-
117
- expect(injections_matcher).to receive(:enabled).and_return(true)
118
- expect(injections_matcher).to receive(:each_injection)
119
-
120
- expect(block_rule.block?(@meta_data)).to eq(false)
121
- end
122
- end
123
-
124
- context "that have a match" do
125
- it "should return true" do
126
- injections_matcher = double("injections_matcher")
127
-
128
- block_rule = BlockRule.new(
129
- Set.new,
130
- Set.new(["route_id"]),
131
- SensorsMatcher.new(injections_matcher),
132
- "block_403s",
133
- Set.new,
134
- []
135
- )
136
-
137
- expect(injections_matcher).to receive(:enabled).and_return(true)
138
- expect(injections_matcher).to receive(:each_injection) do |md, &block|
139
- block.call(double("injection_attempt"))
140
- end
141
-
142
- expect(block_rule.block?(@meta_data)).to eq(true)
143
- end
144
- end
145
- end
146
- end
147
-
148
- context "that does not match the request" do
149
- before(:each) do
150
- @meta_data = TCellAgent::Patches::MetaData.new(
151
- "get",
152
- "1.1.1.1",
153
- "non_matching_route_id",
154
- "session_id",
155
- "user_id",
156
- "transaction_id")
157
- end
158
-
159
- context "with empty sensors" do
160
- it "should return false" do
161
- injections_matcher = double("injections_matcher")
162
-
163
- block_rule = BlockRule.new(
164
- Set.new,
165
- Set.new(["route_id"]),
166
- SensorsMatcher.new(injections_matcher),
167
- "block_403s",
168
- Set.new,
169
- []
170
- )
171
-
172
- expect(injections_matcher).to_not receive(:enabled)
173
-
174
- expect(block_rule.block?(@meta_data)).to eq(false)
175
- end
176
- end
177
-
178
- context "with sensors" do
179
- context "that don't have a match" do
180
- it "should return false" do
181
- injections_matcher = double("injections_matcher")
182
-
183
- block_rule = BlockRule.new(
184
- Set.new,
185
- Set.new(["route_id"]),
186
- SensorsMatcher.new(injections_matcher),
187
- "block_403s",
188
- Set.new,
189
- []
190
- )
191
-
192
- expect(injections_matcher).to_not receive(:enabled)
193
-
194
- expect(block_rule.block?(@meta_data)).to eq(false)
195
- end
196
- end
197
-
198
- context "that have a match" do
199
- it "should return false" do
200
- injections_matcher = double("injections_matcher")
201
-
202
- block_rule = BlockRule.new(
203
- Set.new,
204
- Set.new(["route_id"]),
205
- SensorsMatcher.new(injections_matcher),
206
- "block_403s",
207
- Set.new,
208
- []
209
- )
210
-
211
- expect(injections_matcher).to_not receive(:enabled)
212
-
213
- expect(block_rule.block?(@meta_data)).to eq(false)
214
- end
215
- end
216
- end
217
- end
218
- end
219
- end
220
-
221
- context "with ips" do
222
- before(:each) do
223
- @meta_data = TCellAgent::Patches::MetaData.new(
224
- "get",
225
- "1.1.1.1",
226
- "route_id",
227
- "session_id",
228
- "user_id",
229
- "transaction_id")
230
- end
231
-
232
- context "that does not match the request" do
233
- it "should return false" do
234
- injections_matcher = double("injections_matcher")
235
-
236
- block_rule = BlockRule.new(
237
- Set.new(["2.2.2.2"]),
238
- Set.new(["route_id"]),
239
- SensorsMatcher.new(injections_matcher),
240
- "block_403s",
241
- Set.new,
242
- []
243
- )
244
-
245
- expect(injections_matcher).to_not receive(:enabled)
246
-
247
- expect(block_rule.block?(@meta_data)).to eq(false)
248
- end
249
- end
250
-
251
- context "that matches the request" do
252
- context "with an rid" do
253
- context "that matches the request" do
254
- context "with empty sensors" do
255
- it "should return true" do
256
- injections_matcher = double("injections_matcher")
257
-
258
- block_rule = BlockRule.new(
259
- Set.new(["1.1.1.1"]),
260
- Set.new(["route_id"]),
261
- SensorsMatcher.new(injections_matcher),
262
- "block_403s",
263
- Set.new,
264
- []
265
- )
266
-
267
- expect(injections_matcher).to receive(:enabled).and_return(false)
268
-
269
- expect(block_rule.block?(@meta_data)).to eq(true)
270
- end
271
- end
272
-
273
- context "with sensors" do
274
- context "that don't have a match" do
275
- it "should return false" do
276
- injections_matcher = double("injections_matcher")
277
-
278
- block_rule = BlockRule.new(
279
- Set.new(["1.1.1.1"]),
280
- Set.new(["route_id"]),
281
- SensorsMatcher.new(injections_matcher),
282
- "block_403s",
283
- Set.new,
284
- []
285
- )
286
-
287
- expect(injections_matcher).to receive(:enabled).and_return(true)
288
- expect(injections_matcher).to receive(:each_injection)
289
-
290
- expect(block_rule.block?(@meta_data)).to eq(false)
291
- end
292
- end
293
-
294
- context "that have a match" do
295
- it "should return true" do
296
- injections_matcher = double("injections_matcher")
297
-
298
- block_rule = BlockRule.new(
299
- Set.new(["1.1.1.1"]),
300
- Set.new(["route_id"]),
301
- SensorsMatcher.new(injections_matcher),
302
- "block_403s",
303
- Set.new,
304
- []
305
- )
306
-
307
- expect(injections_matcher).to receive(:enabled).and_return(true)
308
- expect(injections_matcher).to receive(:each_injection) do |md, &block|
309
- block.call(double("injection_attempt"))
310
- end
311
-
312
- expect(block_rule.block?(@meta_data)).to eq(true)
313
- end
314
- end
315
- end
316
- end
317
-
318
- context "that does not match the request" do
319
- before(:each) do
320
- @meta_data.route_id = "non_matching_route_id"
321
- end
322
- context "with empty sensors" do
323
- it "should return false" do
324
- injections_matcher = double("injections_matcher")
325
-
326
- block_rule = BlockRule.new(
327
- Set.new(["1.1.1.1"]),
328
- Set.new(["route_id"]),
329
- SensorsMatcher.new(injections_matcher),
330
- "block_403s",
331
- Set.new,
332
- []
333
- )
334
-
335
- expect(injections_matcher).to_not receive(:enabled)
336
-
337
- expect(block_rule.block?(@meta_data)).to eq(false)
338
- end
339
- end
340
-
341
- context "with sensors" do
342
- context "that don't have a match" do
343
- it "should return false" do
344
- injections_matcher = double("injections_matcher")
345
-
346
- block_rule = BlockRule.new(
347
- Set.new(["1.1.1.1"]),
348
- Set.new(["route_id"]),
349
- SensorsMatcher.new(injections_matcher),
350
- "block_403s",
351
- Set.new,
352
- []
353
- )
354
-
355
- expect(injections_matcher).to_not receive(:enabled)
356
-
357
- expect(block_rule.block?(@meta_data)).to eq(false)
358
- end
359
- end
360
-
361
- context "that have a match" do
362
- it "should return false" do
363
- injections_matcher = double("injections_matcher")
364
-
365
- block_rule = BlockRule.new(
366
- Set.new(["1.1.1.1"]),
367
- Set.new(["route_id"]),
368
- SensorsMatcher.new(injections_matcher),
369
- "block_403s",
370
- Set.new,
371
- []
372
- )
373
-
374
- expect(injections_matcher).to_not receive(:enabled)
375
-
376
- expect(block_rule.block?(@meta_data)).to eq(false)
377
- end
378
- end
379
- end
380
- end
381
- end
382
- end
383
- end
384
-
385
- context "with blocked paths" do
386
- before(:each) do
387
- @meta_data = TCellAgent::Patches::MetaData.new(
388
- "get",
389
- "1.1.1.1",
390
- "route_id",
391
- "session_id",
392
- "user_id",
393
- "transaction_id")
394
- end
395
-
396
- context "without ips" do
397
- context "matching paths" do
398
- it "should block" do
399
- injections_matcher = double("injections_matcher")
400
-
401
- block_rule = BlockRule.new(
402
- Set.new(["1.1.1.1"]),
403
- Set.new(["route_id"]),
404
- SensorsMatcher.new(injections_matcher),
405
- "block_403s",
406
- Set.new(["/index", "/index/"]),
407
- ["/admin"]
408
- )
409
-
410
- expect(injections_matcher).to_not receive(:enabled)
411
-
412
- @meta_data.path = "/index"
413
- expect(block_rule.block?(@meta_data)).to eq(true)
414
-
415
- @meta_data.path = "/index/"
416
- expect(block_rule.block?(@meta_data)).to eq(true)
417
-
418
- @meta_data.path = "/admin"
419
- expect(block_rule.block?(@meta_data)).to eq(true)
420
-
421
- @meta_data.path = "/admin/users"
422
- expect(block_rule.block?(@meta_data)).to eq(true)
423
- end
424
- end
425
-
426
- context "not matching blocking paths" do
427
- it "should not block" do
428
- injections_matcher = double("injections_matcher")
429
-
430
- block_rule = BlockRule.new(
431
- Set.new(["1.1.1.1"]),
432
- Set.new(["route_id"]),
433
- SensorsMatcher.new(injections_matcher),
434
- "block_403s",
435
- Set.new(["/index", "/index/"]),
436
- ["/admin"]
437
- )
438
-
439
- expect(injections_matcher).to_not receive(:enabled)
440
-
441
- @meta_data.path = "/index/subpath"
442
- expect(block_rule.block?(@meta_data)).to eq(false)
443
-
444
- @meta_data.path = "/welcome"
445
- expect(block_rule.block?(@meta_data)).to eq(false)
446
-
447
- @meta_data.path = "/welcome/"
448
- expect(block_rule.block?(@meta_data)).to eq(false)
449
- end
450
- end
451
- end
452
- end
453
- end
454
-
455
- end
456
-
457
- end
458
- end
@@ -1,35 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module TCellAgent
4
- module Patches
5
-
6
- describe "SensorsMatcher" do
7
- describe ".from_json" do
8
- context "with all the fields provided" do
9
- it "should create a sensor matcher properly" do
10
- sensor_matcher_json = {
11
- "xss" => {
12
- "libinjection" => true,
13
- "exclude_cookies" => false,
14
- "exclude_forms" => false,
15
- "exclusions" => {"generic" => ["form", "cookies"]},
16
- "patterns" => ["1", "2"]
17
- }
18
- }
19
-
20
- sensor_matcher = SensorsMatcher.from_json(sensor_matcher_json)
21
-
22
- sorted_sensors = sensor_matcher.injections_matcher.sensors.sort
23
-
24
- expect(sorted_sensors.size).to eq(1)
25
- expect(sorted_sensors[0].libinjection).to eq(true)
26
- expect(sorted_sensors[0].exclude_cookies).to eq(false)
27
- expect(sorted_sensors[0].exclude_forms).to eq(false)
28
- expect(sorted_sensors[0].exclusions).to eq({"generic" => Set.new(["form", "cookies"])})
29
- end
30
- end
31
- end
32
- end
33
-
34
- end
35
- end