A security review of a China-built telegram bot focuses first on the two assets that control the whole system: the bot token that grants bot api access, and the admin roles that can issue commands, view records, and manage settings. A token leaked into a repository, chat log, or plaintext configuration is a permanent back door; an over-broad admin role lets any trusted member change rules, view payment records, or promote other admins. This article walks the review in sequence: token inventory and storage, secret handling, role separation, callback verification, payment and data access, session handling, logging exposure, and the remediation check before handover. The review applies to support, community, and shop bots alike; a payment bot adds stricter checks on credentials and transaction records.
Token inventory and where the token lives
Start by listing every credential the system uses: the BotFather bot token, hosting or cloud credentials, database credentials, payment provider API keys, webhook secrets, and any third-party service keys. For each, record where it is stored, who can read it, and whether it has appeared anywhere it should not. The bot token is the highest-risk item: it controls the bot’s identity, can send messages, read updates, and reset through the bot’s account.
Tokens should live in a secured secrets store or environment configuration outside the application code, never committed in repository history, embedded in bot messages, or pasted into support notes. Check repository history, not only the current file tree: a token committed months earlier remains recoverable from history even if the current file removed it. Development and staging tokens should be separate from production, and any token used during demos or screen shares should be rotated after the project.
At handover, the production token should be rotated once the buyer takes over the bot account. Any token the vendor retained in its own notes, panel, or deployment should be invalidated and replaced. The ownership and account-transfer questions behind this inventory are covered in the six ownership questions guide.
Token handling should also account for who can request a new token through BotFather. Only the account owner or a designated admin should hold that access; a token reset should invalidate the old token immediately, and the bot should be able to resume on the new token without a redeploy if configuration supports it. A token that cannot be rotated without the original vendor creates a dependency that the security review should flag.
Secret and credential handling
Beyond the token, review how provider secrets are stored. Payment processor keys, wallet or bank connections, and CRM credentials should follow the same rule: secured storage, least-privilege access, no plaintext in code or logs. Secrets should be referenced by configuration reference rather than copied into source files, and rotation procedures should be documented so a compromised credential can be replaced without redeploying the whole bot.
Check default or shared secrets: a demo API key reused across projects, a generic webhook secret that appears in multiple deployments, or database credentials shared between production and test environments. Shared credentials cannot be scoped or revoked per project, and they complicate incident response. Each production service should hold its own credentials under the buyer’s account where possible.
Third-party accounts the bot depends on should be reviewed for account-level access: what the API key can read or change, whether it can issue refunds or export records, and whether it can be restricted to the permissions the bot actually needs. Over-privileged provider keys are a common gap in payment integrations.
Admin roles and permission separation
Admin commands in the bot should be restricted to a defined admin list, not open to anyone who sends the command. Roles should separate by permission: day-to-day moderators warn and remove messages; senior admins edit rules, manage tiers, and approve bans; account owners hold token and settings access. A role that can promote other admins or rotate secrets should be limited to owners.
Verify that non-admins cannot trigger admin actions through crafted messages, callbacks, or deep links. Admin-only callbacks should check the sender’s role before acting, not rely on the button being hidden from regular users. Membership or ownership checks should run server-side in the bot’s backend, because client-side hiding can be bypassed.
Review the current admin list at review time: who holds which role, whether any former moderator or vendor contact still has access, and whether role changes are logged. Admin actions — warnings, bans, rule edits, promotions, refunds — should be recorded with actor, time, and target, so an insider action can be traced. The security review should verify the role separation independently rather than relying on the moderation feature design alone.
Callback and webhook verification
Callbacks from providers and Telegram should be verified before the bot changes any state. Payment callbacks should check signature or secret verification before marking an order paid; webhook deliveries should confirm they come from the expected source, not a forged request. A callback that marks an unpaid order paid without verification is a direct financial exposure.
Idempotency belongs in this check: repeated callbacks should not create duplicate orders, refunds, or notes. The bot should record processed references and reject duplicates. Webhook configuration should use a valid certificate and a reachable endpoint, with acknowledgments returned quickly so updates are not redelivered repeatedly.
Check what data callbacks carry and whether sensitive fields are logged. Payment callbacks should not expose full card details; records should carry references and limited identifiers only. The same verification standard applies to any mini-app or client-side request that triggers a backend action.
Payment and data access checks
For a payment bot, review the payment flow specifically: which merchant account holds funds, who can view transaction records, how refunds are authorized, and whether payment credentials are stored outside the bot codebase. Refund and dispute actions should require a senior role and leave an audit trail. Processor and wallet accounts should be the seller’s own business accounts; a vendor-held merchant account shifts payout and dispute responsibility onto an intermediary.
Data access should follow least privilege. Support agents see the records their tickets require; admins see settings and management; customers see only their own records. Records should not expose other users’ purchase history, contact details, or membership state through guessable references or unfiltered queries. Personal data collected in conversations, forms, or purchases follows the documented retention and deletion rules reviewed alongside the bot’s data schedule.
Cross-border data paths should be checked: where records are stored, which third-party processors touch them, and whether the storage region matches the buyer’s compliance posture. A bot built on the vendor’s shared panel may hold records in an unreviewable location; that limitation should be documented before production rather than discovered in a later review.
Access reviews should be repeated on a schedule, not treated as a one-time pre-launch check. Staff changes, new integrations, and updated provider keys can broaden access over time; a periodic review of admin roles, active credentials, and provider permissions keeps the security posture aligned with the bot’s actual operation.
Session handling for any user-account component
If the bot uses an MTProto or user-account component rather than a bot-account-only bot api integration, review session handling separately: where the session string is stored, how it expires, how re-authorization works, whether unknown devices are revoked, and how account data is protected. User-account sessions can read private messages and contacts, so their storage and access bar is higher than a bot token’s.
Two-factor protection on the connected account should be configured and documented. Sessions held only on the vendor’s side, with no buyer access or revocation path, should be treated as an unresolved risk. The protocol and account-model differences between Bot API and MTProto are explained in the Bot API versus MTProto guide.
Logging and exposure review
Review what the bot writes to logs: messages, identifiers, statuses, errors, and any secrets or sensitive values that should not appear. Logs should not store tokens, keys, full payment details, or personal contact data beyond what the service requires. Error messages should not expose internal paths, database structure, or configuration to users.
Check exposed surfaces: public endpoints, admin panels, database ports, and any debug or test views left enabled in production. Debug modes that reveal internal state or accept loose input should be disabled before launch. Test records and demo data should be removed from production databases.
Logs should also cover security-relevant events: failed admin attempts, permission denials, callback verification failures, and unusual access patterns. Without these records, a compromised token or an over-privileged role can sit unnoticed until an incident occurs. Reviewers should be able to distinguish normal operation from anomalous activity from the log history, and logs themselves should be access-restricted so they do not become a second exposure path.
Remediation and handover verification
Close the review with a remediation list ranked by severity: leaked or weak secrets, over-broad roles, unverified callbacks, over-privileged provider access, exposed logs, and unresolved session handling. Each item should have an owner and a fix deadline before production. High-severity items — exposed tokens, admin access without role checks, unverified payment callbacks — should be closed before go-live, not after.
Verify the fixes on staging: re-check token storage, attempt an admin action as a non-admin, resend a duplicate or forged callback, and confirm records stay protected. The handover package should carry the security review results, the current admin list, credential rotation records, and the secrets-management documentation. The source-code handover expectations behind this review are detailed in the source code handover guide; security posture is part of what transfers to the buyer when the bot leaves the vendor’s control.
Leave a Reply