Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions apps/web-app/server/services/telegram/wasabi-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,14 @@ async function handlePhoto(ctx: Context) {
return null
}

let fileUrl

const downloadUrl = await getFileDownloadUrl({ ctx, fileId, botToken })
if (!downloadUrl) {
return
if (downloadUrl) {
const uploaded = await uploadToStorage(downloadUrl, fileId)
fileUrl = uploaded.fileUrl
}

const { fileUrl } = await uploadToStorage(downloadUrl, fileId)

await repository.ticket.createMessage({
ticketId: data.ticket.id,
userId: data.user.id,
Expand Down Expand Up @@ -177,13 +178,14 @@ async function handleVideo(ctx: Context) {
return null
}

let fileUrl

const downloadUrl = await getFileDownloadUrl({ ctx, fileId, botToken })
if (!downloadUrl) {
return
if (downloadUrl) {
const uploaded = await uploadToStorage(downloadUrl, fileId)
fileUrl = uploaded.fileUrl
}

const { fileUrl } = await uploadToStorage(downloadUrl, fileId)

await repository.ticket.createMessage({
ticketId: data.ticket.id,
userId: data.user.id,
Expand Down Expand Up @@ -214,13 +216,14 @@ async function handleFile(ctx: Context) {
return null
}

let fileUrl

const downloadUrl = await getFileDownloadUrl({ ctx, fileId, botToken })
if (!downloadUrl) {
return
if (downloadUrl) {
const uploaded = await uploadToStorage(downloadUrl, fileId)
fileUrl = uploaded.fileUrl
}

const { fileUrl } = await uploadToStorage(downloadUrl, fileId)

await repository.ticket.createMessage({
ticketId: data.ticket.id,
userId: data.user.id,
Expand All @@ -230,7 +233,7 @@ async function handleFile(ctx: Context) {
text: `${ctx.message.caption ?? ''} ${ctx.message.document?.file_name ?? ''}`,
})

logger.log('file', data.user.id, ctx.message.from.id, ctx.message.text, ctx.message.caption, ctx.message.document, downloadUrl)
logger.log('file', data.user.id, ctx.message.from.id, ctx.message.caption, ctx.message.document, downloadUrl)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Do not log downloadUrl (bot token exposure).

downloadUrl embeds the bot token in the URL path; logging it leaks credentials. Remove or redact.

-  logger.log('file', data.user.id, ctx.message.from.id, ctx.message.caption, ctx.message.document, downloadUrl)
+  logger.log('file', data.user.id, ctx.message.from.id, ctx.message.caption, ctx.message.document, { hasDownloadUrl: Boolean(downloadUrl) })

Also update similar logs for photo/video (outside this hunk):

logger.log('photo', data.user.id, ctx.message.from.id, ctx.message.caption, ctx.message.photo, { hasDownloadUrl: Boolean(downloadUrl) })
logger.log('video', data.user.id, ctx.message.from.id, ctx.message.caption, ctx.message.video, { hasDownloadUrl: Boolean(downloadUrl) })
🤖 Prompt for AI Agents
In apps/web-app/server/services/telegram/wasabi-bot.ts around line 236, the
logger call currently includes downloadUrl which exposes the bot token; remove
the raw downloadUrl from logging and instead log only safe identifiers and
metadata (e.g., keep 'file', data.user.id, ctx.message.from.id,
ctx.message.caption, ctx.message.document) and add a boolean flag indicating
presence of a download URL (e.g., { hasDownloadUrl: Boolean(downloadUrl) }) so
the actual URL/token is never written to logs; also update the analogous photo
and video logging sites to stop outputting the raw downloadUrl and use the same
{ hasDownloadUrl: Boolean(downloadUrl) } pattern.

ctx.reply('Файл передан в службу поддержки.')
}

Expand Down Expand Up @@ -259,14 +262,18 @@ async function getUserAndTicket(telegramId: string): Promise<{ user: User, ticke
return { user: telegramUser.user, ticket }
}

async function getFileDownloadUrl(data: { ctx: Context, fileId: string, botToken: string }) {
// https://api.telegram.org/file/bot<token>/<file_path>
const file = await data.ctx.api.getFile(data.fileId)
if (!file) {
async function getFileDownloadUrl(data: { ctx: Context, fileId: string, botToken: string }): Promise<string | null> {
try {
const file = await data.ctx.api.getFile(data.fileId)
if (!file) {
return null
}

return `https://api.telegram.org/file/bot${data.botToken}/${file.file_path}`
} catch (e) {
logger.error('getFileDownloadUrl', e)
return null
}

return `https://api.telegram.org/file/bot${data.botToken}/${file.file_path}`
}

async function getBotToken(): Promise<string | null> {
Expand Down