aikido-zen 1.9.0 → 1.10.0.beta.1
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.
- checksums.yaml +4 -4
- data/lib/aikido/zen/agent.rb +16 -3
- data/lib/aikido/zen/api_client.rb +27 -21
- data/lib/aikido/zen/api_stream.rb +5 -3
- data/lib/aikido/zen/attack.rb +7 -1
- data/lib/aikido/zen/attack_wave/helpers.rb +6 -5
- data/lib/aikido/zen/collector/event.rb +3 -6
- data/lib/aikido/zen/collector/sink_stats.rb +2 -53
- data/lib/aikido/zen/collector/stats.rb +4 -15
- data/lib/aikido/zen/collector.rb +5 -5
- data/lib/aikido/zen/config.rb +17 -33
- data/lib/aikido/zen/context/rack_request.rb +8 -1
- data/lib/aikido/zen/context/rails_request.rb +8 -1
- data/lib/aikido/zen/context.rb +44 -64
- data/lib/aikido/zen/errors.rb +1 -1
- data/lib/aikido/zen/firewall/ip_list.rb +15 -62
- data/lib/aikido/zen/firewall.rb +31 -22
- data/lib/aikido/zen/helpers.rb +77 -5
- data/lib/aikido/zen/internals.rb +112 -11
- data/lib/aikido/zen/payload.rb +2 -5
- data/lib/aikido/zen/payload_extractor/path.rb +54 -0
- data/lib/aikido/zen/payload_extractor.rb +147 -0
- data/lib/aikido/zen/request.rb +7 -3
- data/lib/aikido/zen/scan.rb +2 -12
- data/lib/aikido/zen/scanners/path_traversal_scanner.rb +18 -13
- data/lib/aikido/zen/scanners/shell_injection_scanner.rb +18 -15
- data/lib/aikido/zen/scanners/sql_injection_scanner.rb +31 -14
- data/lib/aikido/zen/scanners/ssrf_scanner.rb +16 -12
- data/lib/aikido/zen/sink.rb +23 -19
- data/lib/aikido/zen/sinks/file.rb +5 -3
- data/lib/aikido/zen/sinks/sqlite3.rb +1 -1
- data/lib/aikido/zen/sinks/trilogy.rb +80 -4
- data/lib/aikido/zen/sinks_dsl.rb +28 -3
- data/lib/aikido/zen/system_info.rb +54 -9
- data/lib/aikido/zen/version.rb +2 -2
- data/lib/aikido/zen/worker_process/agent/client.rb +4 -1
- data/lib/aikido/zen.rb +1 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0d07e9923e47008b95a01a65d3d501659558ab1c2622c2fd274789368b4b0677
|
|
4
|
+
data.tar.gz: 51c5ce16b057f5c73eb351af004b796f506a5270741bac532463c815f8c431d0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 47e2bb9e42c5023fd7a533815af403aa6967ed8345bd78b9daae6094f489c9b1f04ea52f5cd64f08f447170967b944dc3bdafa2c7f88f090ce9425619d2b3390
|
|
7
|
+
data.tar.gz: 93daa7b527b7192494653e9b613a01d0b567b17f616d09a05a8eb5341fd011d95fda4d237233bcfd97de3bae5213cbf01de3ad74553e8b095c0ae3fd5f84b4c6
|
data/lib/aikido/zen/agent.rb
CHANGED
|
@@ -136,9 +136,7 @@ module Aikido::Zen
|
|
|
136
136
|
|
|
137
137
|
# Recording the attack must never prevent us from blocking it.
|
|
138
138
|
begin
|
|
139
|
-
@config.logger.error(
|
|
140
|
-
format("Zen has %s a %s: %s", attack.blocked? ? "blocked" : "detected", attack.humanized_name, attack.as_json.to_json)
|
|
141
|
-
)
|
|
139
|
+
@config.logger.error(attack_log_message(attack))
|
|
142
140
|
|
|
143
141
|
report(Events::Attack.new(attack: attack)) if @api_client.can_make_requests?
|
|
144
142
|
|
|
@@ -227,6 +225,21 @@ module Aikido::Zen
|
|
|
227
225
|
|
|
228
226
|
private
|
|
229
227
|
|
|
228
|
+
def attack_log_message(attack)
|
|
229
|
+
input = attack.as_json
|
|
230
|
+
|
|
231
|
+
format(
|
|
232
|
+
"Zen has %s a %s: %s(...) originating from %s%s",
|
|
233
|
+
attack.blocked? ? "blocked" : "detected",
|
|
234
|
+
attack.humanized_name,
|
|
235
|
+
attack.operation,
|
|
236
|
+
input["source"],
|
|
237
|
+
# The path is built from names in the request, so it can't be trusted
|
|
238
|
+
# not to split the log line.
|
|
239
|
+
input["path"].to_s.gsub(/[\r\n]/, " ")
|
|
240
|
+
)
|
|
241
|
+
end
|
|
242
|
+
|
|
230
243
|
def settings_updated(event)
|
|
231
244
|
updated_at = Time.at(event[:data]["configUpdatedAt"].to_i)
|
|
232
245
|
|
|
@@ -16,12 +16,6 @@ module Aikido::Zen
|
|
|
16
16
|
@config = config
|
|
17
17
|
@system_info = system_info
|
|
18
18
|
@rate_limiter = rate_limiter
|
|
19
|
-
|
|
20
|
-
@should_fetch_settings_endpoint = @config.realtime_endpoint
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def should_fetch_settings_endpoint=(uri)
|
|
24
|
-
@should_fetch_settings_endpoint = URI(uri)
|
|
25
19
|
end
|
|
26
20
|
|
|
27
21
|
# @return [Boolean] whether we have a configured token.
|
|
@@ -44,16 +38,16 @@ module Aikido::Zen
|
|
|
44
38
|
|
|
45
39
|
response = request(
|
|
46
40
|
Net::HTTP::Get.new("/config", default_headers),
|
|
47
|
-
base_url: @
|
|
41
|
+
base_url: @config.realtime_endpoint,
|
|
42
|
+
timeout: @config.api_config_timeout
|
|
48
43
|
)
|
|
49
44
|
|
|
50
45
|
new_updated_at = Time.at(response["configUpdatedAt"].to_i)
|
|
51
46
|
new_updated_at > last_updated_at
|
|
52
47
|
end
|
|
53
48
|
|
|
54
|
-
# Fetches the runtime config from the server.
|
|
55
|
-
# other low-
|
|
56
|
-
# times, after which it will raise an error.
|
|
49
|
+
# Fetches the runtime config from the server. Requests are never retried;
|
|
50
|
+
# on a timeout or other low-level error this raises an error.
|
|
57
51
|
#
|
|
58
52
|
# @return [Hash] decoded JSON response from the server with the runtime
|
|
59
53
|
# settings.
|
|
@@ -61,7 +55,11 @@ module Aikido::Zen
|
|
|
61
55
|
def fetch_runtime_config
|
|
62
56
|
@config.logger.debug("Fetching new runtime config")
|
|
63
57
|
|
|
64
|
-
request(
|
|
58
|
+
request(
|
|
59
|
+
Net::HTTP::Get.new("/api/runtime/config", default_headers),
|
|
60
|
+
base_url: @config.api_endpoint,
|
|
61
|
+
timeout: @config.api_config_timeout
|
|
62
|
+
)
|
|
65
63
|
end
|
|
66
64
|
|
|
67
65
|
def fetch_runtime_firewall_lists
|
|
@@ -71,7 +69,11 @@ module Aikido::Zen
|
|
|
71
69
|
"Accept-Encoding" => "gzip"
|
|
72
70
|
})
|
|
73
71
|
|
|
74
|
-
request(
|
|
72
|
+
request(
|
|
73
|
+
Net::HTTP::Get.new("/api/runtime/firewall/lists", headers),
|
|
74
|
+
base_url: @config.api_endpoint,
|
|
75
|
+
timeout: @config.api_config_timeout
|
|
76
|
+
)
|
|
75
77
|
end
|
|
76
78
|
|
|
77
79
|
# @overload report(event)
|
|
@@ -111,7 +113,7 @@ module Aikido::Zen
|
|
|
111
113
|
@config.json_encoder.call(event)
|
|
112
114
|
end
|
|
113
115
|
|
|
114
|
-
request(req)
|
|
116
|
+
request(req, base_url: @config.api_endpoint, timeout: @config.api_events_timeout)
|
|
115
117
|
rescue Aikido::Zen::RateLimitedError
|
|
116
118
|
@rate_limiter.open!
|
|
117
119
|
raise
|
|
@@ -121,15 +123,16 @@ module Aikido::Zen
|
|
|
121
123
|
# response.
|
|
122
124
|
#
|
|
123
125
|
# @param request [Net::HTTPRequest]
|
|
124
|
-
# @param base_url [URI] which API to use.
|
|
126
|
+
# @param base_url [URI] which API to use.
|
|
127
|
+
# @param timeout [Numeric] seconds to wait on each connect, read and write.
|
|
125
128
|
#
|
|
126
129
|
# @return [Object] the result of decoding the JSON response from the server.
|
|
127
130
|
#
|
|
128
131
|
# @raise [Aikido::Zen::APIError] in case of a 4XX or 5XX response.
|
|
129
132
|
# @raise [Aikido::Zen::NetworkError] if an error occurs trying to make the
|
|
130
133
|
# request.
|
|
131
|
-
private def request(request, base_url:
|
|
132
|
-
Net::HTTP.start(base_url.host, base_url.port, http_settings(base_url)) do |http|
|
|
134
|
+
private def request(request, base_url:, timeout:)
|
|
135
|
+
Net::HTTP.start(base_url.host, base_url.port, http_settings(base_url, timeout)) do |http|
|
|
133
136
|
response = http.request(request)
|
|
134
137
|
|
|
135
138
|
case response
|
|
@@ -168,11 +171,14 @@ module Aikido::Zen
|
|
|
168
171
|
end
|
|
169
172
|
end
|
|
170
173
|
|
|
171
|
-
private def http_settings(base_url)
|
|
172
|
-
|
|
174
|
+
private def http_settings(base_url, timeout)
|
|
175
|
+
{
|
|
173
176
|
use_ssl: base_url.scheme == "https",
|
|
174
|
-
max_retries:
|
|
175
|
-
|
|
177
|
+
max_retries: 0,
|
|
178
|
+
open_timeout: timeout,
|
|
179
|
+
read_timeout: timeout,
|
|
180
|
+
write_timeout: timeout
|
|
181
|
+
}
|
|
176
182
|
end
|
|
177
183
|
|
|
178
184
|
private def default_headers
|
|
@@ -180,7 +186,7 @@ module Aikido::Zen
|
|
|
180
186
|
"Authorization" => @config.api_token,
|
|
181
187
|
"Accept" => "application/json",
|
|
182
188
|
"User-Agent" => "#{@system_info.library_name} v#{@system_info.library_version}"
|
|
183
|
-
}
|
|
189
|
+
}.merge(@system_info.agent_headers)
|
|
184
190
|
end
|
|
185
191
|
end
|
|
186
192
|
end
|
|
@@ -7,7 +7,9 @@ require "json"
|
|
|
7
7
|
module Aikido::Zen
|
|
8
8
|
class APIStream
|
|
9
9
|
def initialize(
|
|
10
|
-
|
|
10
|
+
zen: Aikido::Zen,
|
|
11
|
+
config: zen.config,
|
|
12
|
+
system_info: zen.system_info,
|
|
11
13
|
min_backoff: 5,
|
|
12
14
|
max_backoff: 60,
|
|
13
15
|
backoff_reset: 30,
|
|
@@ -16,6 +18,7 @@ module Aikido::Zen
|
|
|
16
18
|
read_timeout: 70
|
|
17
19
|
)
|
|
18
20
|
@config = config
|
|
21
|
+
@system_info = system_info
|
|
19
22
|
@min_backoff = min_backoff
|
|
20
23
|
@max_backoff = max_backoff
|
|
21
24
|
@backoff_reset = backoff_reset
|
|
@@ -123,8 +126,7 @@ module Aikido::Zen
|
|
|
123
126
|
request["Authorization"] = @token
|
|
124
127
|
request["Accept"] = "text/event-stream"
|
|
125
128
|
request["Cache-Control"] = "no-cache"
|
|
126
|
-
request[
|
|
127
|
-
request["X-Agent-Version"] = Aikido::Zen::VERSION
|
|
129
|
+
@system_info.agent_headers.each { |name, value| request[name] = value }
|
|
128
130
|
# Working around Net::HTTP cleverness; auto-negotiates gzip and buffers
|
|
129
131
|
# decompressed output internally.
|
|
130
132
|
request["Accept-Encoding"] = "identity"
|
data/lib/aikido/zen/attack.rb
CHANGED
|
@@ -43,13 +43,19 @@ module Aikido::Zen
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
def as_json
|
|
46
|
-
{
|
|
46
|
+
attack_json = {
|
|
47
47
|
"kind" => kind,
|
|
48
48
|
"blocked" => blocked?,
|
|
49
49
|
"metadata" => metadata,
|
|
50
50
|
"operation" => @operation,
|
|
51
51
|
"stack" => @stack
|
|
52
52
|
}.compact.merge(input.as_json)
|
|
53
|
+
|
|
54
|
+
if (actor = @context&.request&.actor)
|
|
55
|
+
attack_json["user"] = {"id" => actor.id, "name" => actor.name}.compact
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
attack_json
|
|
53
59
|
end
|
|
54
60
|
|
|
55
61
|
def exception(*)
|
|
@@ -45,7 +45,10 @@ module Aikido::Zen
|
|
|
45
45
|
path = original_path(request)
|
|
46
46
|
query = request.query_string
|
|
47
47
|
|
|
48
|
-
query.empty? ? path : "#{path}?#{query}"
|
|
48
|
+
fullpath = query.empty? ? path : "#{path}?#{query}"
|
|
49
|
+
|
|
50
|
+
# Servers may deliver the path and query string as binary strings.
|
|
51
|
+
Aikido::Zen::Helpers.encode_safely(fullpath)
|
|
49
52
|
end
|
|
50
53
|
|
|
51
54
|
def self.suspicious_method?(method)
|
|
@@ -75,10 +78,8 @@ module Aikido::Zen
|
|
|
75
78
|
end
|
|
76
79
|
|
|
77
80
|
def self.include_suspicious_payload?(context)
|
|
78
|
-
context.
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
value = payload.value.downcase
|
|
81
|
+
context.each_input(:query) do |input|
|
|
82
|
+
value = input.downcase
|
|
82
83
|
|
|
83
84
|
length = value.length
|
|
84
85
|
|
|
@@ -158,16 +158,14 @@ module Aikido::Zen
|
|
|
158
158
|
new(
|
|
159
159
|
data["sink_name"],
|
|
160
160
|
data["sink_kind"],
|
|
161
|
-
data["duration"],
|
|
162
161
|
has_errors: data["has_errors"]
|
|
163
162
|
)
|
|
164
163
|
end
|
|
165
164
|
|
|
166
|
-
def initialize(sink_name, sink_kind,
|
|
165
|
+
def initialize(sink_name, sink_kind, has_errors:)
|
|
167
166
|
super()
|
|
168
167
|
@sink_name = sink_name
|
|
169
168
|
@sink_kind = sink_kind
|
|
170
|
-
@duration = duration
|
|
171
169
|
@has_errors = has_errors
|
|
172
170
|
end
|
|
173
171
|
|
|
@@ -175,17 +173,16 @@ module Aikido::Zen
|
|
|
175
173
|
super.update({
|
|
176
174
|
"sink_name" => @sink_name,
|
|
177
175
|
"sink_kind" => @sink_kind,
|
|
178
|
-
"duration" => @duration,
|
|
179
176
|
"has_errors" => @has_errors
|
|
180
177
|
})
|
|
181
178
|
end
|
|
182
179
|
|
|
183
180
|
def handle(collector)
|
|
184
|
-
collector.handle_track_scan(@sink_name, @sink_kind,
|
|
181
|
+
collector.handle_track_scan(@sink_name, @sink_kind, has_errors: @has_errors)
|
|
185
182
|
end
|
|
186
183
|
|
|
187
184
|
def inspect
|
|
188
|
-
"#<#{self.class.name} #{@sink_name} #{@sink_kind} #{
|
|
185
|
+
"#<#{self.class.name} #{@sink_name} #{@sink_kind} #{@has_errors}>"
|
|
189
186
|
end
|
|
190
187
|
end
|
|
191
188
|
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative "../capped_collections"
|
|
4
|
-
|
|
5
3
|
module Aikido::Zen
|
|
6
4
|
# @api private
|
|
7
5
|
#
|
|
@@ -24,43 +22,14 @@ module Aikido::Zen
|
|
|
24
22
|
# _and_ blocked by the Zen.
|
|
25
23
|
attr_accessor :blocked_attacks
|
|
26
24
|
|
|
27
|
-
|
|
28
|
-
# this grows to match Config#max_performance_samples, the set is
|
|
29
|
-
# cleared and the data is aggregated into #compressed_timings.
|
|
30
|
-
attr_accessor :timings
|
|
31
|
-
|
|
32
|
-
# @return [Array<CompressedTiming>] list of aggregated stats.
|
|
33
|
-
attr_accessor :compressed_timings
|
|
34
|
-
|
|
35
|
-
def initialize(name, config)
|
|
25
|
+
def initialize(name)
|
|
36
26
|
@name = name
|
|
37
|
-
@config = config
|
|
38
27
|
|
|
39
28
|
@scans = 0
|
|
40
29
|
@errors = 0
|
|
41
30
|
|
|
42
31
|
@attacks = 0
|
|
43
32
|
@blocked_attacks = 0
|
|
44
|
-
|
|
45
|
-
@timings = Set.new
|
|
46
|
-
@compressed_timings = CappedSet.new(@config.max_compressed_stats)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def add_timing(duration)
|
|
50
|
-
compress_timings if @timings.size >= @config.max_performance_samples
|
|
51
|
-
@timings << duration
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
def compress_timings(at: Time.now.utc)
|
|
55
|
-
return if @timings.empty?
|
|
56
|
-
|
|
57
|
-
list = @timings.sort
|
|
58
|
-
@timings.clear
|
|
59
|
-
|
|
60
|
-
mean = list.sum / list.size
|
|
61
|
-
percentiles = percentiles(list, 50, 75, 90, 95, 99)
|
|
62
|
-
|
|
63
|
-
@compressed_timings << CompressedTiming.new(mean, percentiles, at)
|
|
64
33
|
end
|
|
65
34
|
|
|
66
35
|
def as_json
|
|
@@ -72,28 +41,8 @@ module Aikido::Zen
|
|
|
72
41
|
"attacksDetected" => {
|
|
73
42
|
"total" => @attacks,
|
|
74
43
|
"blocked" => @blocked_attacks
|
|
75
|
-
},
|
|
76
|
-
"compressedTimings" => @compressed_timings.as_json
|
|
77
|
-
}
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
private def percentiles(sorted, *scores)
|
|
81
|
-
return {} if sorted.empty? || scores.empty?
|
|
82
|
-
|
|
83
|
-
scores.map { |p|
|
|
84
|
-
index = (sorted.size * (p / 100.0)).floor
|
|
85
|
-
[p, sorted.at(index)]
|
|
86
|
-
}.to_h
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
CompressedTiming = Struct.new(:mean, :percentiles, :compressed_at) do
|
|
90
|
-
def as_json
|
|
91
|
-
{
|
|
92
|
-
"averageInMs" => mean * 1000,
|
|
93
|
-
"percentiles" => percentiles.transform_values { |t| t * 1000 },
|
|
94
|
-
"compressedAt" => compressed_at.to_i * 1000
|
|
95
44
|
}
|
|
96
|
-
|
|
45
|
+
}
|
|
97
46
|
end
|
|
98
47
|
end
|
|
99
48
|
end
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative "../capped_collections"
|
|
4
|
-
|
|
5
3
|
module Aikido::Zen
|
|
6
4
|
# @api private
|
|
7
5
|
#
|
|
@@ -13,10 +11,7 @@ module Aikido::Zen
|
|
|
13
11
|
# @!visibility private
|
|
14
12
|
attr_writer :ended_at
|
|
15
13
|
|
|
16
|
-
def initialize
|
|
17
|
-
super()
|
|
18
|
-
@config = config
|
|
19
|
-
|
|
14
|
+
def initialize
|
|
20
15
|
@started_at = @ended_at = nil
|
|
21
16
|
@requests = 0
|
|
22
17
|
@aborted_requests = 0
|
|
@@ -25,7 +20,7 @@ module Aikido::Zen
|
|
|
25
20
|
@ip_lists = Hash.new { |h, k| h[k] = 0 }
|
|
26
21
|
@attack_waves = 0
|
|
27
22
|
@blocked_attack_waves = 0
|
|
28
|
-
@sinks = Hash.new { |h, k| h[k] = Collector::SinkStats.new(k
|
|
23
|
+
@sinks = Hash.new { |h, k| h[k] = Collector::SinkStats.new(k) }
|
|
29
24
|
end
|
|
30
25
|
|
|
31
26
|
# @return [Boolean]
|
|
@@ -50,16 +45,12 @@ module Aikido::Zen
|
|
|
50
45
|
end
|
|
51
46
|
|
|
52
47
|
# Sets the end time for these stats block, freezes it to avoid any more
|
|
53
|
-
# writing to them
|
|
54
|
-
# sending these to the Aikido servers.
|
|
48
|
+
# writing to them.
|
|
55
49
|
#
|
|
56
50
|
# @param at [Time] the time at which we're resetting, which is set as the
|
|
57
51
|
# ending time for the returned copy.
|
|
58
52
|
# @return [void]
|
|
59
53
|
def flush(at: Time.now.utc)
|
|
60
|
-
# Make sure the timing stats are compressed before copying, since we
|
|
61
|
-
# need these compressed when we serialize this for the API.
|
|
62
|
-
@sinks.each_value { |sink| sink.compress_timings(at: at) }
|
|
63
54
|
@ended_at = at
|
|
64
55
|
freeze
|
|
65
56
|
end
|
|
@@ -95,15 +86,13 @@ module Aikido::Zen
|
|
|
95
86
|
|
|
96
87
|
# @param sink_name [String] the name of the sink
|
|
97
88
|
# @param sink_kind [String] the category of operation the sink represents
|
|
98
|
-
# @param duration [Float] the length the scan in seconds
|
|
99
89
|
# @param has_errors [Boolean] whether errors occurred during the scan
|
|
100
90
|
# @return [void]
|
|
101
|
-
def add_scan(sink_name, sink_kind,
|
|
91
|
+
def add_scan(sink_name, sink_kind, has_errors:)
|
|
102
92
|
stats = @sinks[sink_name]
|
|
103
93
|
stats.kind = sink_kind
|
|
104
94
|
stats.scans += 1
|
|
105
95
|
stats.errors += 1 if has_errors
|
|
106
|
-
stats.add_timing(duration)
|
|
107
96
|
end
|
|
108
97
|
|
|
109
98
|
# @param sink_name [String] the name of the sink
|
data/lib/aikido/zen/collector.rb
CHANGED
|
@@ -11,7 +11,7 @@ module Aikido::Zen
|
|
|
11
11
|
|
|
12
12
|
@events = Queue.new
|
|
13
13
|
|
|
14
|
-
@stats = Concurrent::AtomicReference.new(Stats.new
|
|
14
|
+
@stats = Concurrent::AtomicReference.new(Stats.new)
|
|
15
15
|
@users = Concurrent::AtomicReference.new(Users.new(@config))
|
|
16
16
|
@hosts = Concurrent::AtomicReference.new(Hosts.new(@config))
|
|
17
17
|
@routes = Concurrent::AtomicReference.new(Routes.new(@config))
|
|
@@ -56,7 +56,7 @@ module Aikido::Zen
|
|
|
56
56
|
def flush(at: Time.now.utc)
|
|
57
57
|
handle
|
|
58
58
|
|
|
59
|
-
stats = @stats.get_and_set(Stats.new
|
|
59
|
+
stats = @stats.get_and_set(Stats.new)
|
|
60
60
|
users = @users.get_and_set(Users.new(@config))
|
|
61
61
|
hosts = @hosts.get_and_set(Hosts.new(@config))
|
|
62
62
|
routes = @routes.get_and_set(Routes.new(@config))
|
|
@@ -146,12 +146,12 @@ module Aikido::Zen
|
|
|
146
146
|
# @param scan [Aikido::Zen::Scan]
|
|
147
147
|
# @return [void]
|
|
148
148
|
def track_scan(scan)
|
|
149
|
-
add_event(Events::TrackScan.new(scan.sink.name, scan.sink.kind,
|
|
149
|
+
add_event(Events::TrackScan.new(scan.sink.name, scan.sink.kind, has_errors: scan.errors?))
|
|
150
150
|
end
|
|
151
151
|
|
|
152
|
-
def handle_track_scan(sink_name, sink_kind,
|
|
152
|
+
def handle_track_scan(sink_name, sink_kind, has_errors:)
|
|
153
153
|
synchronize(@stats) do |stats|
|
|
154
|
-
stats.add_scan(sink_name, sink_kind,
|
|
154
|
+
stats.add_scan(sink_name, sink_kind, has_errors: has_errors)
|
|
155
155
|
end
|
|
156
156
|
end
|
|
157
157
|
|
data/lib/aikido/zen/config.rb
CHANGED
|
@@ -45,8 +45,15 @@ module Aikido::Zen
|
|
|
45
45
|
# +https://guard.aikido.dev+.
|
|
46
46
|
attr_reader :realtime_endpoint
|
|
47
47
|
|
|
48
|
-
# @return [
|
|
49
|
-
|
|
48
|
+
# @return [Numeric] the timeout in seconds for reporting events to the
|
|
49
|
+
# API (+POST /api/runtime/events+). Applied to each connect, read and
|
|
50
|
+
# write wait. Defaults to 60 seconds.
|
|
51
|
+
attr_accessor :api_events_timeout
|
|
52
|
+
|
|
53
|
+
# @return [Numeric] the timeout in seconds for fetching config, runtime
|
|
54
|
+
# config and firewall lists from the API. Applied to each connect, read
|
|
55
|
+
# and write wait. Defaults to 30 seconds.
|
|
56
|
+
attr_accessor :api_config_timeout
|
|
50
57
|
|
|
51
58
|
# @return [Integer] the interval in seconds to poll the runtime API for
|
|
52
59
|
# settings changes. Defaults to evey 60 seconds.
|
|
@@ -60,6 +67,11 @@ module Aikido::Zen
|
|
|
60
67
|
# when extracting payloads from a nested request property. Defaults to 64.
|
|
61
68
|
attr_accessor :extract_payloads_max_depth
|
|
62
69
|
|
|
70
|
+
# @return [Integer] the maximum number of times we URL-decode a string
|
|
71
|
+
# when extracting payloads from it, as applications may decode input
|
|
72
|
+
# more than once. Defaults to 5.
|
|
73
|
+
attr_accessor :extract_payloads_max_url_decoded_variants
|
|
74
|
+
|
|
63
75
|
# @return [Symbol] the agent mode for forked worker processes. Can be set
|
|
64
76
|
# through the AIKIDO_AGENT_MODE environment variable.
|
|
65
77
|
attr_reader :agent_mode
|
|
@@ -90,15 +102,6 @@ module Aikido::Zen
|
|
|
90
102
|
# @return [String] environment specific HTTP header providing the client IP.
|
|
91
103
|
attr_accessor :client_ip_header
|
|
92
104
|
|
|
93
|
-
# @return [Integer] maximum number of timing measurements to keep in memory
|
|
94
|
-
# before compressing them.
|
|
95
|
-
attr_accessor :max_performance_samples
|
|
96
|
-
|
|
97
|
-
# @return [Integer] maximum number of compressed performance samples to keep
|
|
98
|
-
# in memory. If we take more than this before reporting them to Aikido, we
|
|
99
|
-
# will discard the oldest samples.
|
|
100
|
-
attr_accessor :max_compressed_stats
|
|
101
|
-
|
|
102
105
|
# @return [Integer] maximum number of connections to outbound hosts to keep
|
|
103
106
|
# in memory in order to report them in the next heartbeat event. If new
|
|
104
107
|
# connections are added to the set before reporting them to Aikido, we
|
|
@@ -254,10 +257,12 @@ module Aikido::Zen
|
|
|
254
257
|
self.api_token = ENV.fetch("AIKIDO_TOKEN", nil)
|
|
255
258
|
self.api_endpoint = ENV.fetch("AIKIDO_ENDPOINT") { regional_api_endpoint(api_token) }
|
|
256
259
|
self.realtime_endpoint = api_endpoint
|
|
257
|
-
self.
|
|
260
|
+
self.api_events_timeout = 60 # sec
|
|
261
|
+
self.api_config_timeout = 30 # sec
|
|
258
262
|
self.polling_interval = 60 # 1 min
|
|
259
263
|
self.initial_heartbeat_delays = [30, 60 * 2] # 30 sec, 2 min
|
|
260
264
|
self.extract_payloads_max_depth = 64
|
|
265
|
+
self.extract_payloads_max_url_decoded_variants = 5
|
|
261
266
|
self.agent_mode = ENV.fetch("AIKIDO_AGENT_MODE", "shared")
|
|
262
267
|
self.worker_process_polling_interval = 10
|
|
263
268
|
self.worker_process_polling_jitter = 10
|
|
@@ -266,8 +271,6 @@ module Aikido::Zen
|
|
|
266
271
|
self.json_decoder = DEFAULT_JSON_DECODER
|
|
267
272
|
self.logger = Logger.new($stdout, progname: "aikido", level: debugging ? Logger::DEBUG : Logger::INFO)
|
|
268
273
|
self.client_ip_header = ENV.fetch("AIKIDO_CLIENT_IP_HEADER", nil)
|
|
269
|
-
self.max_performance_samples = 5000
|
|
270
|
-
self.max_compressed_stats = 100
|
|
271
274
|
self.max_outbound_connections = 200
|
|
272
275
|
self.max_users_tracked = 1000
|
|
273
276
|
self.max_custom_events = 25
|
|
@@ -332,25 +335,6 @@ module Aikido::Zen
|
|
|
332
335
|
@logger.level = Logger::DEBUG if debugging
|
|
333
336
|
end
|
|
334
337
|
|
|
335
|
-
# @overload def api_timeouts=(timeouts)
|
|
336
|
-
# Configure granular connection timeouts for the Aikido Zen API. You
|
|
337
|
-
# can set any of these per call.
|
|
338
|
-
# @param timeouts [Hash]
|
|
339
|
-
# @option timeouts [Integer] :open_timeout Duration in seconds.
|
|
340
|
-
# @option timeouts [Integer] :read_timeout Duration in seconds.
|
|
341
|
-
# @option timeouts [Integer] :write_timeout Duration in seconds.
|
|
342
|
-
#
|
|
343
|
-
# @overload def api_timeouts=(duration)
|
|
344
|
-
# Configure the connection timeouts for the Aikido Zen API.
|
|
345
|
-
# @param duration [Integer] Duration in seconds to set for all three
|
|
346
|
-
# timeouts (open, read, and write).
|
|
347
|
-
def api_timeouts=(value)
|
|
348
|
-
value = {open_timeout: value, read_timeout: value, write_timeout: value} if value.respond_to?(:to_int)
|
|
349
|
-
|
|
350
|
-
@api_timeouts ||= {}
|
|
351
|
-
@api_timeouts.update(value)
|
|
352
|
-
end
|
|
353
|
-
|
|
354
338
|
def api_token_hash
|
|
355
339
|
return unless api_token
|
|
356
340
|
|
|
@@ -20,10 +20,17 @@ module Aikido::Zen
|
|
|
20
20
|
{}
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
+
# Parsing the request body reads rack.input and caches the result on env.
|
|
24
|
+
# Ensure that rack.input can be rewound, create a copy of env and rewind
|
|
25
|
+
# the rack.input stream so that the application can still read the full
|
|
26
|
+
# request body and env does not cache the parsed result.
|
|
23
27
|
body = begin
|
|
24
|
-
|
|
28
|
+
env["rack.input"] = Helpers.rewindable(env["rack.input"])
|
|
29
|
+
Rack::Request.new(env.dup).POST
|
|
25
30
|
rescue
|
|
26
31
|
{}
|
|
32
|
+
ensure
|
|
33
|
+
env["rack.input"]&.rewind
|
|
27
34
|
end
|
|
28
35
|
|
|
29
36
|
header = begin
|
|
@@ -40,10 +40,17 @@ module Aikido::Zen
|
|
|
40
40
|
{}
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
+
# Parsing the request body reads rack.input and caches the result on env.
|
|
44
|
+
# Ensure that rack.input can be rewound, create a copy of env and rewind
|
|
45
|
+
# the rack.input stream so that the application can still read the full
|
|
46
|
+
# request body and env does not cache the parsed result.
|
|
43
47
|
body = begin
|
|
44
|
-
|
|
48
|
+
env["rack.input"] = Helpers.rewindable(env["rack.input"])
|
|
49
|
+
ActionDispatch::Request.new(env.dup).request_parameters
|
|
45
50
|
rescue
|
|
46
51
|
{}
|
|
52
|
+
ensure
|
|
53
|
+
env["rack.input"]&.rewind
|
|
47
54
|
end
|
|
48
55
|
|
|
49
56
|
route = begin
|