aikido-zen 1.7.2.beta.2-arm64-linux → 1.9.0-arm64-linux
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/README.md +8 -1
- data/benchmarks/ip_list/benchmark.rb +1 -1
- data/docs/custom-event-tracking.md +33 -0
- data/docs/rails.md +14 -0
- data/docs/request-bypassing.md +50 -0
- data/lib/aikido/zen/agent.rb +47 -21
- data/lib/aikido/zen/api_client.rb +2 -0
- data/lib/aikido/zen/attack.rb +9 -3
- data/lib/aikido/zen/attack_wave/helpers.rb +0 -1
- data/lib/aikido/zen/collector/event.rb +12 -6
- data/lib/aikido/zen/collector/sink_stats.rb +4 -0
- data/lib/aikido/zen/collector/stats.rb +6 -2
- data/lib/aikido/zen/collector.rb +6 -6
- data/lib/aikido/zen/config.rb +44 -6
- data/lib/aikido/zen/context.rb +37 -10
- data/lib/aikido/zen/event.rb +29 -0
- data/lib/aikido/zen/{runtime_settings → firewall}/ip_list.rb +1 -1
- data/lib/aikido/zen/firewall.rb +132 -0
- data/lib/aikido/zen/helpers.rb +16 -0
- data/lib/aikido/zen/internals.rb +3 -11
- data/lib/aikido/zen/libzen-v0.1.74-arm64-linux.so +0 -0
- data/lib/aikido/zen/middleware/allowed_address_checker.rb +3 -2
- data/lib/aikido/zen/middleware/attack_protector.rb +1 -1
- data/lib/aikido/zen/middleware/attack_wave_protector.rb +2 -3
- data/lib/aikido/zen/middleware/fork_detector.rb +10 -4
- data/lib/aikido/zen/middleware/ip_list_checker.rb +6 -10
- data/lib/aikido/zen/middleware/rack_throttler.rb +1 -1
- data/lib/aikido/zen/middleware/request_tracker.rb +8 -8
- data/lib/aikido/zen/middleware/user_agent_checker.rb +7 -11
- data/lib/aikido/zen/payload.rb +5 -2
- data/lib/aikido/zen/request.rb +12 -3
- data/lib/aikido/zen/runtime_settings.rb +1 -150
- data/lib/aikido/zen/scanners/path_traversal/helpers.rb +5 -1
- data/lib/aikido/zen/scanners/path_traversal_scanner.rb +2 -2
- data/lib/aikido/zen/scanners/shell_injection_scanner.rb +2 -2
- data/lib/aikido/zen/scanners/sql_injection_scanner.rb +2 -2
- data/lib/aikido/zen/scanners/ssrf/private_ip_checker.rb +42 -2
- data/lib/aikido/zen/scanners/ssrf_scanner.rb +14 -1
- data/lib/aikido/zen/sink.rb +8 -3
- data/lib/aikido/zen/sinks/action_controller.rb +1 -1
- data/lib/aikido/zen/sinks/async_http.rb +3 -7
- data/lib/aikido/zen/sinks/curb.rb +3 -7
- data/lib/aikido/zen/sinks/em_http.rb +3 -7
- data/lib/aikido/zen/sinks/excon.rb +3 -7
- data/lib/aikido/zen/sinks/file.rb +1 -1
- data/lib/aikido/zen/sinks/http.rb +3 -7
- data/lib/aikido/zen/sinks/httpclient.rb +3 -7
- data/lib/aikido/zen/sinks/httpx.rb +3 -7
- data/lib/aikido/zen/sinks/kernel.rb +1 -1
- data/lib/aikido/zen/sinks/mysql2.rb +1 -1
- data/lib/aikido/zen/sinks/net_http.rb +3 -7
- data/lib/aikido/zen/sinks/patron.rb +3 -7
- data/lib/aikido/zen/sinks/pg.rb +1 -1
- data/lib/aikido/zen/sinks/resolv.rb +1 -1
- data/lib/aikido/zen/sinks/socket.rb +11 -9
- data/lib/aikido/zen/sinks/sqlite3.rb +1 -1
- data/lib/aikido/zen/sinks/trilogy.rb +1 -1
- data/lib/aikido/zen/sinks/typhoeus.rb +3 -7
- data/lib/aikido/zen/version.rb +2 -2
- data/lib/aikido/zen/worker_process/agent/client.rb +6 -3
- data/lib/aikido/zen/worker_process/agent/server.rb +5 -5
- data/lib/aikido/zen.rb +140 -9
- metadata +7 -4
- data/lib/aikido/zen/libzen-v0.1.61-arm64-linux.so +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4a5bcdcebf3bfc75ca73930731383ef5b9456a622ed73c0161a5f0fb251ddb63
|
|
4
|
+
data.tar.gz: ae27ec6d8ae8787e1c9a8b8d9ddb1948a8567b15afa025e512cca00790882fa7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a0ed34a74615eca6ddfee2df194a8781bf2262ad40321bf8bd44866dd1dee2c33c9584f48b312722ed650a73bf3d174349e936011e5ceebfa643477e1de291d4
|
|
7
|
+
data.tar.gz: 3af7433a023446c2e0d29918881a8422b047f5a5cd8331741a64d7d16885a56b7e8f648d1db3bc514c4edfbd1deda457db8fd82632bcb9eae5071b24d0526640
|
data/README.md
CHANGED
|
@@ -39,6 +39,12 @@ Zen for Ruby 2.7+ is compatible with:
|
|
|
39
39
|
|
|
40
40
|
* ✅ [Ruby on Rails](docs/rails.md) 7.x, 8.x
|
|
41
41
|
|
|
42
|
+
### Application servers
|
|
43
|
+
|
|
44
|
+
* ✅ [Puma](https://puma.io/)
|
|
45
|
+
|
|
46
|
+
Our test suite only covers Puma. If you use another Rack server, [contact us](docs/troubleshooting.md#contact-support) and we'll help check whether Zen is compatible.
|
|
47
|
+
|
|
42
48
|
### Database drivers
|
|
43
49
|
|
|
44
50
|
* ✅ [`sqlite3`](https://github.com/sparklemotion/sqlite3-ruby) 1.x, 2.x
|
|
@@ -117,7 +123,8 @@ See [Reporting to Aikido](#reporting-to-your-aikido-security-dashboard) to learn
|
|
|
117
123
|
|
|
118
124
|
## Additional configuration
|
|
119
125
|
|
|
120
|
-
[Configure Zen using environment variables for authentication, mode settings, debugging, and more
|
|
126
|
+
* [Configure Zen using environment variables for authentication, mode settings, debugging, and more](https://help.aikido.dev/doc/configuration-via-env-vars/docrSItUkeR9)
|
|
127
|
+
* [Track custom events](docs/custom-event-tracking.md): trigger events that Playbooks can act on
|
|
121
128
|
|
|
122
129
|
## License
|
|
123
130
|
|
|
@@ -24,7 +24,7 @@ end
|
|
|
24
24
|
if __FILE__ == $0
|
|
25
25
|
ip_ranges = random_ip_ranges.take(1000)
|
|
26
26
|
|
|
27
|
-
ip_list = Aikido::Zen::
|
|
27
|
+
ip_list = Aikido::Zen::Firewall::IPList.from_json({
|
|
28
28
|
"key" => "key",
|
|
29
29
|
"source" => "source",
|
|
30
30
|
"description" => "description",
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# Track custom events
|
|
2
|
+
|
|
3
|
+
Use `Aikido::Zen.track` to report events that only your application knows about, such as failed logins. [Playbooks](https://help.aikido.dev/zen-firewall/zen-features/playbooks) can act when an event occurs repeatedly, for example by blocking an IP after three failed logins in five minutes.
|
|
4
|
+
|
|
5
|
+
```ruby
|
|
6
|
+
# app/controllers/application_controller.rb
|
|
7
|
+
class ApplicationController < ActionController::Base
|
|
8
|
+
private
|
|
9
|
+
|
|
10
|
+
def authenticate_user!
|
|
11
|
+
# Your authentication logic here
|
|
12
|
+
# ...
|
|
13
|
+
|
|
14
|
+
unless current_user
|
|
15
|
+
Aikido::Zen.track("user.login_failed")
|
|
16
|
+
return
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
Aikido::Zen.set_user(
|
|
20
|
+
id: current_user.id,
|
|
21
|
+
name: current_user.name
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
Aikido::Zen.track("user.login_succeeded")
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
After adding `Aikido::Zen.track`, trigger the event at least once. It will then appear on the Playbooks page in the Aikido dashboard. From there, you can create a playbook and choose what should happen when the event occurs. Calling `Aikido::Zen.track` by itself does not create a playbook or block anything.
|
|
30
|
+
|
|
31
|
+
Call `Aikido::Zen.track` while handling an HTTP request. Zen associates the event with the request's IP address. Playbook counts are per IP, not across your whole app. If you call [`Aikido::Zen.set_user`](./rails.md#rate-limiting-and-user-blocking) before tracking the event, Zen also includes the current user. `Aikido::Zen.set_user` is optional. Events without a user are still tracked.
|
|
32
|
+
|
|
33
|
+
Event names can use any format. We recommend lowercase, dot-separated names such as `user.login_failed`.
|
data/docs/rails.md
CHANGED
|
@@ -75,6 +75,20 @@ class ApplicationController < ActionController::Base
|
|
|
75
75
|
end
|
|
76
76
|
```
|
|
77
77
|
|
|
78
|
+
### Rate limiting groups
|
|
79
|
+
|
|
80
|
+
To limit the number of requests for a group of users, you can use the
|
|
81
|
+
`Aikido::Zen.set_rate_limit_group` method. For example, this is useful if you
|
|
82
|
+
want to limit the number of requests per team or company.
|
|
83
|
+
|
|
84
|
+
```ruby
|
|
85
|
+
Aikido::Zen.set_rate_limit_group(current_user.team_id)
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
> [!NOTE]
|
|
89
|
+
> If a rate limiting group is set, the configured rate limits are only applied
|
|
90
|
+
> to the group and not to individual users or IP addresses.
|
|
91
|
+
|
|
78
92
|
## Configuration
|
|
79
93
|
|
|
80
94
|
Zen exposes its configuration object to the Rails configuration, which you can
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# Bypass Zen for a specific request
|
|
2
|
+
|
|
3
|
+
Call `Aikido::Zen.request_bypassed!` from a Rack middleware to bypass Zen for this request. A bypassed request is fully excluded from Zen inspection and enforcement: Zen will not analyze the request, generate findings, or apply blocking rules for that traffic. Your application handles the request normally.
|
|
4
|
+
|
|
5
|
+
> [!NOTE]
|
|
6
|
+
> Zen's built-in [Bypassed IPs](https://help.aikido.dev/zen-firewall/zen-features/bypassed-ips) feature uses request bypassing internally, triggered by a matching IP/CIDR. `Aikido::Zen.request_bypassed!` lets you bypass requests using your custom logic.
|
|
7
|
+
|
|
8
|
+
## What gets bypassed
|
|
9
|
+
|
|
10
|
+
* **Attack protection** — SQL injection, path traversal, command injection, and SSRF attacks are not blocked or reported
|
|
11
|
+
* **Rate limiting** — never triggered.
|
|
12
|
+
* **IP blocking** — Known Threat Actors, Tor traffic blocking/monitoring, country blocking, and custom IP allow/block lists are not checked.
|
|
13
|
+
* **Bot traffic blocking** — not checked.
|
|
14
|
+
* **User blocking** — blocked users are not blocked.
|
|
15
|
+
* **Statistics** — the request isn't counted, and doesn't count against your monitored request quota.
|
|
16
|
+
* **Attack wave protection** — the request doesn't count towards wave detection.
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
Insert your middleware directly after `Aikido::Zen::Middleware::ContextSetter`, so it runs after the request context is set up but before Zen's other middleware:
|
|
21
|
+
|
|
22
|
+
```ruby
|
|
23
|
+
# config/application.rb
|
|
24
|
+
class RequestBypasser
|
|
25
|
+
def initialize(app)
|
|
26
|
+
@app = app
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def call(env)
|
|
30
|
+
if your_custom_logic?(env)
|
|
31
|
+
Aikido::Zen.request_bypassed! # Bypasses Zen for this request
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
@app.call(env)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
module YourApp
|
|
39
|
+
class Application < Rails::Application
|
|
40
|
+
# ...
|
|
41
|
+
|
|
42
|
+
initializer "your_app.insert_request_bypasser", after: "aikido.add_middleware" do |app|
|
|
43
|
+
app.middleware.insert_after Aikido::Zen::Middleware::ContextSetter, RequestBypasser
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
> [!WARNING]
|
|
50
|
+
> A bypassed request gets zero protection from Zen — no attack detection, no rate limiting, no blocking, no tracking. Ensure that your custom logic only bypasses requests that you fully trust.
|
data/lib/aikido/zen/agent.rb
CHANGED
|
@@ -68,27 +68,22 @@ module Aikido::Zen
|
|
|
68
68
|
# :nocov:
|
|
69
69
|
|
|
70
70
|
report(Events::Started.new(time: @started_at)) do |response|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if @config.realtime_settings_updates_enabled? || @settings.realtime_settings_updates_enabled?
|
|
75
|
-
@api_stream.handle("config-updated") do |event|
|
|
76
|
-
@config.logger.debug("Received server-sent event: config-updated")
|
|
77
|
-
settings_updated(event)
|
|
78
|
-
end
|
|
71
|
+
update_settings_from_runtime_config!(response, reason: "after start")
|
|
72
|
+
updated_settings!
|
|
79
73
|
|
|
80
|
-
|
|
74
|
+
if @config.realtime_settings_updates_enabled? || @settings.realtime_settings_updates_enabled?
|
|
75
|
+
@api_stream.handle("config-updated") do |event|
|
|
76
|
+
@config.logger.debug("Received server-sent event: config-updated")
|
|
77
|
+
settings_updated(event)
|
|
81
78
|
end
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
# empty
|
|
79
|
+
|
|
80
|
+
@api_stream.start!
|
|
85
81
|
end
|
|
86
|
-
# :nocov:
|
|
87
82
|
rescue => err
|
|
88
83
|
@config.logger.error(err.message)
|
|
89
84
|
end
|
|
90
85
|
|
|
91
|
-
|
|
86
|
+
@worker.perform do
|
|
92
87
|
update_settings_from_runtime_firewall_lists!(@api_client.fetch_runtime_firewall_lists, reason: "after start")
|
|
93
88
|
rescue => err
|
|
94
89
|
@config.logger.error(err.message)
|
|
@@ -139,12 +134,19 @@ module Aikido::Zen
|
|
|
139
134
|
def handle_attack(attack)
|
|
140
135
|
attack.will_be_blocked! if Aikido::Zen.blocking_mode?
|
|
141
136
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
137
|
+
# Recording the attack must never prevent us from blocking it.
|
|
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
|
+
)
|
|
142
|
+
|
|
143
|
+
report(Events::Attack.new(attack: attack)) if @api_client.can_make_requests?
|
|
144
|
+
|
|
145
|
+
@collector.track_attack(attack)
|
|
146
|
+
rescue => err
|
|
147
|
+
@config.logger.error("Zen failed to record an attack: #{err.class}: #{err.message}")
|
|
148
|
+
end
|
|
146
149
|
|
|
147
|
-
@collector.track_attack(attack)
|
|
148
150
|
raise attack if attack.blocked?
|
|
149
151
|
end
|
|
150
152
|
|
|
@@ -165,6 +167,15 @@ module Aikido::Zen
|
|
|
165
167
|
end
|
|
166
168
|
end
|
|
167
169
|
|
|
170
|
+
# Reports a custom event tracked via Aikido::Zen.track, if
|
|
171
|
+
# reporting is enabled.
|
|
172
|
+
#
|
|
173
|
+
# @param event [Aikido::Zen::Events::Custom]
|
|
174
|
+
# @return [void]
|
|
175
|
+
def report_custom_event(event)
|
|
176
|
+
report(event) if @api_client.can_make_requests?
|
|
177
|
+
end
|
|
178
|
+
|
|
168
179
|
# @api private
|
|
169
180
|
#
|
|
170
181
|
# Atomically flushes all the stats stored by the agent, and sends a
|
|
@@ -220,6 +231,8 @@ module Aikido::Zen
|
|
|
220
231
|
updated_at = Time.at(event[:data]["configUpdatedAt"].to_i)
|
|
221
232
|
|
|
222
233
|
if should_fetch_settings?(updated_at)
|
|
234
|
+
return if realtime_settings_updates_too_fast?
|
|
235
|
+
|
|
223
236
|
if update_settings_from_runtime_config!(@api_client.fetch_runtime_config, reason: "after server-sent event")
|
|
224
237
|
updated_settings!
|
|
225
238
|
|
|
@@ -239,6 +252,19 @@ module Aikido::Zen
|
|
|
239
252
|
updated_at > last_updated_at
|
|
240
253
|
end
|
|
241
254
|
|
|
255
|
+
def realtime_settings_updates_too_fast?
|
|
256
|
+
now = Process.clock_gettime(Process::CLOCK_MONOTONIC, :millisecond)
|
|
257
|
+
|
|
258
|
+
last_updated_at = @realtime_settings_updates_last_updated_at
|
|
259
|
+
if last_updated_at && now - last_updated_at < @config.realtime_settings_updates_min_time_between_events
|
|
260
|
+
return true
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
@realtime_settings_updates_last_updated_at = now
|
|
264
|
+
|
|
265
|
+
false
|
|
266
|
+
end
|
|
267
|
+
|
|
242
268
|
def heartbeats
|
|
243
269
|
@heartbeats ||= Aikido::Zen::Agent::HeartbeatsManager.new(
|
|
244
270
|
config: @config,
|
|
@@ -257,7 +283,7 @@ module Aikido::Zen
|
|
|
257
283
|
begin
|
|
258
284
|
return false unless Aikido::Zen.api_cache.update_runtime_config(data)
|
|
259
285
|
|
|
260
|
-
if Aikido::Zen.runtime_settings.
|
|
286
|
+
if Aikido::Zen.runtime_settings.update_from_json(data)
|
|
261
287
|
@config.logger.info("Updated runtime settings #{reason}")
|
|
262
288
|
true
|
|
263
289
|
else
|
|
@@ -279,7 +305,7 @@ module Aikido::Zen
|
|
|
279
305
|
begin
|
|
280
306
|
return false unless Aikido::Zen.api_cache.update_runtime_firewall_lists(data)
|
|
281
307
|
|
|
282
|
-
if Aikido::Zen.
|
|
308
|
+
if Aikido::Zen.firewall.update_from_json(data)
|
|
283
309
|
@config.logger.info("Updated runtime firewall list #{reason}")
|
|
284
310
|
true
|
|
285
311
|
else
|
data/lib/aikido/zen/attack.rb
CHANGED
|
@@ -69,8 +69,10 @@ module Aikido::Zen
|
|
|
69
69
|
end
|
|
70
70
|
|
|
71
71
|
def metadata
|
|
72
|
+
safe_filepath = Aikido::Zen::Helpers.encode_safely(filepath)
|
|
73
|
+
|
|
72
74
|
{
|
|
73
|
-
"filename" =>
|
|
75
|
+
"filename" => safe_filepath
|
|
74
76
|
}
|
|
75
77
|
end
|
|
76
78
|
|
|
@@ -106,8 +108,10 @@ module Aikido::Zen
|
|
|
106
108
|
end
|
|
107
109
|
|
|
108
110
|
def metadata
|
|
111
|
+
safe_command = Aikido::Zen::Helpers.encode_safely(@command)
|
|
112
|
+
|
|
109
113
|
{
|
|
110
|
-
"command" =>
|
|
114
|
+
"command" => safe_command
|
|
111
115
|
}
|
|
112
116
|
end
|
|
113
117
|
|
|
@@ -138,8 +142,10 @@ module Aikido::Zen
|
|
|
138
142
|
end
|
|
139
143
|
|
|
140
144
|
def metadata
|
|
145
|
+
safe_query = Aikido::Zen::Helpers.encode_safely(@query)
|
|
146
|
+
|
|
141
147
|
{
|
|
142
|
-
"sql" =>
|
|
148
|
+
"sql" => safe_query,
|
|
143
149
|
"dialect" => @dialect.name,
|
|
144
150
|
"failedToTokenize" => @failed_to_tokenize || nil
|
|
145
151
|
}.compact
|
|
@@ -157,14 +157,16 @@ module Aikido::Zen
|
|
|
157
157
|
def self.from_json(data)
|
|
158
158
|
new(
|
|
159
159
|
data["sink_name"],
|
|
160
|
+
data["sink_kind"],
|
|
160
161
|
data["duration"],
|
|
161
162
|
has_errors: data["has_errors"]
|
|
162
163
|
)
|
|
163
164
|
end
|
|
164
165
|
|
|
165
|
-
def initialize(sink_name, duration, has_errors:)
|
|
166
|
+
def initialize(sink_name, sink_kind, duration, has_errors:)
|
|
166
167
|
super()
|
|
167
168
|
@sink_name = sink_name
|
|
169
|
+
@sink_kind = sink_kind
|
|
168
170
|
@duration = duration
|
|
169
171
|
@has_errors = has_errors
|
|
170
172
|
end
|
|
@@ -172,17 +174,18 @@ module Aikido::Zen
|
|
|
172
174
|
def as_json
|
|
173
175
|
super.update({
|
|
174
176
|
"sink_name" => @sink_name,
|
|
177
|
+
"sink_kind" => @sink_kind,
|
|
175
178
|
"duration" => @duration,
|
|
176
179
|
"has_errors" => @has_errors
|
|
177
180
|
})
|
|
178
181
|
end
|
|
179
182
|
|
|
180
183
|
def handle(collector)
|
|
181
|
-
collector.handle_track_scan(@sink_name, @duration, has_errors: @has_errors)
|
|
184
|
+
collector.handle_track_scan(@sink_name, @sink_kind, @duration, has_errors: @has_errors)
|
|
182
185
|
end
|
|
183
186
|
|
|
184
187
|
def inspect
|
|
185
|
-
"#<#{self.class.name} #{@sink_name} #{format "%0.6f", @duration} #{@has_errors}>"
|
|
188
|
+
"#<#{self.class.name} #{@sink_name} #{@sink_kind} #{format "%0.6f", @duration} #{@has_errors}>"
|
|
186
189
|
end
|
|
187
190
|
end
|
|
188
191
|
|
|
@@ -192,29 +195,32 @@ module Aikido::Zen
|
|
|
192
195
|
def self.from_json(data)
|
|
193
196
|
new(
|
|
194
197
|
data["sink_name"],
|
|
198
|
+
data["sink_kind"],
|
|
195
199
|
being_blocked: data["being_blocked"]
|
|
196
200
|
)
|
|
197
201
|
end
|
|
198
202
|
|
|
199
|
-
def initialize(sink_name, being_blocked:)
|
|
203
|
+
def initialize(sink_name, sink_kind, being_blocked:)
|
|
200
204
|
super()
|
|
201
205
|
@sink_name = sink_name
|
|
206
|
+
@sink_kind = sink_kind
|
|
202
207
|
@being_blocked = being_blocked
|
|
203
208
|
end
|
|
204
209
|
|
|
205
210
|
def as_json
|
|
206
211
|
super.update({
|
|
207
212
|
"sink_name" => @sink_name,
|
|
213
|
+
"sink_kind" => @sink_kind,
|
|
208
214
|
"being_blocked" => @being_blocked
|
|
209
215
|
})
|
|
210
216
|
end
|
|
211
217
|
|
|
212
218
|
def handle(collector)
|
|
213
|
-
collector.handle_track_attack(@sink_name, being_blocked: @being_blocked)
|
|
219
|
+
collector.handle_track_attack(@sink_name, @sink_kind, being_blocked: @being_blocked)
|
|
214
220
|
end
|
|
215
221
|
|
|
216
222
|
def inspect
|
|
217
|
-
"#<#{self.class.name} #{@sink_name} #{@being_blocked}>"
|
|
223
|
+
"#<#{self.class.name} #{@sink_name} #{@sink_kind} #{@being_blocked}>"
|
|
218
224
|
end
|
|
219
225
|
end
|
|
220
226
|
|
|
@@ -7,6 +7,9 @@ module Aikido::Zen
|
|
|
7
7
|
#
|
|
8
8
|
# Tracks data specific to a single Sink.
|
|
9
9
|
class Collector::SinkStats
|
|
10
|
+
# @return [String] category of operation this sink represents.
|
|
11
|
+
attr_accessor :kind
|
|
12
|
+
|
|
10
13
|
# @return [Integer] number of total calls to Sink#scan.
|
|
11
14
|
attr_accessor :scans
|
|
12
15
|
|
|
@@ -62,6 +65,7 @@ module Aikido::Zen
|
|
|
62
65
|
|
|
63
66
|
def as_json
|
|
64
67
|
{
|
|
68
|
+
"kind" => @kind,
|
|
65
69
|
"total" => @scans,
|
|
66
70
|
"interceptorThrewError" => @errors,
|
|
67
71
|
"withoutContext" => 0,
|
|
@@ -94,21 +94,25 @@ module Aikido::Zen
|
|
|
94
94
|
end
|
|
95
95
|
|
|
96
96
|
# @param sink_name [String] the name of the sink
|
|
97
|
+
# @param sink_kind [String] the category of operation the sink represents
|
|
97
98
|
# @param duration [Float] the length the scan in seconds
|
|
98
99
|
# @param has_errors [Boolean] whether errors occurred during the scan
|
|
99
100
|
# @return [void]
|
|
100
|
-
def add_scan(sink_name, duration, has_errors:)
|
|
101
|
+
def add_scan(sink_name, sink_kind, duration, has_errors:)
|
|
101
102
|
stats = @sinks[sink_name]
|
|
103
|
+
stats.kind = sink_kind
|
|
102
104
|
stats.scans += 1
|
|
103
105
|
stats.errors += 1 if has_errors
|
|
104
106
|
stats.add_timing(duration)
|
|
105
107
|
end
|
|
106
108
|
|
|
107
109
|
# @param sink_name [String] the name of the sink
|
|
110
|
+
# @param sink_kind [String] the category of operation the sink represents
|
|
108
111
|
# @param being_blocked [Boolean] whether the Agent blocked the request
|
|
109
112
|
# @return [void]
|
|
110
|
-
def add_attack(sink_name, being_blocked:)
|
|
113
|
+
def add_attack(sink_name, sink_kind, being_blocked:)
|
|
111
114
|
stats = @sinks[sink_name]
|
|
115
|
+
stats.kind = sink_kind
|
|
112
116
|
stats.attacks += 1
|
|
113
117
|
stats.blocked_attacks += 1 if being_blocked
|
|
114
118
|
end
|
data/lib/aikido/zen/collector.rb
CHANGED
|
@@ -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.duration, has_errors: scan.errors?))
|
|
149
|
+
add_event(Events::TrackScan.new(scan.sink.name, scan.sink.kind, scan.duration, has_errors: scan.errors?))
|
|
150
150
|
end
|
|
151
151
|
|
|
152
|
-
def handle_track_scan(sink_name, duration, has_errors:)
|
|
152
|
+
def handle_track_scan(sink_name, sink_kind, duration, has_errors:)
|
|
153
153
|
synchronize(@stats) do |stats|
|
|
154
|
-
stats.add_scan(sink_name, duration, has_errors: has_errors)
|
|
154
|
+
stats.add_scan(sink_name, sink_kind, duration, has_errors: has_errors)
|
|
155
155
|
end
|
|
156
156
|
end
|
|
157
157
|
|
|
@@ -160,12 +160,12 @@ module Aikido::Zen
|
|
|
160
160
|
# @param attack [Aikido::Zen::Attack]
|
|
161
161
|
# @return [void]
|
|
162
162
|
def track_attack(attack)
|
|
163
|
-
add_event(Events::TrackAttack.new(attack.sink.name, being_blocked: attack.blocked?))
|
|
163
|
+
add_event(Events::TrackAttack.new(attack.sink.name, attack.sink.kind, being_blocked: attack.blocked?))
|
|
164
164
|
end
|
|
165
165
|
|
|
166
|
-
def handle_track_attack(sink_name, being_blocked:)
|
|
166
|
+
def handle_track_attack(sink_name, sink_kind, being_blocked:)
|
|
167
167
|
synchronize(@stats) do |stats|
|
|
168
|
-
stats.add_attack(sink_name, being_blocked: being_blocked)
|
|
168
|
+
stats.add_attack(sink_name, sink_kind, being_blocked: being_blocked)
|
|
169
169
|
end
|
|
170
170
|
end
|
|
171
171
|
|
data/lib/aikido/zen/config.rb
CHANGED
|
@@ -42,7 +42,7 @@ module Aikido::Zen
|
|
|
42
42
|
attr_reader :api_endpoint
|
|
43
43
|
|
|
44
44
|
# @return [URI] The HTTP host for the Aikido Runtime API. Defaults to
|
|
45
|
-
# +https://
|
|
45
|
+
# +https://guard.aikido.dev+.
|
|
46
46
|
attr_reader :realtime_endpoint
|
|
47
47
|
|
|
48
48
|
# @return [Hash] HTTP timeouts for communicating with the API.
|
|
@@ -56,6 +56,14 @@ module Aikido::Zen
|
|
|
56
56
|
# each initial heartbeat event.
|
|
57
57
|
attr_accessor :initial_heartbeat_delays
|
|
58
58
|
|
|
59
|
+
# @return [Integer] the maximum number of levels deep we want to traverse
|
|
60
|
+
# when extracting payloads from a nested request property. Defaults to 64.
|
|
61
|
+
attr_accessor :extract_payloads_max_depth
|
|
62
|
+
|
|
63
|
+
# @return [Symbol] the agent mode for forked worker processes. Can be set
|
|
64
|
+
# through the AIKIDO_AGENT_MODE environment variable.
|
|
65
|
+
attr_reader :agent_mode
|
|
66
|
+
|
|
59
67
|
# @return [Integer] the interval in seconds at which forked worker processes
|
|
60
68
|
# poll the parent process for updated runtime settings. Defaults to 10 seconds.
|
|
61
69
|
attr_accessor :worker_process_polling_interval
|
|
@@ -103,6 +111,10 @@ module Aikido::Zen
|
|
|
103
111
|
# the oldest seen users.
|
|
104
112
|
attr_accessor :max_users_tracked
|
|
105
113
|
|
|
114
|
+
# @return [Integer] the maximum number of custom events tracked per request.
|
|
115
|
+
# Defaults to 25.
|
|
116
|
+
attr_accessor :max_custom_events
|
|
117
|
+
|
|
106
118
|
# @return [Proc{(Aikido::Zen::Request, Symbol, reason: String=nil) => Array(Integer, Hash, #each)}]
|
|
107
119
|
# Rack handler used to respond to requests from IPs, users or others blocked in the Aikido
|
|
108
120
|
# dashboard.
|
|
@@ -229,6 +241,11 @@ module Aikido::Zen
|
|
|
229
241
|
attr_accessor :realtime_settings_updates_enabled
|
|
230
242
|
alias_method :realtime_settings_updates_enabled?, :realtime_settings_updates_enabled
|
|
231
243
|
|
|
244
|
+
# @return [Integer] the minimum time in milliseconds between realtime
|
|
245
|
+
# settings updates.
|
|
246
|
+
# Defaults to 9 seconds in milliseconds.
|
|
247
|
+
attr_accessor :realtime_settings_updates_min_time_between_events
|
|
248
|
+
|
|
232
249
|
def initialize
|
|
233
250
|
self.insert_middleware_after = ::ActionDispatch::RemoteIp
|
|
234
251
|
self.disabled = read_boolean_from_env(ENV.fetch("AIKIDO_DISABLE", false)) || read_boolean_from_env(ENV.fetch("AIKIDO_DISABLED", false))
|
|
@@ -236,10 +253,12 @@ module Aikido::Zen
|
|
|
236
253
|
self.debugging = read_boolean_from_env(ENV.fetch("AIKIDO_DEBUG", false))
|
|
237
254
|
self.api_token = ENV.fetch("AIKIDO_TOKEN", nil)
|
|
238
255
|
self.api_endpoint = ENV.fetch("AIKIDO_ENDPOINT") { regional_api_endpoint(api_token) }
|
|
239
|
-
self.realtime_endpoint =
|
|
256
|
+
self.realtime_endpoint = api_endpoint
|
|
240
257
|
self.api_timeouts = 10
|
|
241
258
|
self.polling_interval = 60 # 1 min
|
|
242
259
|
self.initial_heartbeat_delays = [30, 60 * 2] # 30 sec, 2 min
|
|
260
|
+
self.extract_payloads_max_depth = 64
|
|
261
|
+
self.agent_mode = ENV.fetch("AIKIDO_AGENT_MODE", "shared")
|
|
243
262
|
self.worker_process_polling_interval = 10
|
|
244
263
|
self.worker_process_polling_jitter = 10
|
|
245
264
|
self.worker_process_heartbeat_interval = 10
|
|
@@ -251,6 +270,7 @@ module Aikido::Zen
|
|
|
251
270
|
self.max_compressed_stats = 100
|
|
252
271
|
self.max_outbound_connections = 200
|
|
253
272
|
self.max_users_tracked = 1000
|
|
273
|
+
self.max_custom_events = 25
|
|
254
274
|
self.blocked_responder = DEFAULT_BLOCKED_RESPONDER
|
|
255
275
|
self.rate_limited_responder = DEFAULT_RATE_LIMITED_RESPONDER
|
|
256
276
|
self.rate_limiting_discriminator = DEFAULT_RATE_LIMITING_DISCRIMINATOR
|
|
@@ -277,6 +297,7 @@ module Aikido::Zen
|
|
|
277
297
|
self.idor_excluded_table_names = []
|
|
278
298
|
self.idor_max_cache_entries = 1000
|
|
279
299
|
self.realtime_settings_updates_enabled = false
|
|
300
|
+
self.realtime_settings_updates_min_time_between_events = 9 * 1000 # 9 sec (ms)
|
|
280
301
|
end
|
|
281
302
|
|
|
282
303
|
# Set the base URL for API requests.
|
|
@@ -293,6 +314,17 @@ module Aikido::Zen
|
|
|
293
314
|
@realtime_endpoint = URI(url)
|
|
294
315
|
end
|
|
295
316
|
|
|
317
|
+
# @param mode [Symbol, String] a supported agent mode.
|
|
318
|
+
# @raise [ArgumentError]
|
|
319
|
+
def agent_mode=(mode)
|
|
320
|
+
mode = mode.to_sym
|
|
321
|
+
unless AGENT_MODES.include?(mode)
|
|
322
|
+
raise ArgumentError, "agent_mode must be one of #{AGENT_MODES.join(", ")}, got #{mode}"
|
|
323
|
+
end
|
|
324
|
+
|
|
325
|
+
@agent_mode = mode
|
|
326
|
+
end
|
|
327
|
+
|
|
296
328
|
# Set the logger and configure its severity level according to agent's debug mode
|
|
297
329
|
# @param logger [::Logger]
|
|
298
330
|
def logger=(logger)
|
|
@@ -364,6 +396,9 @@ module Aikido::Zen
|
|
|
364
396
|
end
|
|
365
397
|
end
|
|
366
398
|
|
|
399
|
+
# @!visibility private
|
|
400
|
+
AGENT_MODES = [:shared, :per_worker].freeze
|
|
401
|
+
|
|
367
402
|
# @!visibility private
|
|
368
403
|
DEFAULT_AIKIDO_ENDPOINT = "https://guard.aikido.dev"
|
|
369
404
|
|
|
@@ -377,9 +412,6 @@ module Aikido::Zen
|
|
|
377
412
|
"AU" => "https://guard.au.aikido.dev"
|
|
378
413
|
}.freeze
|
|
379
414
|
|
|
380
|
-
# @!visibility private
|
|
381
|
-
DEFAULT_RUNTIME_BASE_URL = "https://runtime.aikido.dev"
|
|
382
|
-
|
|
383
415
|
# @!visibility private
|
|
384
416
|
DEFAULT_JSON_ENCODER = JSON.method(:dump)
|
|
385
417
|
|
|
@@ -420,7 +452,13 @@ module Aikido::Zen
|
|
|
420
452
|
|
|
421
453
|
# @!visibility private
|
|
422
454
|
DEFAULT_RATE_LIMITING_DISCRIMINATOR = ->(request) {
|
|
423
|
-
|
|
455
|
+
rate_limiting_group = request.rate_limiting_group
|
|
456
|
+
return "group:#{rate_limiting_group}" unless rate_limiting_group.nil?
|
|
457
|
+
|
|
458
|
+
actor = request.actor
|
|
459
|
+
return "actor:#{request.actor.id}" unless actor.nil?
|
|
460
|
+
|
|
461
|
+
request.client_ip
|
|
424
462
|
}
|
|
425
463
|
end
|
|
426
464
|
end
|