Skip to content

Conversation

@johnnymo87
Copy link

Summary

Add support for Telegram's secret_token webhook authentication. When configured,
the server verifies the X-Telegram-Bot-Api-Secret-Token header on incoming
requests, ensuring they originate from Telegram rather than arbitrary sources.

Without this verification, the webhook endpoint accepts any POST request containing
a valid-looking chat_id or whitelisted user_id in the JSON body—values that
are easily guessable integers. The secret token provides cryptographic proof that
requests actually come from Telegram's servers.

Changes

  • .env.example - Add TELEGRAM_WEBHOOK_SECRET with generation instructions
  • src/channels/telegram/webhook.js - Verify header on incoming requests (401 if invalid);
    include secret_token when registering webhook with Telegram API
  • start-telegram-webhook.js - Load secret from env, warn at startup if not configured
  • setup-telegram.sh - Add secret to setup instructions with security note

Backward Compatibility

This change is fully backward compatible. If TELEGRAM_WEBHOOK_SECRET is not set,
the server continues to work as before (with a warning logged at startup).

Usage

Generate a secret and add to .env:

openssl rand -hex 32
TELEGRAM_WEBHOOK_SECRET=your-generated-secret

The secret is automatically passed to Telegram when registering the webhook and
verified on every incoming request.

Reference

Add support for X-Telegram-Bot-Api-Secret-Token header to authenticate
that webhook requests actually come from Telegram, preventing forged
POSTs from attackers who might guess chat_id/user_id values.

Changes:
- Add TELEGRAM_WEBHOOK_SECRET to .env.example with generation instructions
- Verify secret header in webhook handler, return 401 if invalid
- Pass secret_token when registering webhook with Telegram API
- Add security warning in startup logs if secret not configured
- Update setup-telegram.sh with security guidance

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@PabloVitasso
Copy link

is this project alive? or we should create a fork and incorporate this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants