fix: validate media URL before downloading content from message (#1560)

This commit is contained in:
João Lucas de Oliveira Lopes
2025-06-30 16:02:40 -03:00
committed by GitHub
parent 210338c747
commit 591c98f3e6

View File

@@ -448,7 +448,12 @@ export const downloadContentFromMessage = async (
type: MediaType,
opts: MediaDownloadOptions = {}
) => {
const downloadUrl = url || getUrlFromDirectPath(directPath!)
const isValidMediaUrl = url?.startsWith('https://mmg.whatsapp.net/')
const downloadUrl = isValidMediaUrl ? url : getUrlFromDirectPath(directPath!)
if (!downloadUrl) {
throw new Boom('No valid media URL or directPath present in message', { statusCode: 400 })
}
const keys = await getMediaKeys(mediaKey, type)
return downloadEncryptedContent(downloadUrl, keys, opts)