From e541000347d9d8f5b19fe23ea9d90672a61b636e Mon Sep 17 00:00:00 2001 From: Daniel Dolezal Date: Wed, 7 Jan 2026 00:00:44 +0100 Subject: [PATCH] create Variables for to many 418 errors when they are a hacker or bot to get blocked --- my_modules/app/constens.py | 4 ++++ routes/handeling/errorsAndBots.py | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/my_modules/app/constens.py b/my_modules/app/constens.py index 1175715..86a5c51 100644 --- a/my_modules/app/constens.py +++ b/my_modules/app/constens.py @@ -18,3 +18,7 @@ SECRET_KEY = os.getenv("FLASK_SECRET_KEY", "USE_ENV_das_ist_ein_geheimer_schlüs API_GROUP = os.getenv("API_GROUP", 'NanoShare') THE_IP_BOT_MANAGER = TheIPManager() + +# Blocke IPs (Bots, Hackers) +BLOCKED_IPS_ACCESSING_TIMES = int(os.getenv("BLOCKE_IPS_AFTER_ACCESSING_HOWMANY_TIME", 5)) +BLOCKED_IPS_STORED_TIMEFRAME = int(os.getenv("BLOCKE_IPS_STORE_KEYS_TIMEFRAME", 3600)) diff --git a/routes/handeling/errorsAndBots.py b/routes/handeling/errorsAndBots.py index 8fd2995..3291159 100644 --- a/routes/handeling/errorsAndBots.py +++ b/routes/handeling/errorsAndBots.py @@ -1,3 +1,4 @@ +from my_modules.app.constens import BLOCKED_IPS_ACCESSING_TIMES, BLOCKED_IPS_STORED_TIMEFRAME from my_modules.app.setup import app, LIMITER from my_modules.app.logger import logger @@ -38,7 +39,7 @@ async def not_found(e): @app.errorhandler(418) async def maybe_a_hacker(e=None): try: - enforce_custom_limit(LIMITER, "BotScan", 5, 120) + enforce_custom_limit(LIMITER, "BotScan", BLOCKED_IPS_ACCESSING_TIMES, BLOCKED_IPS_STORED_TIMEFRAME) except LookupError as e: client_ip=get_ip() await current_app.convex.increment_blocked_ip_address_access(