T09 · Insecure Skill Coding Practices
- Location
references/exemplos-agentes.md:142- Finding
Unauthenticated Telegram Webhook Permits Forged Job Submission
- Content
View full analysis
{ const update = req.body as TelegramUpdate const message = update.message if (!message?.text) return reply.send({ ok: true }) // Upsert user_profile const { data: user } = await supabase .from('user_profiles') .upsert({ telegram_id: message.from.id, first_name: message.from.first_name, username: message.from.username, default_chat_id: message.chat.id }, { onConflict: 'telegram_id' }) .select().single() // Criar command const { data: command } = await supabase .from('commands') .insert({ user_id: user.id, payload: { text: message.text, source: 'telegram', chat_id: message.chat.id } }).select().single() // Criar job const { data: job } = await supabase .from('jobs') .insert({ command_id: command.id, chat_id: message.chat.id, status: 'pending' }).select().single() // Enfileirar await supabase.rpc('push_intent_job', { p_job_id: job.id }) // Resposta imediata ao usuário await sendTelegramMessage(message.chat.id, '🔄 Processando sua solicitação...') return reply.send({ ok: true }) }) ``` ### Technical Analysis The endpoint trusts the submitted request body merely by casting it to `TelegramUpdate`. It does not verify Telegram's `X-Telegram-Bot-Api-Secret-Token` header, authenticate the caller through another mechanism, validate the request schema, or reject replayed updates. An arbitrary Internet client able to reach this route can therefore impersonate Telegram users and chats. The handler uses attacker-controlled identifiers to update `user_profiles`, creates a command containing attacker-controlled prompt text, creates a job, and invokes the queue RPC. The ...[truncated 1267 chars]- Remediation
View remediation
