|
| 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