add protection that shares the data with my webside

This commit is contained in:
2025-12-23 15:20:36 +01:00
parent 0b2d635fd8
commit 729e7f5fca
13 changed files with 211 additions and 60 deletions
+20 -1
View File
@@ -1,3 +1,6 @@
from routes.handeling.errorsAndBots import maybe_a_hacker
from my_modules.app.constens import THE_IP_BOT_MANAGER
from my_modules.app.logger import logger
from my_modules.functions import get_ip
from my_modules.app.setup import app
@@ -14,13 +17,29 @@ async def custom_middleware():
path = request.path
method = request.method
db_whitelisted_or_blocked = await current_app.convex.is_ip_address_whitelisted_or_blocked(ip_address=client_ip)
# Skip allowed IPs or non-critical assets
if (
"favicon" in path
db_whitelisted_or_blocked['whiteliste']
or THE_IP_BOT_MANAGER.is_client_ip_always_allowed(client_ip)
or "static" in path
or "favicon" in path
or "storage" in path
):
return
# 2. If IP is already blocked
if db_whitelisted_or_blocked['blocked']:
await logger.error(f"[BLOCKED] {method} | {client_ip} tried {method} {path}")
await current_app.convex.increment_blocked_ip_address_access(ip_address=client_ip, method=method, path=path)
return await render_template("views/basics/blocked_access.htm", remote_addr=client_ip), 403
# 3. If path contains honeypot targets
if await current_app.convex.is_path_blocked(path=path):
await logger.warning(f"[HONEYPOT] {method} | {client_ip} accessed {path}")
return await maybe_a_hacker()
await logger.info(f"{method} | {client_ip} had accessed the Side {path}")
@app.context_processor