Skip to content

Verify the webhook secret token of operator bots - #101

Merged
remdex merged 1 commit into
LiveHelperChat:masterfrom
mysubcult:fix/webhook-secret-token
Oct 26, 2026
Merged

remdex merged 1 commit into
LiveHelperChat:masterfrom
mysubcult:fix/webhook-secret-token

Conversation

@mysubcult

Copy link
Copy Markdown
Contributor

Problem

telegram/callback/<bot id> accepts any POST request. Anyone who knows (or guesses) the URL can post a fake update with an operator's Telegram user id and act as that operator: write to visitors, press inline buttons, run bot commands.

Telegram supports this case: setWebhook takes a secret_token, and every webhook request then carries it in the X-Telegram-Bot-Api-Secret-Token header.

Change

  • erLhcoreClassModelTelegramBot::$webhook_secret is derived from the bot id, the bot token and the site secrethash (HMAC-SHA256). No new column, no settings.
  • Set webhook sends secret_token and stores webhook_set = 2.
  • callback.php returns 403 when webhook_set = 2 and the header is missing or wrong, and 404 for an unknown bot id (it used to fatal on null).
  • Backward compatible: bots whose webhook was set before (webhook_set = 1) keep working without the header. The bot list shows them as "Yes (no secret token, set again)", so admins know to click Set webhook once.
  • Changing the bot token already resets webhook_set to 0, and the secret changes with the token.

Testing

  • Set webhook again for a client bot: getWebhookInfo stays OK, messages and button presses in topics keep working.
  • curl -X POST .../telegram/callback/<id> without the header or with a wrong one gets 403.

Note: with modulecompile enabled, the cache has to be cleared after updating (php cron.php -s site_admin -c cron/util/clear_cache).

🤖 Generated with Claude Code

The callback endpoint accepted any POST, so anyone who knows the URL could post fake updates on behalf of
operators. Set webhook now registers a secret_token (derived from the bot token and the site secret hash) and
the callback rejects requests whose X-Telegram-Bot-Api-Secret-Token header does not match.

Webhooks set earlier (webhook_set = 1) keep working without the header until Set webhook is clicked again;
the bot list shows them as "Yes (no secret token, set again)".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@remdex
remdex merged commit 8c8a0f2 into LiveHelperChat:master Oct 26, 2026
mysubcult added a commit to mysubcult/telegram that referenced this pull request Oct 26, 2026
…perChat#98, LiveHelperChat#100, LiveHelperChat#101, LiveHelperChat#104 accepted upstream; fork already had them)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mysubcult
mysubcult deleted the fix/webhook-secret-token branch October 26, 2026 17:45
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