This document describes the security measures implemented in the bot to protect against abuse, floods, and unauthorized usage.
The bot implements a global rate limiter to prevent LLM cost spikes and API abuse.
- Algorithm: Sliding window counter.
- Storage: Request timestamps are stored in
TEMP_DATA/global_request_timestamps.txt. - Limit: Defined by
GLOBAL_RATE_LIMIT_REQUESTS_PER_MINUTEinconfig.py(default: 10 requests/minute).
- Normal Operation: As long as the global request count is below the limit, requests are processed normally. Only messages that trigger an AI reply (e.g. private messages, or group messages where the bot is mentioned) consume the rate limit. Passive monitoring of group messages does not count.
- Limit Exceeded:
- The bot stops processing the "heavy" logic (LLM generation).
- Silent Blocking: Most requests are dropped silently to avoid spamming the chat.
- Warning Message: Once per minute, if the limit is exceeded, the bot replies with a configured warning (e.g., "Dude, slow down...").
- This prevents the bot from sending 100 replies to 100 spammed messages.
The timestamp file is automatically pruned on every request. Timestamps older than 60 seconds are discarded, ensuring the file size remains negligible regardless of uptime.
The bot uses the DoormanWorker to classify each incoming request.
- Classification: The
DoormanWorkeranalyzes the user's prompt + recent context and classifies it into one of:SHALLOW,DEEP,GENIUS,JAILBREAK, orEXPLOITATION. - Trigger: An LLM-based classifier (prompted to detect malicious intent) makes this decision.
- Action:
- If classified as
JAILBREAKorEXPLOITATION:- The bot overrides the user's message with a sanitized, pre-configured alarm text (e.g., "Seems the user attempted to jailbreak...").
- This sanitized message is what the downstream workers (Style, Quality, etc.) see and respond to.
- The
IntegrationWorkerforces "Shallow Mode" (skipping deep DB lookups) for these requests to minimize resource usage.
- The bot then generates a refusal response based on this sanitized input.
- If classified as
JAILBREAK_ALARM_TEXTinconfig.pydefines the replacement text.JAILBREAK_TRUNCATE_LENdefines how much of the original message is kept for context (safely truncated).
Access to the bot is strictly controlled via allowlists.
- User Allowlist: Only Telegram User IDs listed in
ALLOWED_USER_IDScan interact with the bot in private chats. - Group Allowlist: The bot will only process messages in groups listed in
ALLOWED_GROUP_IDS. - Unauthorized Access: Users or groups not on the list receive a "Not authorized" message, and their requests are not sent to the LLM.