chore: build
Backend - Build & Lint / build (push) Failing after 30m33s

This commit is contained in:
Nuxgrid
2026-08-01 21:51:32 +02:00
parent 0d9b4adc3a
commit 020ba7c1e4
6 changed files with 187 additions and 69 deletions
+17
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"math/big"
"path/filepath"
"strings"
)
func GenerateUniqueFileName(productName string, originalFileName string) string {
@@ -13,3 +14,19 @@ func GenerateUniqueFileName(productName string, originalFileName string) string
ext := filepath.Ext(originalFileName)
return fmt.Sprintf("%s_%s%s", productName, randomString, ext)
}
// SanitizeFilePath valide qu'un chemin de fichier local reste bien dans le
// dossier uploads/ et ne contient pas de tentative de path traversal.
func SanitizeFilePath(path string) (string, error) {
cleaned := filepath.Clean(path)
if strings.Contains(cleaned, "..") {
return "", fmt.Errorf("path traversal détecté")
}
if !strings.HasPrefix(cleaned, "uploads/") && !strings.HasPrefix(cleaned, "uploads\\") {
return "", fmt.Errorf("chemin invalide")
}
return cleaned, nil
}