Roles, Security & Operations
Telegram Uploader Bot (Cloudflare Workers) enforces a five-rank RBAC model backed by D1 SQL quota triggers, Worker-secret owner verification, sliding-window isolate rate limiting, and atomic JSON configuration restore.
1. Five-Level Role & Quota Matrix
Section titled “1. Five-Level Role & Quota Matrix”| Rank | Role | Daily / Per-Link Download Quota | Active Bundle Caps & Privileges |
|---|---|---|---|
| Rank 4 | Owner | Unlimited (exempt from user_downloads) |
Full system control (/maintenance, /setfilelimit, /setautodel, /setbundlettl, /setlogchannel, /factoryreset confirm, /restore), appoints/revokes Super Admins, overrides bundle locks, advisory warnings at 20 passcode / 20 rotating bundles. Cannot be banned or demoted. |
| Rank 3 | Super Admin | 150 daily / 20 per-link | Up to 15 passcode & 10 rotating bundles; manages /settings, /setdailylimit, /setpubchannel, /botprofile, regular Admins (up to MAX_ADMINS = 10), user bans (/ban 1–3650 days, /unban), and VIPs (/addvip, /vips, /delvip, /clearvips). |
| Rank 2 | Admin | 150 daily / 20 per-link | Up to 5 passcode & 3 rotating bundles; runs /upload, /batch, /edit, /review, /setname, /search (Arabic/Persian normalized), /stats (5-min cache), /top, /postbundle, /rotatelink, /setexpiry, /setpass, and Force-Join /channels. |
| Rank 1 | VIP | 5× standard daily (50) / 3× standard per-link (9) |
Recorded in vips with finite days or lifetime (expires_at = 0); receives multiplied quotas with zero admin privileges. |
| Rank 0 | User | 10 daily / 3 per-link (default, enforced by D1 SQL triggers) | Standard public user via /start and /help; subject to Force-Join gates, D1 quota triggers, and rate limiting. |
2. Secret-Only Owner Authentication (OWNER_ID)
Section titled “2. Secret-Only Owner Authentication (OWNER_ID)”Root ownership is verified exclusively against the mandatory Worker secret:
ctx.isOwner = userId === Number(ctx.env.OWNER_ID)- During deployment,
OWNER_IDis seeded into the D1adminstable as'owner'. - Ownership cannot be claimed or transferred interactively inside Telegram—rotating the Owner requires updating the
OWNER_IDWorker secret and re-seeding the database.
3. Fail-Closed Edge Guards & Rate Limiting
Section titled “3. Fail-Closed Edge Guards & Rate Limiting”- Webhook Secret Authentication: Incoming requests to
POST /<WEBHOOK_PATH>must supply the matchingX-Telegram-Bot-Api-Secret-Tokenheader; mismatched paths/methods return404 Not Foundand invalid tokens return403 Forbidden. - Private Chat Enforcement: All updates strictly require
ctx.chat.type === "private". - Zero-Write Maintenance Mode (
/maintenance): When enabled, non-admin requests receive a maintenance response immediately with 0 D1 writes. - Pre-Routing Command Guard:
commandGuardMiddlewaredrops unauthorized or out-of-rank commands before any handler logic runs. - Sliding-Window Rate Limiter & Ban Pre-Filter:
rateLimitMiddlewareenforces 3 requests per 5 seconds, triggering a 60-second in-memory isolate ban on bursts. Globally banned users (user_quotas) are dropped directly insidefetchbefore invoking grammY middleware.
4. Backup, Factory Reset & Atomic /restore
Section titled “4. Backup, Factory Reset & Atomic /restore”- Factory Reset with Automatic Backup (
/factoryreset confirm): Before wiping runtime tables, the bot exports a JSON configuration backup containingsystem_configandforce_channelsto the configured log channel or Owner DM. - Atomic Configuration Restore (
/restore): Reply directly to a.jsonbackup document (up to 256 KB) with/restoreto atomically overwritesystem_configandforce_channelsin D1.
Next Steps
Section titled “Next Steps”- Commands & Configuration — View the full primary command reference,
Envbindings, andsrc/config.tsdefaults. - Architecture, D1 Schema & Cron — Inspect the 10 D1 tables, 2 SQL quota triggers, and Analytics Engine integration.
- Setup & Deployment — Review required Worker secrets and D1 seeding commands.