getHeaderLine('X-Telegram-Bot-Api-Secret-Token'))) { return $response->withJson(['ok' => false], 403); } $stream = $request->getBody(); if ($stream->getSize() !== null && $stream->getSize() > 65536) { return $response->withJson(['ok' => false], 413); } if ($stream->isSeekable()) { $stream->rewind(); } // Also cap unknown-length/chunked bodies before loading them into memory. $body = $stream->read(65537); if (strlen($body) > 65536) { return $response->withJson(['ok' => false], 413); } $update = json_decode($body, true); if (!is_array($update)) { return $response->withJson(['ok' => false], 400); } try { TicketTelegramNotifier::handleUpdate($update); return $response->withJson(['ok' => true]); } catch (\Throwable $exception) { // Database errors may be retryable, but must never expose bot // credentials or administrator reply content in logs/responses. error_log('Administrator Telegram update processing failed'); return $response->withJson(['ok' => false], 503); } } }