Browse Source

feat: add max download size validation for media files

- settings.go: add WhatsappSettingMaxDownloadSize for file size
  validation (500MB)
- utils.go: check file size before writing media to disk, returning
  an error if it exceeds the max limit
pull/221/head
Aldino Kemal 1 year ago
parent
commit
0b59619c93
  1. 1
      src/config/settings.go
  2. 6
      src/pkg/whatsapp/utils.go

1
src/config/settings.go

@ -25,6 +25,7 @@ var (
WhatsappLogLevel = "ERROR"
WhatsappSettingMaxFileSize int64 = 50000000 // 50MB
WhatsappSettingMaxVideoSize int64 = 100000000 // 100MB
WhatsappSettingMaxDownloadSize int64 = 500000000 // 500MB
WhatsappTypeUser = "@s.whatsapp.net"
WhatsappTypeGroup = "@g.us"
WhatsappAccountValidation = true

6
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()

Loading…
Cancel
Save