|
6 | 6 | from aikido_zen.helpers.logging import logger |
7 | 7 | from aikido_zen.thread.thread_cache import get_cache |
8 | 8 | 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 |
10 | 10 |
|
11 | 11 |
|
12 | 12 | def request_handler(stage, status_code=0): |
@@ -49,21 +49,32 @@ def pre_response(): |
49 | 49 | message += f" (Your IP: {context.remote_address})" |
50 | 50 | return message, 403 |
51 | 51 |
|
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": |
54 | 66 | message = "Your IP address is not allowed." |
55 | 67 | message += " (Your IP: " + context.remote_address + ")" |
56 | 68 | return message, 403 |
57 | 69 |
|
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"] |
62 | 73 | message += " (Your IP: " + context.remote_address + ")" |
63 | 74 | return message, 403 |
64 | 75 |
|
65 | 76 | # 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": |
67 | 78 | msg = "You are not allowed to access this resource because you have been identified as a bot." |
68 | 79 | return msg, 403 |
69 | 80 |
|
|
0 commit comments