Personal Telegram developer console for GitHub
fix: fail closed webhook and silence unauthorized users
davoodmehraban89 committed
Oct 2, 2026 at 16:36 UTC
85f714ed37488413b9fc09cc02192c3f291c562a
1 file changed
+6
-8
src/index.js
+6
-8
@@ -78,10 +78,8 @@ async function handleCommand(env, message) {
78
const chatId = message.chat?.id;
79
const command = (message.text || "").trim().split(/\s+/)[0].split("@")[0].toLowerCase();
80
81
- if (!isOwner(env, message.from)) {
82
- if (chatId) await sendMessage(env, chatId, "⛔️ دسترسی مجاز نیست.");
83
- return;
84
- }
81
+ // Personal bot: fail silently for every Telegram user except the owner.
82
+ if (!isOwner(env, message.from)) return;
83
84
if (command === "/start") {
85
await sendMessage(env, chatId, startMessage());
@@ -119,10 +117,10 @@ async function handleCommand(env, message) {
117
118
async function handleTelegramWebhook(request, env) {
119
const expected = env.TELEGRAM_WEBHOOK_SECRET;
122
- if (expected) {
123
- const actual = request.headers.get("X-Telegram-Bot-Api-Secret-Token");
124
- if (actual !== expected) return text("Forbidden", 403);
125
- }
120
+ if (!expected) return text("Webhook secret not configured", 503);
121
+
122
+ const actual = request.headers.get("X-Telegram-Bot-Api-Secret-Token");
123
+ if (actual !== expected) return text("Forbidden", 403);
124
125
const update = await request.json();
126
if (update.message?.text) {