High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
fix: harden config and upload path handling
Luigi Agosti0b9a3d65d098
diff --git a/internal/config/fileio_minimal.go b/internal/config/fileio_minimal.goindex 7cf3732a..0676fa4b 100644--- a/internal/config/fileio_minimal.go+++ b/internal/config/fileio_minimal.go@@ -63,7 +63,10 @@ func parseJSONObject(data []byte) []jsonMember {// stale value in place, which is the one way writing less can lose data.func patchConfigObject(onDisk []jsonMember, full, shipped map[string]any) []jsonMember {seen := make(map[string]bool, len(onDisk))- out := make([]jsonMember, 0, len(onDisk)+len(full))+ // The result often needs room for both collections, but adding their lengths+ // can overflow int before make validates the capacity. Start with the known+ // on-disk size and let append grow the slice for new members.+ out := make([]jsonMember, 0, len(onDisk))for _, member := range onDisk {seen[member.key] = truediff --git a/internal/handlers/upload.go b/internal/handlers/upload.goindex 0ac4d738..c7d8aa04 100644--- a/internal/handlers/upload.go+++ b/internal/handlers/upload.go@@ -268,8 +268,11 @@ func stagedUploadName(name string, i int, ext string) string {// contains no separator at all and survives whole. The cost is that a literal// backslash in a genuine POSIX filename is treated as a separator too, which is// the same trade a browser makes — it sends the final component and nothing else.- trimmed := strings.TrimSpace(name)- base := trimmed[strings.LastIndexAny(trimmed, `/\`)+1:]+ trimmed := strings.ReplaceAll(strings.TrimSpace(name), `\`, "/")+ if strings.HasSuffix(trimmed, "/") {+ return generated+ }+ base := filepath.Base(trimmed)switch {case base == "", base == ".", base == "..", strings.ContainsRune(base, 0):return generated@@ -292,7 +295,11 @@ func stageUploadPath(stagedDir string, i int, name, ext string) (string, error)if err := os.MkdirAll(fileDir, 0o700); err != nil {return "", fmt.Errorf("create staged dir: %w", err)}- return filepath.Join(fileDir, stagedUploadName(name, i, ext)), nil+ path, err := httpx.SafeCreatePath(fileDir, stagedUploadName(name, i, ext))+ if err != nil {+ return "", fmt.Errorf("resolve staged file path: %w", err)+ }+ return path, nil}func validateUploadSandboxPath(baseDir, rawPath string, maxFileBytes int) (string, int64, error) {