Skip to content

Commit e886059

Browse files
authored
Merge branch 'main' into version-119
2 parents f2d2032 + d6222b1 commit e886059

File tree

87 files changed

+1262
-269
lines changed

Some content is hidden

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

87 files changed

+1262
-269
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,4 +499,4 @@ jobs:
499499
name: test-results-aikido-${{ env.AIKIDO_VERSION }}-${{ matrix.os }}-php-${{ matrix.php_version }}
500500
if-no-files-found: ignore
501501
path: |
502-
${{ github.workspace }}/tests/cli/**/*.diff
502+
${{ github.workspace }}/tests/cli/**/*.diff

.vscode/c_cpp_properties.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Linux",
5+
"includePath": [
6+
"${workspaceFolder}/**",
7+
"/usr/include/php",
8+
"/usr/include/php/main",
9+
"/usr/include/php/Zend",
10+
"/usr/include/php/TSRM",
11+
"/usr/include/php/ext"
12+
],
13+
"defines": [],
14+
"compilerPath": "/usr/bin/gcc",
15+
"cStandard": "c11",
16+
"cppStandard": "c++17",
17+
"intelliSenseMode": "linux-gcc-x64"
18+
}
19+
],
20+
"version": 4
21+
}

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,30 @@ Prerequisites:
3636

3737
#### For Red Hat-based Systems (RHEL, CentOS, Fedora)
3838

39+
##### x86_64
3940
```
4041
rpm -Uvh --oldpackage https://github.com/AikidoSec/firewall-php/releases/download/v1.0.119/aikido-php-firewall.x86_64.rpm
4142
```
4243

44+
##### arm64 / aarch64
45+
```
46+
rpm -Uvh --oldpackage https://github.com/AikidoSec/firewall-php/releases/download/v1.0.119/aikido-php-firewall.aarch64.rpm
47+
```
48+
4349
#### For Debian-based Systems (Debian, Ubuntu)
4450

51+
##### x86_64
4552
```
4653
curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.0.119/aikido-php-firewall.x86_64.deb
4754
dpkg -i -E ./aikido-php-firewall.x86_64.deb
4855
```
4956

57+
##### arm64 / aarch64
58+
```
59+
curl -L -O https://github.com/AikidoSec/firewall-php/releases/download/v1.0.118/aikido-php-firewall.aarch64.deb
60+
dpkg -i -E ./aikido-php-firewall.aarch64.deb
61+
```
62+
5063
We support Debian >= 11 and Ubuntu >= 20.04.
5164
You can run on Debian 10, by doing this setup before install: [Debian10 setup](./docs/debian10.md)
5265

docs/should_block_request.md

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,6 @@ class AikidoMiddleware implements MiddlewareInterface
5555
if ($decision->trigger == "user") {
5656
$message = "Your user is blocked!";
5757
}
58-
else if ($decision->trigger == "ip") {
59-
$message = "Your IP ({$decision->ip}) is blocked due to: {$decision->description}!";
60-
}
61-
else if ($decision->trigger == "user-agent") {
62-
$message = "Your user agent ({$decision->user_agent}) is blocked due to: {$decision->description}!";
63-
}
6458

6559
return new Response([
6660
'message' => $message,
@@ -118,14 +112,14 @@ class ZenBlockDecision
118112
return $next($request);
119113
}
120114

121-
// Get the authenticated user's ID from Laravel's Auth system
122-
$userId = Auth::id();
115+
// Get the authenticated user's ID from Laravel's Auth system
116+
$userId = Auth::id();
123117

124-
// If a user is authenticated, set the user in Aikido's firewall context
125-
if ($userId) {
126-
// If username is available, you can set it as the second parameter in the \aikido\set_user function call
127-
\aikido\set_user($userId);
128-
}
118+
// If a user is authenticated, set the user in Aikido's firewall context
119+
if ($userId) {
120+
// If username is available, you can set it as the second parameter in the \aikido\set_user function call
121+
\aikido\set_user($userId);
122+
}
129123

130124
// Check blocking decision from Aikido
131125
$decision = \aikido\should_block_request();
@@ -135,9 +129,6 @@ class ZenBlockDecision
135129
if ($decision->trigger == "user") {
136130
return response('Your user is blocked!', 403);
137131
}
138-
else if ($decision->trigger == "ip") {
139-
return response("Your IP ({$decision->ip}) is blocked due to: {$decision->description}!", 403);
140-
}
141132
}
142133
else if ($decision->type == "ratelimited") {
143134
if ($decision->trigger == "user") {

lib/API.h

Lines changed: 1 addition & 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_GET_AUTO_BLOCKING_STATUS,
910
EVENT_GET_BLOCKING_STATUS,
1011
EVENT_PRE_OUTGOING_REQUEST,
1112
EVENT_POST_OUTGOING_REQUEST,

lib/agent/aikido_types/events.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,23 @@ type MonitoredSinkStats struct {
5252
CompressedTimings []CompressedTiming `json:"compressedTimings"`
5353
}
5454

55+
type MonitoredListsBreakdown struct {
56+
Breakdown map[string]int `json:"breakdown"`
57+
}
58+
5559
type Requests struct {
5660
Total int `json:"total"`
5761
Aborted int `json:"aborted"`
5862
AttacksDetected AttacksDetected `json:"attacksDetected"`
5963
}
6064

6165
type Stats struct {
62-
Sinks map[string]MonitoredSinkStats `json:"sinks"`
63-
StartedAt int64 `json:"startedAt"`
64-
EndedAt int64 `json:"endedAt"`
65-
Requests Requests `json:"requests"`
66+
Sinks map[string]MonitoredSinkStats `json:"sinks"`
67+
StartedAt int64 `json:"startedAt"`
68+
EndedAt int64 `json:"endedAt"`
69+
Requests Requests `json:"requests"`
70+
UserAgents MonitoredListsBreakdown `json:"userAgents"`
71+
IpAddresses MonitoredListsBreakdown `json:"ipAddresses"`
6672
}
6773

6874
type AgentInfo struct {

lib/agent/aikido_types/init_data.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ type CloudConfigData struct {
6060
Block *bool `json:"block,omitempty"`
6161
BlockedIpsList map[string]IpBlocklist
6262
BlockedUserAgents string
63+
MonitoredIpsList map[string]IpBlocklist
64+
MonitoredUserAgents string
65+
UserAgentDetails map[string]string
6366
}
6467

6568
type BlockedIpsData struct {
@@ -68,11 +71,19 @@ type BlockedIpsData struct {
6871
Ips []string `json:"ips"`
6972
}
7073

74+
type UserAgentDetails struct {
75+
Key string `json:"key"`
76+
Pattern string `json:"pattern"`
77+
}
78+
7179
type ListsConfigData struct {
72-
Success bool `json:"success"`
73-
ServiceId int `json:"serviceId"`
74-
BlockedIpAddresses []BlockedIpsData `json:"blockedIPAddresses"`
75-
BlockedUserAgents string `json:"blockedUserAgents"`
80+
Success bool `json:"success"`
81+
ServiceId int `json:"serviceId"`
82+
BlockedIpAddresses []BlockedIpsData `json:"blockedIPAddresses"`
83+
BlockedUserAgents string `json:"blockedUserAgents"`
84+
MonitoredIpAddresses []BlockedIpsData `json:"monitoredIpAddresses"`
85+
MonitoredUserAgents string `json:"monitoredUserAgents"`
86+
UserAgentDetails []UserAgentDetails `json:"userAgentDetails"`
7687
}
7788

7889
type CloudConfigUpdatedAt struct {

lib/agent/aikido_types/queue.go

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,46 @@
11
package aikido_types
22

3-
type Queue struct {
4-
items []int
3+
type Queue[T any] struct {
4+
items []T
5+
maxSize int
56
}
67

7-
func (q *Queue) Push(item int) {
8+
func NewQueue[T any](maxSize int) Queue[T] {
9+
// Passing 0 as maxSize means no limit on the queue size.
10+
return Queue[T]{
11+
items: []T{},
12+
maxSize: maxSize,
13+
}
14+
}
15+
16+
func (q *Queue[T]) Clear() {
17+
q.items = []T{}
18+
}
19+
20+
func (q *Queue[T]) PushAndGetRemovedItemIfMaxExceeded(item T) *T {
21+
var oldest *T
22+
if q.maxSize > 0 && q.Length() >= q.maxSize {
23+
temp := q.Pop()
24+
oldest = &temp
25+
}
826
q.items = append(q.items, item)
27+
return oldest
928
}
1029

11-
func (q *Queue) Pop() int {
30+
func (q *Queue[T]) Pop() T {
31+
var zero T
1232
if len(q.items) == 0 {
13-
return -1
33+
return zero
1434
}
1535
item := q.items[0]
1636
q.items = q.items[1:]
1737
return item
1838
}
1939

20-
func (q *Queue) IsEmpty() bool {
40+
func (q *Queue[T]) IsEmpty() bool {
2141
return q.Length() == 0
2242
}
2343

24-
func (q *Queue) IncrementLast() {
25-
if q.IsEmpty() {
26-
return
27-
}
28-
q.items[q.Length()-1] += 1
29-
}
30-
31-
func (q *Queue) Length() int {
44+
func (q *Queue[T]) Length() int {
3245
return len(q.items)
3346
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package aikido_types
2+
3+
import (
4+
"testing"
5+
"github.com/stretchr/testify/assert"
6+
)
7+
8+
func TestNewQueue(t *testing.T) {
9+
t.Run("it works", func(t *testing.T) {
10+
maxSize := 2
11+
q := NewQueue[string](maxSize)
12+
assert.Nil(t, q.PushAndGetRemovedItemIfMaxExceeded("a"))
13+
assert.Nil(t, q.PushAndGetRemovedItemIfMaxExceeded("b"))
14+
expected := "a"
15+
removedItem := q.PushAndGetRemovedItemIfMaxExceeded("c")
16+
assert.NotNil(t, removedItem)
17+
assert.Equal(t, expected, *removedItem)
18+
assert.Equal(t, maxSize, q.Length())
19+
assert.False(t, q.IsEmpty())
20+
})
21+
22+
t.Run("it can clear the queue", func(t *testing.T) {
23+
q := NewQueue[string](2)
24+
q.PushAndGetRemovedItemIfMaxExceeded("a")
25+
q.Clear()
26+
assert.Equal(t, 0, q.Length())
27+
assert.True(t, q.IsEmpty())
28+
})
29+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package aikido_types
2+
3+
type RateLimitingQueue struct {
4+
items []int
5+
}
6+
7+
func (q *RateLimitingQueue) Push(item int) {
8+
q.items = append(q.items, item)
9+
}
10+
11+
func (q *RateLimitingQueue) Pop() int {
12+
if len(q.items) == 0 {
13+
return -1
14+
}
15+
item := q.items[0]
16+
q.items = q.items[1:]
17+
return item
18+
}
19+
20+
func (q *RateLimitingQueue) IsEmpty() bool {
21+
return q.Length() == 0
22+
}
23+
24+
func (q *RateLimitingQueue) IncrementLast() {
25+
if q.IsEmpty() {
26+
return
27+
}
28+
q.items[q.Length()-1]++
29+
}
30+
31+
func (q *RateLimitingQueue) Length() int {
32+
return len(q.items)
33+
}

0 commit comments

Comments
 (0)