fix: tolerate malformed telegram callbacks, constrain channel id

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BCrwHHnGCB5XH968Nxokqw
This commit is contained in:
nikita.hohlov
2026-09-04 07:59:45 -03:00
parent 90d17ec378
commit 44f50e1d66
4 changed files with 24 additions and 4 deletions

View File

@@ -67,21 +67,31 @@ class TelegramWebhookController extends Controller
$this->telegram->touch($chatId);
}
$callbackId = (string) ($callback['id'] ?? '');
[$action, $token] = array_pad(explode(':', (string) ($callback['data'] ?? ''), 2), 2, '');
$delivery = Delivery::where('action_token', $token)->with('event.user')->first();
if ($delivery === null || $delivery->event->isTerminal() || ! in_array($action, ['ack', 'done'], true)) {
$this->telegram->answerCallback((string) $callback['id'], 'Уже неактуально');
$this->answerCallback($callbackId, 'Уже неактуально');
return;
}
if ($action === 'done') {
$this->actions->done($delivery->event);
$this->telegram->answerCallback((string) $callback['id'], 'Закрыто');
$this->answerCallback($callbackId, 'Закрыто');
} else {
$this->actions->ack($delivery->event);
$this->telegram->answerCallback((string) $callback['id'], 'Ок, напомню позже');
$this->answerCallback($callbackId, 'Ок, напомню позже');
}
}
private function answerCallback(string $callbackId, string $text): void
{
if ($callbackId === '') {
// Нет id — отвечать нечему (malformed payload), но не считаем это ошибкой.
return;
}
$this->telegram->answerCallback($callbackId, $text);
}
}