Skip to content

Commit

Permalink
Merge #301: A bit more secure I'd say
Browse files Browse the repository at this point in the history
Check `X-Telegram-Bot-Api-Secret-Token` in Webhook
  • Loading branch information
HeySreelal authored Oct 23, 2024
2 parents df8b610 + 699e5eb commit 62f81b8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.26.6

- Check `Webhook.secretToken` with the header `X-Telegram-Bot-Api-Secret-Token` before processing the incoming webhook update.

# 1.26.5

- Fixed in `ReactionTypeCustomEmoji.customEmojiId`
Expand Down
9 changes: 9 additions & 0 deletions lib/src/televerse/fetch/webhook.dart
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ class Webhook extends Fetcher {

/// Handles incoming HTTP requests.
Future<void> _handleRequest(io.HttpRequest request) async {
const secretTokenHeader = "X-Telegram-Bot-Api-Secret-Token";
final Map<String, dynamic> error = {
'ok': false,
'error_code': 404,
Expand All @@ -276,6 +277,14 @@ class Webhook extends Fetcher {
return;
}

if (secretToken != null &&
request.headers.value(secretTokenHeader) != secretToken) {
error["description"] = "Unauthorized request";
error["error_code"] = 401;
_sendResponse(request, error["error_code"], error);
return;
}

final body = await request
.cast<List<int>>()
.transform(
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: televerse
description: Televerse lets you create your own efficient Telegram bots with ease in Dart. Supports latest Telegram Bot API - 7.10!
version: 1.26.5
version: 1.26.6
homepage: https://televerse.xooniverse.com
repository: https://github.com/xooniverse/televerse
topics:
Expand Down

0 comments on commit 62f81b8

Please sign in to comment.