tcell_agent 0.2.12 → 0.2.13

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 (79) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tcell_agent.rb +2 -2
  3. data/lib/tcell_agent/agent/policy_manager.rb +1 -1
  4. data/lib/tcell_agent/api.rb +2 -2
  5. data/lib/tcell_agent/appsensor/rules/appsensor_rule_manager.rb +46 -0
  6. data/lib/tcell_agent/appsensor/rules/appsensor_rule_set.rb +67 -0
  7. data/lib/tcell_agent/appsensor/rules/baserules.json +153 -0
  8. data/lib/tcell_agent/configuration.rb +7 -1
  9. data/lib/tcell_agent/instrumentation.rb +3 -0
  10. data/lib/tcell_agent/logger.rb +25 -3
  11. data/lib/tcell_agent/policies/appsensor/cmdi_sensor.rb +19 -0
  12. data/lib/tcell_agent/policies/appsensor/fpt_sensor.rb +19 -0
  13. data/lib/tcell_agent/policies/appsensor/injection_sensor.rb +136 -0
  14. data/lib/tcell_agent/policies/appsensor/login_sensor.rb +42 -0
  15. data/lib/tcell_agent/policies/appsensor/nullbyte_sensor.rb +22 -0
  16. data/lib/tcell_agent/policies/appsensor/request_size_sensor.rb +21 -0
  17. data/lib/tcell_agent/policies/appsensor/response_codes_sensor.rb +58 -0
  18. data/lib/tcell_agent/policies/appsensor/response_size_sensor.rb +21 -0
  19. data/lib/tcell_agent/policies/appsensor/retr_sensor.rb +18 -0
  20. data/lib/tcell_agent/policies/appsensor/sensor.rb +28 -0
  21. data/lib/tcell_agent/policies/appsensor/size_sensor.rb +43 -0
  22. data/lib/tcell_agent/policies/appsensor/sqli_sensor.rb +25 -0
  23. data/lib/tcell_agent/policies/appsensor/xss_sensor.rb +26 -0
  24. data/lib/tcell_agent/policies/appsensor_policy.rb +198 -67
  25. data/lib/tcell_agent/policies/clickjacking_policy.rb +1 -1
  26. data/lib/tcell_agent/policies/content_security_policy.rb +1 -1
  27. data/lib/tcell_agent/policies/dataloss_policy.rb +1 -1
  28. data/lib/tcell_agent/policies/honeytokens_policy.rb +1 -1
  29. data/lib/tcell_agent/policies/http_redirect_policy.rb +1 -1
  30. data/lib/tcell_agent/policies/http_tx_policy.rb +1 -1
  31. data/lib/tcell_agent/policies/login_fraud_policy.rb +1 -1
  32. data/lib/tcell_agent/policies/secure_headers_policy.rb +1 -1
  33. data/lib/tcell_agent/rails.rb +0 -1
  34. data/lib/tcell_agent/rails/auth/devise.rb +0 -1
  35. data/lib/tcell_agent/rails/dlp.rb +58 -13
  36. data/lib/tcell_agent/rails/middleware/body_filter_middleware.rb +0 -1
  37. data/lib/tcell_agent/rails/middleware/context_middleware.rb +0 -1
  38. data/lib/tcell_agent/rails/middleware/global_middleware.rb +0 -1
  39. data/lib/tcell_agent/rails/middleware/headers_middleware.rb +6 -34
  40. data/lib/tcell_agent/sensor_events/appsensor_event.rb +59 -0
  41. data/lib/tcell_agent/sensor_events/appsensor_meta_event.rb +95 -0
  42. data/lib/tcell_agent/servers/rails_server.rb +18 -9
  43. data/lib/tcell_agent/utils/params.rb +40 -0
  44. data/lib/tcell_agent/version.rb +1 -1
  45. data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_manager_spec.rb +39 -0
  46. data/spec/lib/tcell_agent/appsensor/rules/appsensor_rule_set_spec.rb +152 -0
  47. data/spec/lib/tcell_agent/instrumentation_spec.rb +4 -4
  48. data/spec/lib/tcell_agent/policies/appsensor/cmdi_sensor_spec.rb +128 -0
  49. data/spec/lib/tcell_agent/policies/appsensor/fpt_sensor_spec.rb +128 -0
  50. data/spec/lib/tcell_agent/policies/appsensor/login_sensor_spec.rb +104 -0
  51. data/spec/lib/tcell_agent/policies/appsensor/nullbyte_sensor_spec.rb +132 -0
  52. data/spec/lib/tcell_agent/policies/appsensor/request_size_sensor_spec.rb +164 -0
  53. data/spec/lib/tcell_agent/policies/appsensor/response_codes_sensor_spec.rb +194 -0
  54. data/spec/lib/tcell_agent/policies/appsensor/response_size_sensor_spec.rb +157 -0
  55. data/spec/lib/tcell_agent/policies/appsensor/retr_sensor_spec.rb +128 -0
  56. data/spec/lib/tcell_agent/policies/appsensor/sqli_sensor_spec.rb +151 -0
  57. data/spec/lib/tcell_agent/policies/appsensor/xss_sensor_spec.rb +652 -0
  58. data/spec/lib/tcell_agent/policies/appsensor_policy_spec.rb +461 -28
  59. data/spec/lib/tcell_agent/policies/clickjacking_policy_spec.rb +4 -4
  60. data/spec/lib/tcell_agent/policies/content_security_policy_spec.rb +6 -6
  61. data/spec/lib/tcell_agent/policies/dataloss_policy_spec.rb +10 -10
  62. data/spec/lib/tcell_agent/policies/honeytokens_policy_spec.rb +1 -1
  63. data/spec/lib/tcell_agent/policies/http_redirect_policy_spec.rb +1 -1
  64. data/spec/lib/tcell_agent/policies/http_tx_policy_spec.rb +1 -1
  65. data/spec/lib/tcell_agent/policies/login_policy_spec.rb +2 -2
  66. data/spec/lib/tcell_agent/policies/secure_headers_policy_spec.rb +4 -4
  67. data/spec/lib/tcell_agent/rails/middleware/appsensor_middleware_spec.rb +67 -7
  68. data/spec/lib/tcell_agent/sensor_events/appsensor_meta_event_spec.rb +80 -0
  69. data/spec/lib/tcell_agent/utils/params_spec.rb +119 -0
  70. data/spec/support/resources/baserules.json +155 -0
  71. metadata +51 -12
  72. data/lib/tcell_agent/appsensor.rb +0 -42
  73. data/lib/tcell_agent/appsensor/cmdi.rb +0 -32
  74. data/lib/tcell_agent/appsensor/path_traversal.rb +0 -33
  75. data/lib/tcell_agent/appsensor/sqli.rb +0 -55
  76. data/lib/tcell_agent/appsensor/xss.rb +0 -40
  77. data/lib/tcell_agent/sensor_events/app_sensor.rb +0 -302
  78. data/spec/lib/tcell_agent/appsensor_spec.rb +0 -65
  79. data/spec/lib/tcell_agent/sensor_events/tcell_app_sensor_event_processor_spec.rb +0 -289
@@ -9,7 +9,7 @@ module TCellAgent
9
9
  {"name"=>"csp", "value"=>"csp header value"}
10
10
  ]
11
11
  }
12
- csp_from_json = ClickjackingPolicy.fromJson(content_security_policy_json)
12
+ csp_from_json = ClickjackingPolicy.from_json(content_security_policy_json)
13
13
  context "initialized with 3 items" do
14
14
  it "returns true" do
15
15
  expect(csp_from_json.policy_id).to eq("00a1")
@@ -30,7 +30,7 @@ module TCellAgent
30
30
  {"name"=>"csp-header-is-bad", "value"=>"csp header value"}
31
31
  ]
32
32
  }
33
- csp_policy = ClickjackingPolicy.fromJson(content_security_policy_json)
33
+ csp_policy = ClickjackingPolicy.from_json(content_security_policy_json)
34
34
  context "csp header example, invalid header" do
35
35
  it "returns false" do
36
36
  expect(csp_policy.headers.length).to eq(0)
@@ -44,7 +44,7 @@ module TCellAgent
44
44
  {"name"=>"csp", "value"=>"value123\\nabc"}
45
45
  ]
46
46
  }
47
- csp_policy = ClickjackingPolicy.fromJson(content_security_policy_json)
47
+ csp_policy = ClickjackingPolicy.from_json(content_security_policy_json)
48
48
  context "secure header, value is bad" do
49
49
  it "returns false" do
50
50
  expect(csp_policy.headers.length).to eq(0)
@@ -58,7 +58,7 @@ module TCellAgent
58
58
  {"name"=>"csp", "value"=>"value normal", "report-uri"=>"https://example.com/abcdde"}
59
59
  ]
60
60
  }
61
- csp_policy = ClickjackingPolicy.fromJson(content_security_policy_json)
61
+ csp_policy = ClickjackingPolicy.from_json(content_security_policy_json)
62
62
  context "secure header, report-uri seperate" do
63
63
  it "returns false" do
64
64
  expect(csp_policy.headers.length).to eq(1)
@@ -21,7 +21,7 @@ module TCellAgent
21
21
  }
22
22
  }
23
23
 
24
- empty_policy = ContentSecurityPolicy.fromJson(policy_json_empty)
24
+ empty_policy = ContentSecurityPolicy.from_json(policy_json_empty)
25
25
  context "test empty agent" do
26
26
  it "enabled is false" do
27
27
  expect(empty_policy.policy_id).to eq("01a1")
@@ -29,7 +29,7 @@ module TCellAgent
29
29
  end
30
30
  end
31
31
 
32
- from_json = ContentSecurityPolicy.fromJson(policy_json_one)
32
+ from_json = ContentSecurityPolicy.from_json(policy_json_one)
33
33
  context "tests xss is true and enabled true" do
34
34
  it "returns true" do
35
35
  expect(from_json.policy_id).to eq("01a1")
@@ -44,7 +44,7 @@ module TCellAgent
44
44
  {"name"=>"csp", "value"=>"csp header value"}
45
45
  ]
46
46
  }
47
- csp_from_json = ContentSecurityPolicy.fromJson(content_security_policy_json)
47
+ csp_from_json = ContentSecurityPolicy.from_json(content_security_policy_json)
48
48
  context "initialized with 3 items" do
49
49
  it "returns true" do
50
50
  expect(csp_from_json.policy_id).to eq("00a1")
@@ -65,7 +65,7 @@ module TCellAgent
65
65
  {"name"=>"csp-header-is-bad", "value"=>"csp header value"}
66
66
  ]
67
67
  }
68
- csp_policy = ContentSecurityPolicy.fromJson(content_security_policy_json)
68
+ csp_policy = ContentSecurityPolicy.from_json(content_security_policy_json)
69
69
  context "csp header example, invalid header" do
70
70
  it "returns false" do
71
71
  expect(csp_policy.headers.length).to eq(0)
@@ -79,7 +79,7 @@ module TCellAgent
79
79
  {"name"=>"csp", "value"=>"value123\\nabc"}
80
80
  ]
81
81
  }
82
- csp_policy = ContentSecurityPolicy.fromJson(content_security_policy_json)
82
+ csp_policy = ContentSecurityPolicy.from_json(content_security_policy_json)
83
83
  context "secure header, value is bad" do
84
84
  it "returns false" do
85
85
  expect(csp_policy.headers.length).to eq(0)
@@ -93,7 +93,7 @@ module TCellAgent
93
93
  {"name"=>"csp", "value"=>"value normal", "report-uri"=>"https://example.com/abcdde"}
94
94
  ]
95
95
  }
96
- csp_policy = ContentSecurityPolicy.fromJson(content_security_policy_json)
96
+ csp_policy = ContentSecurityPolicy.from_json(content_security_policy_json)
97
97
  context "secure header, report-uri seperate" do
98
98
  it "returns false" do
99
99
  expect(csp_policy.headers.length).to eq(1)
@@ -18,7 +18,7 @@ module TCellAgent
18
18
  ]
19
19
  }
20
20
  }
21
- policy = DataLossPolicy.fromJson(policy_json)
21
+ policy = DataLossPolicy.from_json(policy_json)
22
22
  # context "initialized with 3 items" do
23
23
  # it "returns true" do
24
24
  # expect(policy.get_actions_for("user","ssn")).to eq(["body_redact"].to_set)
@@ -30,7 +30,7 @@ module TCellAgent
30
30
  "session_id_protections"=>{"body"=>["redact"], "log"=>["event"]}
31
31
  }
32
32
  }
33
- policy_two = DataLossPolicy.fromJson(policy_json_two)
33
+ policy_two = DataLossPolicy.from_json(policy_json_two)
34
34
  context "check session_id_protections" do
35
35
  it "gives the right actions" do
36
36
  expect(policy_two.get_actions_for_session_id.body_redact).to eq(true)
@@ -57,7 +57,7 @@ module TCellAgent
57
57
  ]
58
58
  }
59
59
  }
60
- db_one_policy = DataLossPolicy.fromJson(policy_json_requests)
60
+ db_one_policy = DataLossPolicy.from_json(policy_json_requests)
61
61
  expect(db_one_policy.get_actions_for_table("dave","sam","tommy","fred")).to eq(nil)
62
62
  end
63
63
  it "Partial Policy" do
@@ -76,7 +76,7 @@ module TCellAgent
76
76
  ]
77
77
  }
78
78
  }
79
- db_one_policy = DataLossPolicy.fromJson(policy_json_requests)
79
+ db_one_policy = DataLossPolicy.from_json(policy_json_requests)
80
80
  expect((db_one_policy.get_actions_for_table("dave","sam","tommy","fred").to_a)[0].log_redact).to eq(true)
81
81
  expect((db_one_policy.get_actions_for_table("dave","sam","tommy","fred","abcd").to_a)[0].log_redact).to eq(true)
82
82
  end
@@ -100,7 +100,7 @@ module TCellAgent
100
100
  ]
101
101
  }
102
102
  }
103
- db_two_policy = DataLossPolicy.fromJson(policy_json_request_ids)
103
+ db_two_policy = DataLossPolicy.from_json(policy_json_request_ids)
104
104
  expect((db_two_policy.get_actions_for_table("dave","sam","tommy","fred").to_a).size).to eq(0)
105
105
  expect((db_two_policy.get_actions_for_table("dave","sam","tommy","fred","other_route").to_a).size).to eq(0)
106
106
  expect((db_two_policy.get_actions_for_table("dave","sam","tommy","fred","abcd").to_a).size).to eq(1)
@@ -129,7 +129,7 @@ module TCellAgent
129
129
  ]
130
130
  }
131
131
  }
132
- policy_three = DataLossPolicy.fromJson(policy_json_requests)
132
+ policy_three = DataLossPolicy.from_json(policy_json_requests)
133
133
  expect(policy_three.get_actions_for_request("form","test123").to_a[0].body_event).to eq(true)
134
134
  expect(policy_three.get_actions_for_request("form","test123").to_a[0].log_event).to eq(nil)
135
135
  end
@@ -151,7 +151,7 @@ module TCellAgent
151
151
  ]
152
152
  }
153
153
  }
154
- policy_three = DataLossPolicy.fromJson(policy_json_requests)
154
+ policy_three = DataLossPolicy.from_json(policy_json_requests)
155
155
  entry_wildcard_route = policy_three.get_actions_for_request("form","TeSt123")
156
156
  entry_given_route = policy_three.get_actions_for_request("form","TeSt123","routex")
157
157
  expect(entry_wildcard_route).to eq(nil)
@@ -178,7 +178,7 @@ module TCellAgent
178
178
  ]
179
179
  }
180
180
  }
181
- policy_three = DataLossPolicy.fromJson(policy_json_requests)
181
+ policy_three = DataLossPolicy.from_json(policy_json_requests)
182
182
  entry_wildcard_route = policy_three.get_actions_for_request("cookie","test123")
183
183
  entry_given_route = policy_three.get_actions_for_request("cookie","test123","routex")
184
184
  expect(entry_wildcard_route).to eq(nil)
@@ -205,7 +205,7 @@ module TCellAgent
205
205
  ]
206
206
  }
207
207
  }
208
- policy_three = DataLossPolicy.fromJson(policy_json_requests)
208
+ policy_three = DataLossPolicy.from_json(policy_json_requests)
209
209
  entry_wildcard_route = policy_three.get_actions_for_request("cookie","test123")
210
210
  entry_given_route = policy_three.get_actions_for_request("cookie","test123","routex")
211
211
  expect(entry_wildcard_route).to eq(nil)
@@ -230,7 +230,7 @@ module TCellAgent
230
230
  ]
231
231
  }
232
232
  }
233
- policy_three = DataLossPolicy.fromJson(policy_json_requests)
233
+ policy_three = DataLossPolicy.from_json(policy_json_requests)
234
234
  entry_wildcard_route = policy_three.get_actions_for_request("header","TeSt123")
235
235
  entry_given_route = policy_three.get_actions_for_request("header","TeSt123","routex")
236
236
  expect(entry_wildcard_route).to eq(nil)
@@ -10,7 +10,7 @@ module TCellAgent
10
10
  {"type"=>"cred", "token"=>"TOKEN", "id"=>"ID001"}
11
11
  ]
12
12
  }
13
- policy = HoneytokensPolicy.fromJson(policy_json)
13
+ policy = HoneytokensPolicy.from_json(policy_json)
14
14
  context "initialized with 3 items" do
15
15
  it "returns true" do
16
16
  expect(policy.policy_id).to eq("x1a1")
@@ -16,7 +16,7 @@ module TCellAgent
16
16
  "enabled"=>true
17
17
  }
18
18
  }
19
- http_redirect_from_json = HttpRedirectPolicy.fromJson(http_redirect_policy_json)
19
+ http_redirect_from_json = HttpRedirectPolicy.from_json(http_redirect_policy_json)
20
20
  context "initialized with 3 items" do
21
21
  it "returns true" do
22
22
  expect(http_redirect_from_json.policy_id).to eq("x1a1")
@@ -9,7 +9,7 @@ module TCellAgent
9
9
  "firehose"=>{"enabled"=>true}
10
10
  }
11
11
  }
12
- http_tx_from_json = HttpTxPolicy.fromJson(http_tx_policy_json)
12
+ http_tx_from_json = HttpTxPolicy.from_json(http_tx_policy_json)
13
13
  context "initialized with 3 items" do
14
14
  it "returns true" do
15
15
  expect(http_tx_from_json.policy_id).to eq("01a1")
@@ -22,7 +22,7 @@ module TCellAgent
22
22
  }
23
23
  }
24
24
 
25
- empty_policy = LoginFraudPolicy.fromJson(policy_json_empty)
25
+ empty_policy = LoginFraudPolicy.from_json(policy_json_empty)
26
26
  context "test empty agent" do
27
27
  it "enabled is false" do
28
28
  expect(empty_policy.policy_id).to eq("01a1")
@@ -32,7 +32,7 @@ module TCellAgent
32
32
  end
33
33
  end
34
34
 
35
- policy_one = LoginFraudPolicy.fromJson(policy_json_one)
35
+ policy_one = LoginFraudPolicy.from_json(policy_json_one)
36
36
  context "enabled agent" do
37
37
  it "enabled is true" do
38
38
  expect(empty_policy.policy_id).to eq("01a1")
@@ -9,7 +9,7 @@ module TCellAgent
9
9
  {"name"=>"x-permitted-cross-domain-policies", "value"=>"value123"}
10
10
  ]
11
11
  }
12
- secure_headers_policy = SecureHeadersPolicy.fromJson(secure_headers_policy_json)
12
+ secure_headers_policy = SecureHeadersPolicy.from_json(secure_headers_policy_json)
13
13
  context "secure header example" do
14
14
  it "returns true" do
15
15
  expect(secure_headers_policy.headers[0].name).to eq("x-permitted-cross-domain-policies")
@@ -25,7 +25,7 @@ module TCellAgent
25
25
  {"name"=>"x-xss-protection", "value"=>"1; mode=block"}
26
26
  ]
27
27
  }
28
- secure_headers_policy = SecureHeadersPolicy.fromJson(secure_headers_policy_json)
28
+ secure_headers_policy = SecureHeadersPolicy.from_json(secure_headers_policy_json)
29
29
  context "secure headers (2) example" do
30
30
  it "returns true" do
31
31
  expect(secure_headers_policy.headers[0].name).to eq("x-frame-options")
@@ -42,7 +42,7 @@ module TCellAgent
42
42
  {"name"=>"bad-header", "value"=>"value123"}
43
43
  ]
44
44
  }
45
- secure_headers_policy = SecureHeadersPolicy.fromJson(secure_headers_policy_json)
45
+ secure_headers_policy = SecureHeadersPolicy.from_json(secure_headers_policy_json)
46
46
  context "secure header example, invalid header" do
47
47
  it "returns false" do
48
48
  expect(secure_headers_policy.headers.length).to eq(0)
@@ -56,7 +56,7 @@ module TCellAgent
56
56
  {"name"=>"x-permitted-cross-domain-policies", "value"=>"value123\\nabc"}
57
57
  ]
58
58
  }
59
- secure_headers_policy = SecureHeadersPolicy.fromJson(secure_headers_policy_json)
59
+ secure_headers_policy = SecureHeadersPolicy.from_json(secure_headers_policy_json)
60
60
  context "secure header, value is bad" do
61
61
  it "returns false" do
62
62
  expect(secure_headers_policy.headers.length).to eq(0)
@@ -64,24 +64,59 @@ module TCellAgent
64
64
  end
65
65
  it "alerts on get xss payload" do
66
66
  response = request.get("/foo?xyz=%3Cscript%3Ealert(1)%3C%2Fscript%3E", 'REMOTE_ADDR' => '1.3.3.4,3.4.5.6')
67
- expected_as = {"event_type"=>"as", "dp"=>"xss", "param"=>"xyz", "remote_addr"=>"1.3.3.4", "m"=>"GET", "loc"=>"http://example.org/foo?xyz=", "tid"=>"a-b-c-d-e-f"}
67
+ expected_as = {
68
+ "event_type"=>"as",
69
+ "dp"=>"xss",
70
+ "param"=>"xyz",
71
+ "remote_addr"=>"1.3.3.4",
72
+ "m"=>"GET",
73
+ "pattern"=>"1",
74
+ "loc"=>"http://example.org/foo?xyz=",
75
+ "tid"=>"a-b-c-d-e-f"}
68
76
  expect(TCellAgent.event_queue).to include(expected_as)
69
77
  end
70
78
  it "alerts on post xss payload" do
71
79
  response = request.post("/foo", :input => "x=<script>alert(1)</script>", 'REMOTE_ADDR' => '1.2.3.4,3.4.5.6')
72
- expected_as = {"event_type"=>"as", "dp"=>"xss", "param"=>"x", "remote_addr"=>"1.2.3.4", "m"=>"POST", "loc"=>"http://example.org/foo", "tid"=>"a-b-c-d-e-f"}
80
+ expected_as = {
81
+ "event_type"=>"as",
82
+ "dp"=>"xss",
83
+ "param"=>"x",
84
+ "remote_addr"=>"1.2.3.4",
85
+ "m"=>"POST",
86
+ "pattern"=>"1",
87
+ "loc"=>"http://example.org/foo",
88
+ "tid"=>"a-b-c-d-e-f"}
73
89
  expect(TCellAgent.event_queue).to include(expected_as)
74
90
  end #/it
75
91
  it "alerts on get xss payload with route_id" do
76
92
  response = request2.get("/foo?xyz=%3Cscript%3Ealert(1)%3C%2Fscript%3E")
77
- expected_as = {"event_type"=>"as", "dp"=>"xss", "param"=>"xyz", "remote_addr"=>nil, "rou"=>"myrouteid", "m"=>"GET", "loc"=>"http://example.org/foo?xyz=", "tid"=>"a-b-c-d-e-f"}
93
+ expected_as = {
94
+ "event_type"=>"as",
95
+ "dp"=>"xss",
96
+ "param"=>"xyz",
97
+ "remote_addr"=>nil,
98
+ "rou"=>"myrouteid",
99
+ "m"=>"GET",
100
+ "pattern"=>"1",
101
+ "loc"=>"http://example.org/foo?xyz=",
102
+ "tid"=>"a-b-c-d-e-f"}
78
103
  expect(TCellAgent.event_queue).to include(expected_as)
79
104
  end
80
105
  it "checks that payload is sent in xss with route_id" do
81
106
  old_uap = TCellAgent.configuration.allow_unencrypted_appsensor_payloads
82
107
  TCellAgent.configuration.allow_unencrypted_appsensor_payloads = true
83
108
  response = request2.get("/foo?xyz=%3Cscript%3Ealert(1)%3C%2Fscript%3E")
84
- expected_as = {"event_type"=>"as", "dp"=>"xss", "param"=>"xyz", "remote_addr"=>nil, "rou"=>"myrouteid", "m"=>"GET", "loc"=>"http://example.org/foo?xyz=", "tid"=>"a-b-c-d-e-f", "payload"=>"<script>alert(1)</script>"}
109
+ expected_as = {
110
+ "event_type"=>"as",
111
+ "dp"=>"xss",
112
+ "param"=>"xyz",
113
+ "remote_addr"=>nil,
114
+ "rou"=>"myrouteid",
115
+ "m"=>"GET",
116
+ "pattern"=>"1",
117
+ "loc"=>"http://example.org/foo?xyz=",
118
+ "tid"=>"a-b-c-d-e-f",
119
+ "payload"=>"<script>alert(1)</script>"}
85
120
  TCellAgent.configuration.allow_unencrypted_appsensor_payloads = old_uap
86
121
  expect(TCellAgent.event_queue).to include(expected_as)
87
122
  end
@@ -104,7 +139,15 @@ module TCellAgent
104
139
  it "alerts on get sqli payload" do
105
140
  # ' OR '3'='3
106
141
  response = request.get("/foo?xyz=abds&def=%27%20OR%20%273%27%3D%273", 'REMOTE_ADDR' => '1.3.3.4,3.4.5.6')
107
- expected_as = {"event_type"=>"as", "dp"=>"sqli", "param"=>"def", "remote_addr"=>"1.3.3.4", "m"=>"GET", "loc"=>"http://example.org/foo?xyz=&def=", "tid"=>"a-b-c-d-e-f"}
142
+ expected_as = {
143
+ "event_type"=>"as",
144
+ "dp"=>"sqli",
145
+ "param"=>"def",
146
+ "remote_addr"=>"1.3.3.4",
147
+ "m"=>"GET",
148
+ "pattern"=>"1",
149
+ "loc"=>"http://example.org/foo?xyz=&def=",
150
+ "tid"=>"a-b-c-d-e-f"}
108
151
  expect(TCellAgent.event_queue).to include(expected_as)
109
152
  end
110
153
  end #/conext
@@ -124,14 +167,31 @@ module TCellAgent
124
167
  end
125
168
  it "alerts on most obvious payload" do
126
169
  response = request.get("/foo?xyz=/etc/passwd", 'REMOTE_ADDR' => '1.3.3.4,3.4.5.6')
127
- expected_as = {"event_type"=>"as", "dp"=>"fpt", "param"=>"xyz", "remote_addr"=>"1.3.3.4", "m"=>"GET", "loc"=>"http://example.org/foo?xyz=", "tid"=>"a-b-c-d-e-f"}
170
+ expected_as = {
171
+ "event_type"=>"as",
172
+ "dp"=>"fpt",
173
+ "param"=>"xyz",
174
+ "remote_addr"=>"1.3.3.4",
175
+ "m"=>"GET",
176
+ "pattern"=>"2",
177
+ "loc"=>"http://example.org/foo?xyz=",
178
+ "tid"=>"a-b-c-d-e-f"}
128
179
  expect(TCellAgent.event_queue).to include(expected_as)
129
180
  end
130
181
  it "checks that payload is sent" do
131
182
  old_uap = TCellAgent.configuration.allow_unencrypted_appsensor_payloads
132
183
  TCellAgent.configuration.allow_unencrypted_appsensor_payloads = true
133
184
  response = request.get("/foo?xyz=/etc/passwd", 'REMOTE_ADDR' => '1.3.3.4,3.4.5.6')
134
- expected_as = {"event_type"=>"as", "dp"=>"fpt", "param"=>"xyz", "remote_addr"=>"1.3.3.4", "m"=>"GET", "loc"=>"http://example.org/foo?xyz=", "tid"=>"a-b-c-d-e-f", "payload"=>"/etc/passwd"}
185
+ expected_as = {
186
+ "event_type"=>"as",
187
+ "dp"=>"fpt",
188
+ "param"=>"xyz",
189
+ "remote_addr"=>"1.3.3.4",
190
+ "m"=>"GET",
191
+ "pattern"=>"2",
192
+ "loc"=>"http://example.org/foo?xyz=",
193
+ "tid"=>"a-b-c-d-e-f",
194
+ "payload"=>"/etc/passwd"}
135
195
  TCellAgent.configuration.allow_unencrypted_appsensor_payloads = old_uap
136
196
  expect(TCellAgent.event_queue).to include(expected_as)
137
197
  end
@@ -0,0 +1,80 @@
1
+ require 'spec_helper'
2
+
3
+ module TCellAgent
4
+ module SensorEvents
5
+
6
+ describe AppSensorMetaEvent do
7
+
8
+ describe "#body_params" do
9
+ context "with text/html content type" do
10
+ it "should set the body params to empty" do
11
+ app_sensor_event_process = AppSensorMetaEvent.new
12
+ app_sensor_event_process.set_body_dict(
13
+ 67,
14
+ "text/html",
15
+ {username:"tester",password:"pass"}.to_json
16
+ )
17
+
18
+ expect(app_sensor_event_process.body_dict).to eq({})
19
+ end
20
+ end
21
+
22
+ context "with application/json content type" do
23
+
24
+ context "with empty request body" do
25
+ it "should set the body params to empty" do
26
+ @app_sensor_event_process = AppSensorMetaEvent.new
27
+ @app_sensor_event_process.set_body_dict(
28
+ 67,
29
+ "application/json",
30
+ nil
31
+ )
32
+
33
+ expect(@app_sensor_event_process.body_dict).to eq({})
34
+ end
35
+ end
36
+
37
+ context "with bad json in the body" do
38
+ it "should set the body params to empty" do
39
+ @app_sensor_event_process = AppSensorMetaEvent.new
40
+ @app_sensor_event_process.set_body_dict(
41
+ 67,
42
+ "application/json",
43
+ '{"username":"tester""password":"pass"}'
44
+ )
45
+
46
+ expect(@app_sensor_event_process.body_dict).to eq({})
47
+ end
48
+ end
49
+
50
+ context "with valid json in the body" do
51
+ it "should set the body params" do
52
+ @app_sensor_event_process = AppSensorMetaEvent.new
53
+ @app_sensor_event_process.set_body_dict(
54
+ 67,
55
+ "application/json",
56
+ {username:"tester",password:"pass"}.to_json
57
+ )
58
+
59
+ expect(@app_sensor_event_process.body_dict).to eq({"username"=>"tester","password"=>"pass"})
60
+ end
61
+ end
62
+
63
+ context "with a json body that's too big" do
64
+ it "should set the body params to empty" do
65
+ @app_sensor_event_process = AppSensorMetaEvent.new
66
+ @app_sensor_event_process.set_body_dict(
67
+ 20000000,
68
+ "application/json",
69
+ {username:"tester",password:"pass"}.to_json
70
+ )
71
+ expect(@app_sensor_event_process.body_dict).to eq({})
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ end
78
+
79
+ end
80
+ end