Skip to content

Commit d40e833

Browse files
committed
Create CHECK_FIREWALL_LISTS
1 parent ccaea28 commit d40e833

2 files changed

Lines changed: 44 additions & 0 deletions

File tree

aikido_zen/background_process/commands/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from aikido_zen.helpers.logging import logger
44
from .attack import process_attack
5+
from .check_firewall_lists import process_check_firewall_lists
56
from .read_property import process_read_property
67
from .should_ratelimit import process_should_ratelimit
78
from .ping import process_ping
@@ -16,6 +17,7 @@
1617
"READ_PROPERTY": (process_read_property, True),
1718
"SHOULD_RATELIMIT": (process_should_ratelimit, True),
1819
"PING": (process_ping, True),
20+
"CHECK_FIREWALL_LISTS": (process_check_firewall_lists, True),
1921
}
2022

2123

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
"""Exports process_check_firewall_lists"""
2+
3+
from aikido_zen.api_discovery.update_route_info import update_route_info
4+
from aikido_zen.background_process.cloud_connection_manager import (
5+
CloudConnectionManager,
6+
)
7+
from aikido_zen.background_process.packages import PackagesStore
8+
from aikido_zen.helpers.logging import logger
9+
10+
11+
def process_check_firewall_lists(
12+
connection_manager: CloudConnectionManager, data, conn, queue=None
13+
):
14+
"""
15+
Checks whether an IP is blocked
16+
data: {"ip": string, "user-agent": string}
17+
returns -> {"blocked": boolean, "type": string, "reason": string}
18+
"""
19+
ip = data["ip"]
20+
if ip is not None and isinstance(ip, str):
21+
# Global IP Allowlist (e.g. for geofencing)
22+
if not connection_manager.firewall_lists.is_allowed_ip(ip):
23+
return {"blocked": True, "type": "allowlist"}
24+
25+
# Global IP Blocklist (e.g. blocking known threat actors)
26+
reason = connection_manager.firewall_lists.is_blocked_ip(ip)
27+
if reason:
28+
return {
29+
"blocked": True,
30+
"type": "blocklist",
31+
"reason": reason,
32+
}
33+
34+
user_agent = data["user-agent"]
35+
if user_agent is not None and isinstance(user_agent, str):
36+
# User agent blocking (e.g. blocking AI scrapers)
37+
if connection_manager.firewall_lists.is_user_agent_blocked(user_agent):
38+
reason = "You"
39+
return {
40+
"blocked": True,
41+
"type": "bot-blocking",
42+
}

0 commit comments

Comments
 (0)