Skip to content

Commit b248a8a

Browse files
committed
bot: apply global rate limit before AD check; admins bypass
1 parent 12ac5ce commit b248a8a

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

bot/telegram_jwt_bot.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,11 @@ async def reply_invalid_access() -> None:
446446
await update.message.reply_text("Too many requests for this username. Try again later.")
447447
return
448448

449+
# Global rate limit (across all chat IDs) - checked before AD to protect LDAP from spam
450+
if not is_admin and not _global_rate_limit_ok():
451+
await update.message.reply_text("Global rate limit exceeded. Try again later.")
452+
return
453+
449454
try:
450455
is_enabled, in_group = await asyncio.to_thread(_is_user_enabled_and_in_group, username)
451456
except Exception as exc:
@@ -457,11 +462,6 @@ async def reply_invalid_access() -> None:
457462
await reply_invalid_access()
458463
return
459464

460-
# Global rate limit (across all chat IDs)
461-
if not _global_rate_limit_ok():
462-
await update.message.reply_text("Global rate limit exceeded. Try again later.")
463-
return
464-
465465
INVALID_IDENTITY_ATTEMPTS.pop(chat_id, None)
466466
_save_state()
467467

0 commit comments

Comments
 (0)