aikido-zen 1.0.2.beta.2-aarch64-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 +7 -0
- data/.aikido +6 -0
- data/.ruby-version +1 -0
- data/.simplecov +26 -0
- data/.standard.yml +3 -0
- data/LICENSE +674 -0
- data/README.md +146 -0
- data/Rakefile +67 -0
- data/benchmarks/README.md +23 -0
- data/benchmarks/rails7.1_sql_injection.js +70 -0
- data/docs/banner.svg +202 -0
- data/docs/config.md +125 -0
- data/docs/proxy.md +10 -0
- data/docs/rails.md +114 -0
- data/lib/aikido/zen/actor.rb +116 -0
- data/lib/aikido/zen/agent/heartbeats_manager.rb +66 -0
- data/lib/aikido/zen/agent.rb +179 -0
- data/lib/aikido/zen/api_client.rb +145 -0
- data/lib/aikido/zen/attack.rb +207 -0
- data/lib/aikido/zen/background_worker.rb +52 -0
- data/lib/aikido/zen/capped_collections.rb +68 -0
- data/lib/aikido/zen/collector/hosts.rb +15 -0
- data/lib/aikido/zen/collector/routes.rb +66 -0
- data/lib/aikido/zen/collector/sink_stats.rb +95 -0
- data/lib/aikido/zen/collector/stats.rb +111 -0
- data/lib/aikido/zen/collector/users.rb +30 -0
- data/lib/aikido/zen/collector.rb +144 -0
- data/lib/aikido/zen/config.rb +282 -0
- data/lib/aikido/zen/context/rack_request.rb +24 -0
- data/lib/aikido/zen/context/rails_request.rb +44 -0
- data/lib/aikido/zen/context.rb +112 -0
- data/lib/aikido/zen/detached_agent/agent.rb +78 -0
- data/lib/aikido/zen/detached_agent/front_object.rb +37 -0
- data/lib/aikido/zen/detached_agent/server.rb +78 -0
- data/lib/aikido/zen/detached_agent.rb +2 -0
- data/lib/aikido/zen/errors.rb +107 -0
- data/lib/aikido/zen/event.rb +71 -0
- data/lib/aikido/zen/internals.rb +103 -0
- data/lib/aikido/zen/libzen-v0.1.39-aarch64-linux.so +0 -0
- data/lib/aikido/zen/middleware/check_allowed_addresses.rb +26 -0
- data/lib/aikido/zen/middleware/middleware.rb +11 -0
- data/lib/aikido/zen/middleware/rack_throttler.rb +48 -0
- data/lib/aikido/zen/middleware/request_tracker.rb +192 -0
- data/lib/aikido/zen/middleware/set_context.rb +26 -0
- data/lib/aikido/zen/outbound_connection.rb +45 -0
- data/lib/aikido/zen/outbound_connection_monitor.rb +23 -0
- data/lib/aikido/zen/package.rb +22 -0
- data/lib/aikido/zen/payload.rb +50 -0
- data/lib/aikido/zen/rails_engine.rb +56 -0
- data/lib/aikido/zen/rate_limiter/breaker.rb +61 -0
- data/lib/aikido/zen/rate_limiter/bucket.rb +76 -0
- data/lib/aikido/zen/rate_limiter/result.rb +31 -0
- data/lib/aikido/zen/rate_limiter.rb +50 -0
- data/lib/aikido/zen/request/heuristic_router.rb +115 -0
- data/lib/aikido/zen/request/rails_router.rb +77 -0
- data/lib/aikido/zen/request/schema/auth_discovery.rb +86 -0
- data/lib/aikido/zen/request/schema/auth_schemas.rb +54 -0
- data/lib/aikido/zen/request/schema/builder.rb +121 -0
- data/lib/aikido/zen/request/schema/definition.rb +107 -0
- data/lib/aikido/zen/request/schema/empty_schema.rb +28 -0
- data/lib/aikido/zen/request/schema.rb +87 -0
- data/lib/aikido/zen/request.rb +122 -0
- data/lib/aikido/zen/route.rb +39 -0
- data/lib/aikido/zen/runtime_settings/endpoints.rb +49 -0
- data/lib/aikido/zen/runtime_settings/ip_set.rb +36 -0
- data/lib/aikido/zen/runtime_settings/protection_settings.rb +62 -0
- data/lib/aikido/zen/runtime_settings/rate_limit_settings.rb +47 -0
- data/lib/aikido/zen/runtime_settings.rb +65 -0
- data/lib/aikido/zen/scan.rb +75 -0
- data/lib/aikido/zen/scanners/path_traversal/helpers.rb +65 -0
- data/lib/aikido/zen/scanners/path_traversal_scanner.rb +63 -0
- data/lib/aikido/zen/scanners/shell_injection/helpers.rb +159 -0
- data/lib/aikido/zen/scanners/shell_injection_scanner.rb +64 -0
- data/lib/aikido/zen/scanners/sql_injection_scanner.rb +93 -0
- data/lib/aikido/zen/scanners/ssrf/dns_lookups.rb +27 -0
- data/lib/aikido/zen/scanners/ssrf/private_ip_checker.rb +97 -0
- data/lib/aikido/zen/scanners/ssrf_scanner.rb +265 -0
- data/lib/aikido/zen/scanners/stored_ssrf_scanner.rb +49 -0
- data/lib/aikido/zen/scanners.rb +7 -0
- data/lib/aikido/zen/sink.rb +118 -0
- data/lib/aikido/zen/sinks/action_controller.rb +83 -0
- data/lib/aikido/zen/sinks/async_http.rb +80 -0
- data/lib/aikido/zen/sinks/curb.rb +113 -0
- data/lib/aikido/zen/sinks/em_http.rb +83 -0
- data/lib/aikido/zen/sinks/excon.rb +118 -0
- data/lib/aikido/zen/sinks/file.rb +112 -0
- data/lib/aikido/zen/sinks/http.rb +93 -0
- data/lib/aikido/zen/sinks/httpclient.rb +95 -0
- data/lib/aikido/zen/sinks/httpx.rb +78 -0
- data/lib/aikido/zen/sinks/kernel.rb +33 -0
- data/lib/aikido/zen/sinks/mysql2.rb +31 -0
- data/lib/aikido/zen/sinks/net_http.rb +101 -0
- data/lib/aikido/zen/sinks/patron.rb +103 -0
- data/lib/aikido/zen/sinks/pg.rb +72 -0
- data/lib/aikido/zen/sinks/resolv.rb +62 -0
- data/lib/aikido/zen/sinks/socket.rb +78 -0
- data/lib/aikido/zen/sinks/sqlite3.rb +46 -0
- data/lib/aikido/zen/sinks/trilogy.rb +31 -0
- data/lib/aikido/zen/sinks/typhoeus.rb +78 -0
- data/lib/aikido/zen/sinks.rb +36 -0
- data/lib/aikido/zen/sinks_dsl.rb +250 -0
- data/lib/aikido/zen/synchronizable.rb +24 -0
- data/lib/aikido/zen/system_info.rb +84 -0
- data/lib/aikido/zen/version.rb +10 -0
- data/lib/aikido/zen/worker.rb +87 -0
- data/lib/aikido/zen.rb +246 -0
- data/lib/aikido-zen.rb +3 -0
- data/placeholder/.gitignore +4 -0
- data/placeholder/README.md +11 -0
- data/placeholder/Rakefile +75 -0
- data/placeholder/lib/placeholder.rb.template +3 -0
- data/placeholder/placeholder.gemspec.template +20 -0
- data/tasklib/bench.rake +94 -0
- data/tasklib/libzen.rake +133 -0
- data/tasklib/wrk.rb +88 -0
- metadata +205 -0
data/README.md
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+

|
2
|
+
|
3
|
+
# Zen, in-app firewall for Ruby | by Aikido
|
4
|
+
|
5
|
+
[](https://badge.fury.io/rb/aikido-zen)
|
6
|
+
[](http://makeapullrequest.com)
|
7
|
+
[](https://github.com/AikidoSec/firewall-ruby/actions/workflows/main.yml)
|
8
|
+
[](https://github.com/AikidoSec/firewall-ruby/actions/workflows/release.yml)
|
9
|
+
|
10
|
+
Zen, your in-app firewall for peace of mind - at runtime.
|
11
|
+
|
12
|
+
Zen by Aikido is an embedded Web Application Firewall that autonomously protects Ruby apps against common and critical attacks.
|
13
|
+
|
14
|
+
It protects your Ruby apps by preventing user input containing dangerous strings, which allow injection, pollution, and path traversal attacks. It runs on the same server as your Ruby app for simple [installation](#installation) and zero maintenance.
|
15
|
+
|
16
|
+
## Features
|
17
|
+
|
18
|
+
Zen will autonomously protect your Ruby applications against:
|
19
|
+
|
20
|
+
* 🛡️ [SQL injection attacks](https://www.aikido.dev/blog/the-state-of-sql-injections)
|
21
|
+
* 🛡️ [Server-side request forgery (SSRF)](https://github.com/AikidoSec/firewall-node/blob/main/docs/ssrf.md)
|
22
|
+
* 🛡️ [Command injection attacks](https://www.aikido.dev/blog/command-injection-in-2024-unpacked)
|
23
|
+
* 🛡️ [Path traversal attacks](https://www.aikido.dev/blog/path-traversal-in-2024-the-year-unpacked)
|
24
|
+
* 🛡️ [NoSQL injection attacks](https://www.aikido.dev/blog/web-application-security-vulnerabilities) (coming soon)
|
25
|
+
|
26
|
+
Zen operates autonomously on the same server as your Ruby app to:
|
27
|
+
|
28
|
+
* ✅ Secure your app like a classic web application firewall (WAF), but with none of the infrastructure or cost
|
29
|
+
* ✅ Rate limit specific API endpoints by IP or by user
|
30
|
+
* ✅ Allow you to block specific users manually
|
31
|
+
|
32
|
+
## Supported libraries and frameworks
|
33
|
+
|
34
|
+
Zen for Ruby 2.7+ is compatible with:
|
35
|
+
|
36
|
+
### Web frameworks
|
37
|
+
|
38
|
+
* ✅ [Ruby on Rails](docs/rails.md) 7.x, 8.x
|
39
|
+
|
40
|
+
### Database drivers
|
41
|
+
|
42
|
+
* ✅ [`sqlite3`](https://github.com/sparklemotion/sqlite3-ruby) 1.x, 2.x
|
43
|
+
* ✅ [`pg`](https://github.com/ged/ruby-pg) 1.x
|
44
|
+
* ✅ [`mysql2`](https://github.com/brianmario/mysql2) 0.x
|
45
|
+
* ✅ [`trilogy`](https://github.com/trilogy-libraries/trilogy) 2.x
|
46
|
+
|
47
|
+
### ORMs and query builders
|
48
|
+
|
49
|
+
See list above for supported database drivers.
|
50
|
+
|
51
|
+
* ✅ [ActiveRecord](https://github.com/rails/rails)
|
52
|
+
* ✅ [Sequel](https://github.com/jeremyevans/sequel)
|
53
|
+
|
54
|
+
### HTTP clients
|
55
|
+
|
56
|
+
* ✅ [`net-http`](https://github.com/ruby/net-http)
|
57
|
+
* ✅ [`http.rb`](https://github.com/httprb/http) 1.x, 2.x, 3.x, 4.x, 5.x
|
58
|
+
* ✅ [`httpx`](https://gitlab.com/os85/httpx) 1.x (1.1.3+)
|
59
|
+
* ✅ [`httpclient`](https://github.com/nahi/httpclient) 2.x, 3.x
|
60
|
+
* ✅ [`excon`](https://github.com/excon/excon) 0.x (0.50.0+), 1.x
|
61
|
+
* ✅ [`curb`](https://github.com/taf2/curb) 0.x (0.2.3+), 1.x
|
62
|
+
* ✅ [`patron`](https://github.com/toland/patron) 0.x (0.6.4+)
|
63
|
+
* ✅ [`typhoeus`](https://github.com/typhoeus/typhoeus) 0.x (0.5.0+), 1.x
|
64
|
+
* ✅ [`async-http`](https://github.com/socketry/async-http) 0.x (0.70.0+)
|
65
|
+
* ✅ [`em-http-request`](https://github.com/igrigorik/em-http-request) 1.x
|
66
|
+
|
67
|
+
## Installation
|
68
|
+
|
69
|
+
We recommend testing Zen locally or on staging before deploying to production.
|
70
|
+
|
71
|
+
```sh
|
72
|
+
bundle add aikido-zen
|
73
|
+
```
|
74
|
+
|
75
|
+
or, if not using bundler:
|
76
|
+
|
77
|
+
```sh
|
78
|
+
gem install aikido-zen
|
79
|
+
```
|
80
|
+
|
81
|
+
For framework specific instructions, check out our docs:
|
82
|
+
|
83
|
+
* [Ruby on Rails](docs/rails.md)
|
84
|
+
|
85
|
+
## Reporting to your Aikido Security dashboard
|
86
|
+
|
87
|
+
> Aikido is your no nonsense application security platform. One central system that scans your source code & cloud, shows you what vulnerabilities matter, and how to fix them - fast. So you can get back to building.
|
88
|
+
|
89
|
+
Zen is a new product by Aikido. Built for developers to level up their security. While Aikido scans, get Zen for always-on protection.
|
90
|
+
|
91
|
+
You can use some of Zen's features without Aikido, of course. Peace of mind is just a few lines of code away.
|
92
|
+
|
93
|
+
But you will get the most value by reporting your data to Aikido.
|
94
|
+
|
95
|
+
You will need an Aikido account and a token to report events to Aikido. If you don't have an account, you can [sign up for free](https://app.aikido.dev/login).
|
96
|
+
|
97
|
+
Here's how:
|
98
|
+
|
99
|
+
* [Log in to your Aikido account](https://app.aikido.dev/login).
|
100
|
+
* Go to [Zen](https://app.aikido.dev/runtime/services).
|
101
|
+
* Go to apps.
|
102
|
+
* Click on **Add app**.
|
103
|
+
* Choose a name for your app.
|
104
|
+
* Click **Generate token**.
|
105
|
+
* Copy the token.
|
106
|
+
* Set the token as an environment variable, `AIKIDO_TOKEN`, using [dotenv](https://github.com/bkeepers/dotenv) or another method of your choosing.
|
107
|
+
|
108
|
+
## Running in production (blocking) mode
|
109
|
+
|
110
|
+
By default, Zen will only detect and report attacks to Aikido.
|
111
|
+
|
112
|
+
To block requests, set the `AIKIDO_BLOCK` environment variable to `true`.
|
113
|
+
|
114
|
+
See [Reporting to Aikido](#reporting-to-your-aikido-security-dashboard) to learn how to send events to Aikido.
|
115
|
+
|
116
|
+
## Additional configuration
|
117
|
+
|
118
|
+
[Configure Zen using environment variables for authentication, mode settings, debugging, and more.](https://help.aikido.dev/doc/configuration-via-env-vars/docrSItUkeR9)
|
119
|
+
|
120
|
+
## License
|
121
|
+
|
122
|
+
This program is offered under a commercial and under the AGPL license. You can be released from the requirements of the AGPL license by purchasing a commercial license. Buying such a license is mandatory as soon as you develop commercial activities involving the Zen software without disclosing the source code of your own applications.
|
123
|
+
|
124
|
+
For more information, please contact Aikido Security at this address: support@aikido.dev or create an account at https://app.aikido.dev.
|
125
|
+
|
126
|
+
## Benchmarks
|
127
|
+
|
128
|
+
We run a benchmark on every commit to ensure Zen has a minimal impact on your application's performance.
|
129
|
+
|
130
|
+
See [benchmarks](benchmarks)
|
131
|
+
|
132
|
+
## Bug bounty program
|
133
|
+
|
134
|
+
Our bug bounty program is public and can be found by all registered Intigriti users at: https://app.intigriti.com/researcher/programs/aikido/aikidozenbeta
|
135
|
+
|
136
|
+
## Contributing
|
137
|
+
|
138
|
+
See [CONTRIBUTING.md](.github/CONTRIBUTING.md) for more information.
|
139
|
+
|
140
|
+
## Code of Conduct
|
141
|
+
|
142
|
+
See [CODE_OF_CONDUCT.md](.github/CODE_OF_CONDUCT.md) for more information.
|
143
|
+
|
144
|
+
## Security
|
145
|
+
|
146
|
+
See [SECURITY.md](.github/SECURITY.md) for more information.
|
data/Rakefile
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "minitest/test_task"
|
5
|
+
require "standard/rake"
|
6
|
+
require "rake/clean"
|
7
|
+
|
8
|
+
load "tasklib/libzen.rake"
|
9
|
+
load "tasklib/bench.rake"
|
10
|
+
|
11
|
+
desc "Run all benchmarks"
|
12
|
+
task bench: "bench:default"
|
13
|
+
|
14
|
+
namespace :build do
|
15
|
+
desc "Ensure Gemfile.lock is up-to-date"
|
16
|
+
task "update_gem_lockfile" do
|
17
|
+
sh "bundle check >/dev/null || bundle"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
task build: ["build:update_gem_lockfile", "libzen:download:all"]
|
21
|
+
|
22
|
+
# Build all the native gems as well
|
23
|
+
Rake::Task["build"].enhance(["libzen:gems"])
|
24
|
+
|
25
|
+
# rake release wants to tag the commit and push the tag, but we run the release
|
26
|
+
# workflow after creating the tag, and so we don't need another one.
|
27
|
+
Rake::Task["release:source_control_push"].clear
|
28
|
+
task "release:source_control_push" do
|
29
|
+
# do nothing
|
30
|
+
end
|
31
|
+
|
32
|
+
# Push all the native gems before the libzen-less one.
|
33
|
+
task "release:rubygem_push" => "libzen:release"
|
34
|
+
|
35
|
+
Pathname.glob("sample_apps/*").select(&:directory?).each do |dir|
|
36
|
+
namespace :build do
|
37
|
+
desc "Ensure Gemfile.lock is up-to-date in the #{dir.basename} sample app"
|
38
|
+
task "update_#{dir.basename}_lockfile" do
|
39
|
+
Dir.chdir(dir) { sh "bundle check >/dev/null || bundle" }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
task build: "build:update_#{dir.basename}_lockfile"
|
44
|
+
end
|
45
|
+
|
46
|
+
Minitest::TestTask.create do |test_task|
|
47
|
+
test_task.test_globs = FileList["test/**/{test_*,*_test}.rb"]
|
48
|
+
.exclude("test/e2e/**/*.rb")
|
49
|
+
end
|
50
|
+
task test: "libzen:download:current"
|
51
|
+
|
52
|
+
Pathname.glob("test/e2e/*").select(&:directory?).each do |dir|
|
53
|
+
namespace :e2e do
|
54
|
+
desc "Run e2e tests for the #{dir.basename} sample app"
|
55
|
+
task dir.basename do
|
56
|
+
Dir.chdir(dir) do
|
57
|
+
sh "rake ci:setup"
|
58
|
+
sh "rake test"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
desc "Run all e2e tests"
|
64
|
+
task e2e: "e2e:#{dir.basename}"
|
65
|
+
end
|
66
|
+
|
67
|
+
task default: %i[test standard]
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# Benchmarking Zen for Ruby
|
2
|
+
|
3
|
+
|
4
|
+
We use [WRK](https://github.com/wg/wrk) & [Grafana K6](https://k6.io) for these.
|
5
|
+
|
6
|
+
WRK benchmarks are only requesting a URL (`/benchmark`). In case you want to add more
|
7
|
+
of those test, you have to code them in the file `tasklib/bench.rake`.
|
8
|
+
|
9
|
+
K6 tests are defined in `benchmarks` folder. They are a javascript file, with calls
|
10
|
+
to different endpoints.
|
11
|
+
|
12
|
+
In order to run a benchmarks against a single application, run the following
|
13
|
+
from the root of the project:
|
14
|
+
|
15
|
+
```
|
16
|
+
$ BUNDLE_GEMFILE=./sample_apps/{app}/Gemfile bundle exec rake bench:{app}:(k6|wrk)_run
|
17
|
+
```
|
18
|
+
|
19
|
+
For example, for the WRK of `rails7.1_benchmark` application:
|
20
|
+
|
21
|
+
```
|
22
|
+
$ BUNDLE_GEMFILE=./sample_apps/rails7.1_benchmark/Gemfile bundle exec rake bench:rails7.1_benchmark:wrk_run
|
23
|
+
```
|
@@ -0,0 +1,70 @@
|
|
1
|
+
import http from 'k6/http';
|
2
|
+
import {Trend} from 'k6/metrics';
|
3
|
+
|
4
|
+
const HTTP = {
|
5
|
+
withZen: {
|
6
|
+
get: (path, ...args) => http.get("http://localhost:3001" + path, ...args),
|
7
|
+
post: (path, ...args) => http.post("http://localhost:3001" + path, ...args)
|
8
|
+
},
|
9
|
+
withoutZen: {
|
10
|
+
get: (path, ...args) => http.get("http://localhost:3002" + path, ...args),
|
11
|
+
post: (path, ...args) => http.post("http://localhost:3002" + path, ...args)
|
12
|
+
}
|
13
|
+
}
|
14
|
+
|
15
|
+
function test(name, fn) {
|
16
|
+
const withZen = fn(HTTP.withZen);
|
17
|
+
const withoutZen = fn(HTTP.withoutZen);
|
18
|
+
const timeWithZen = withZen.timings.duration;
|
19
|
+
const timeWithoutZen = withoutZen.timings.duration;
|
20
|
+
|
21
|
+
tests[name].delta.add(timeWithZen - timeWithoutZen);
|
22
|
+
tests[name].overhead.add(100 * (timeWithZen - timeWithoutZen) / timeWithoutZen)
|
23
|
+
|
24
|
+
tests[name].with_zen.add(timeWithZen);
|
25
|
+
tests[name].without_zen.add(timeWithoutZen);
|
26
|
+
}
|
27
|
+
|
28
|
+
function buildTestTrends(prefix) {
|
29
|
+
return {
|
30
|
+
delta: new Trend(`${prefix}_delta`),
|
31
|
+
with_zen: new Trend(`${prefix}_with_zen`),
|
32
|
+
without_zen: new Trend(`${prefix}_without_zen`),
|
33
|
+
overhead: new Trend(`${prefix}_overhead`)
|
34
|
+
};
|
35
|
+
}
|
36
|
+
|
37
|
+
const tests = {
|
38
|
+
test_post_page_with_json_body: buildTestTrends("test_post_page_with_json_body"),
|
39
|
+
test_get_page_without_attack: buildTestTrends("test_get_page_without_attack"),
|
40
|
+
test_get_page_with_sql_injection: buildTestTrends("test_get_page_with_sql_injection")
|
41
|
+
}
|
42
|
+
export const options = {
|
43
|
+
vus: 1, // Number of virtual users
|
44
|
+
iterations: 200,
|
45
|
+
thresholds: {
|
46
|
+
http_req_failed: ['rate==0'], // we are marking the attacks as expected, so we should have no errors
|
47
|
+
test_post_page_with_json_body_delta: ["med<10"],
|
48
|
+
test_get_page_without_attack_delta: ["med<10"],
|
49
|
+
test_get_page_with_sql_injection_delta: ["med<10"],
|
50
|
+
}
|
51
|
+
};
|
52
|
+
|
53
|
+
const expectAttack = http.expectedStatuses(200, 500);
|
54
|
+
|
55
|
+
export default function () {
|
56
|
+
test("test_post_page_with_json_body",
|
57
|
+
(http) => http.post("/cats", JSON.stringify({cat: {name: "Féline Dion"}}), {
|
58
|
+
headers: {
|
59
|
+
"Content-Type": "application/json",
|
60
|
+
"Accept": "application/json"
|
61
|
+
}
|
62
|
+
})
|
63
|
+
)
|
64
|
+
|
65
|
+
test("test_get_page_without_attack", (http) => http.get("/cats"))
|
66
|
+
|
67
|
+
test("test_get_page_with_sql_injection", (http) =>
|
68
|
+
http.get("/cats/1'%20OR%20''='", { responseCallback: expectAttack })
|
69
|
+
)
|
70
|
+
}
|