Skip to content

Commit c823731

Browse files
committed
request_handler update to use CHECK_FIREWALL_LISTS
1 parent d40e833 commit c823731

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

aikido_zen/sources/functions/request_handler.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from aikido_zen.helpers.logging import logger
77
from aikido_zen.thread.thread_cache import get_cache
88
from .ip_allowed_to_access_route import ip_allowed_to_access_route
9-
from ...helpers.is_ip_allowed_by_allowlist import is_ip_allowed_by_allowlist
9+
from ...background_process import get_comms
1010

1111

1212
def request_handler(stage, status_code=0):
@@ -49,21 +49,32 @@ def pre_response():
4949
message += f" (Your IP: {context.remote_address})"
5050
return message, 403
5151

52-
# Global IP Allowlist (e.g. for geofencing)
53-
if not is_ip_allowed_by_allowlist(cache.config, context.remote_address):
52+
# Do a check on firewall lists, this happens in background because of the heavy data.
53+
comms = get_comms()
54+
check_fw_lists_res = comms.send_data_to_bg_process(
55+
action="CHECK_FIREWALL_LISTS",
56+
obj={
57+
"ip": context.remote_address,
58+
"user-agent": context.get_user_agent(),
59+
},
60+
receive=True,
61+
)
62+
if not check_fw_lists_res["success"] or not check_fw_lists_res["blocked"]:
63+
return
64+
65+
if check_fw_lists_res["type"] == "allowlist":
5466
message = "Your IP address is not allowed."
5567
message += " (Your IP: " + context.remote_address + ")"
5668
return message, 403
5769

58-
# Global IP Blocklist (e.g. blocking known threat actors)
59-
reason = cache.config.is_blocked_ip(context.remote_address)
60-
if reason:
61-
message = "Your IP address is blocked due to " + reason
70+
if check_fw_lists_res["data"]["type"] == "blocklist":
71+
message = "Your IP address is blocked due to "
72+
message += check_fw_lists_res["data"]["reason"]
6273
message += " (Your IP: " + context.remote_address + ")"
6374
return message, 403
6475

6576
# User agent blocking (e.g. blocking AI scrapers)
66-
if cache.config.is_user_agent_blocked(context.get_user_agent()):
77+
if check_fw_lists_res["data"]["type"] == "bot-blocking":
6778
msg = "You are not allowed to access this resource because you have been identified as a bot."
6879
return msg, 403
6980

0 commit comments

Comments
 (0)