diff --git a/src/config/settings.go b/src/config/settings.go index aafe443..6941493 100644 --- a/src/config/settings.go +++ b/src/config/settings.go @@ -19,13 +19,14 @@ var ( DBName = "whatsapp.db" - WhatsappAutoReplyMessage string - WhatsappWebhook string - WhatsappWebhookSecret = "secret" - WhatsappLogLevel = "ERROR" - WhatsappSettingMaxFileSize int64 = 50000000 // 50MB - WhatsappSettingMaxVideoSize int64 = 100000000 // 100MB - WhatsappTypeUser = "@s.whatsapp.net" - WhatsappTypeGroup = "@g.us" - WhatsappAccountValidation = true + WhatsappAutoReplyMessage string + WhatsappWebhook string + WhatsappWebhookSecret = "secret" + WhatsappLogLevel = "ERROR" + WhatsappSettingMaxFileSize int64 = 50000000 // 50MB + WhatsappSettingMaxVideoSize int64 = 100000000 // 100MB + WhatsappSettingMaxDownloadSize int64 = 500000000 // 500MB + WhatsappTypeUser = "@s.whatsapp.net" + WhatsappTypeGroup = "@g.us" + WhatsappAccountValidation = true ) diff --git a/src/pkg/whatsapp/utils.go b/src/pkg/whatsapp/utils.go index c98e876..e48cd74 100644 --- a/src/pkg/whatsapp/utils.go +++ b/src/pkg/whatsapp/utils.go @@ -34,6 +34,12 @@ func ExtractMedia(storageLocation string, mediaFile whatsmeow.DownloadableMessag return extractedMedia, err } + // Validate file size before writing to disk + maxFileSize := config.WhatsappSettingMaxDownloadSize + if int64(len(data)) > maxFileSize { + return extractedMedia, fmt.Errorf("file size exceeds the maximum limit of %d bytes", maxFileSize) + } + switch media := mediaFile.(type) { case *waE2E.ImageMessage: extractedMedia.MimeType = media.GetMimetype()