Skip to content

Commit a44561d

Browse files
authored
Set rate limiting group (#250)
1 parent 7add94c commit a44561d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+680
-47
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,25 +38,25 @@ Prerequisites:
3838

3939
##### x86_64
4040
```
41-
rpm -Uvh --oldpackage https://github.com/AikidoSec/firewall-php/releases/download/v1.2.0/aikido-php-firewall.x86_64.rpm
41+
rpm -Uvh --oldpackage https://github.com/AikidoSec/firewall-php/releases/download/v1.3.0/aikido-php-firewall.x86_64.rpm
4242
```
4343

4444
##### arm64 / aarch64
4545
```
46-
rpm -Uvh --oldpackage https://github.com/AikidoSec/firewall-php/releases/download/v1.2.0/aikido-php-firewall.aarch64.rpm
46+
rpm -Uvh --oldpackage https://github.com/AikidoSec/firewall-php/releases/download/v1.3.0/aikido-php-firewall.aarch64.rpm
4747
```
4848

4949
#### For Debian-based Systems (Debian, Ubuntu)
5050

5151
##### x86_64
5252
```
53-
curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.2.0/aikido-php-firewall.x86_64.deb
53+
curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.3.0/aikido-php-firewall.x86_64.deb
5454
dpkg -i -E ./aikido-php-firewall.x86_64.deb
5555
```
5656

5757
##### arm64 / aarch64
5858
```
59-
curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.2.0/aikido-php-firewall.aarch64.deb
59+
curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.3.0/aikido-php-firewall.aarch64.deb
6060
dpkg -i -E ./aikido-php-firewall.aarch64.deb
6161
```
6262

docs/aws-elastic-beanstalk.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
```
55
commands:
66
aikido-php-firewall:
7-
command: "rpm -Uvh --oldpackage https://github.com/AikidoSec/firewall-php/releases/download/v1.2.0/aikido-php-firewall.x86_64.rpm"
7+
command: "rpm -Uvh --oldpackage https://github.com/AikidoSec/firewall-php/releases/download/v1.3.0/aikido-php-firewall.x86_64.rpm"
88
ignoreErrors: true
99
1010
files:

docs/fly-io.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Create a script to install the Aikido PHP Firewall during deployment:
3232
#!/usr/bin/env bash
3333
cd /tmp
3434

35-
curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.2.0/aikido-php-firewall.x86_64.deb
35+
curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.3.0/aikido-php-firewall.x86_64.deb
3636
dpkg -i -E ./aikido-php-firewall.x86_64.deb
3737
```
3838

docs/laravel-forge.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ cd /tmp
2121
2222
# Install commands from the "Manual install" section below, based on your OS
2323
24-
curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.2.0/aikido-php-firewall.x86_64.deb
24+
curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.3.0/aikido-php-firewall.x86_64.deb
2525
dpkg -i -E ./aikido-php-firewall.x86_64.deb
2626
2727
# Restarting the php services in order to load the Aikido PHP Firewall

docs/should_block_request.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ class AikidoMiddleware implements MiddlewareInterface
7272
else if ($decision->trigger == "ip") {
7373
$message = "Your IP ({$decision->ip}) exceeded the rate limit for this endpoint!";
7474
}
75+
else if ($decision->trigger == "group") {
76+
$message = "Your group exceeded the rate limit for this endpoint!";
77+
}
7578
return new Response([
7679
'message' => $message,
7780
], 429);
@@ -147,6 +150,9 @@ class AikidoMiddleware
147150
else if ($decision->trigger == "ip") {
148151
return response("Your IP ({$decision->ip}) exceeded the rate limit for this endpoint!", 429);
149152
}
153+
else if ($decision->trigger == "group") {
154+
return response("Your group exceeded the rate limit for this endpoint!", 429);
155+
}
150156
}
151157
}
152158

docs/user.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,12 @@ Using `\aikido\set_user` has the following benefits:
1717
- Whenever attacks are detected, the user will be included in the report to Aikido.
1818
- The dashboard will show all your users, where you can also block them.
1919
- Passing the user's name is optional, but it can help you identify the user in the dashboard. You will be required to list Aikido Security as a subprocessor if you choose to share personal identifiable information (PII).
20+
21+
# Rate limiting groups
22+
23+
To limit the number of requests for a group of users, you can use the `set_rate_limit_group` function. For example, this is useful if you want to limit the number of requests per team or company.
24+
Please note that if a rate limit group is set, the configured rate limits are only applied to the group and not to individual users or IP addresses.
25+
26+
```php
27+
\aikido\set_rate_limit_group("123");
28+
```

lib/API.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ enum EVENT_ID {
66
EVENT_PRE_REQUEST,
77
EVENT_POST_REQUEST,
88
EVENT_SET_USER,
9+
EVENT_SET_RATE_LIMIT_GROUP,
910
EVENT_GET_AUTO_BLOCKING_STATUS,
1011
EVENT_GET_BLOCKING_STATUS,
1112
EVENT_PRE_OUTGOING_REQUEST,
@@ -35,6 +36,8 @@ enum CALLBACK_ID {
3536

3637
CONTEXT_USER_ID,
3738
CONTEXT_USER_NAME,
39+
40+
CONTEXT_RATE_LIMIT_GROUP,
3841

3942
FUNCTION_NAME,
4043

lib/agent/aikido_types/stats.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ type RateLimitingKey struct {
4747
}
4848

4949
type RateLimitingValue struct {
50-
Method string
51-
Route string
52-
Config RateLimitingConfig
53-
UserCounts map[string]*RateLimitingCounts
54-
IpCounts map[string]*RateLimitingCounts
50+
Method string
51+
Route string
52+
Config RateLimitingConfig
53+
UserCounts map[string]*RateLimitingCounts
54+
IpCounts map[string]*RateLimitingCounts
55+
RateLimitGroupCounts map[string]*RateLimitingCounts
5556
}
5657

5758
type RateLimitingWildcardValue struct {

lib/agent/cloud/common.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ func UpdateRateLimitingConfig() {
9191
Config: RateLimitingConfig{
9292
MaxRequests: newEndpointConfig.RateLimiting.MaxRequests,
9393
WindowSizeInMinutes: newEndpointConfig.RateLimiting.WindowSizeInMS / MinRateLimitingIntervalInMs},
94-
UserCounts: make(map[string]*RateLimitingCounts),
95-
IpCounts: make(map[string]*RateLimitingCounts),
94+
UserCounts: make(map[string]*RateLimitingCounts),
95+
IpCounts: make(map[string]*RateLimitingCounts),
96+
RateLimitGroupCounts: make(map[string]*RateLimitingCounts),
9697
}
9798

9899
if isWildcardEndpoint(k.Route) {

lib/agent/globals/constants.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package globals
22

33
const (
4-
Version = "1.2.0"
4+
Version = "1.3.0"
55
ConfigUpdatedAtMethod = "GET"
66
ConfigUpdatedAtAPI = "/config"
77
ConfigAPIMethod = "GET"

0 commit comments

Comments
 (0)