ProductBarcode: backend: improve security of image fetching

This commit is contained in:
Crumb Owl
2025-07-06 19:20:53 +00:00
parent 402b8c429e
commit e80e5744f7

View File

@@ -7,6 +7,7 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"github.com/hay-kot/httpkit/errchain"
"github.com/rs/zerolog/log"
@@ -242,6 +243,13 @@ func (ctrl *V1Controller) HandleProductSearchFromBarcode(conf config.BarcodeAPIC
continue
}
// Validate URL is HTTPS
u, err := url.Parse(p.ImageURL)
if err != nil || u.Scheme != "https" {
log.Warn().Msg("Skipping non-HTTPS image URL: " + p.ImageURL)
continue
}
res, err := http.Get(p.ImageURL)
if err != nil {
log.Warn().Msg("Cannot fetch image for URL: " + p.ImageURL + ": " + err.Error())