Update path validator
All checks were successful
CI.yml / build (push) Successful in 56s

This commit is contained in:
d3m0k1d
2026-01-12 15:56:28 +03:00
parent 7c0bdc2dfa
commit 871965f437

View File

@@ -1,8 +1,11 @@
package blocker
import (
"errors"
"fmt"
"net"
"path/filepath"
"strings"
)
func validateIP(ip string) error {
@@ -17,10 +20,20 @@ func validateIP(ip string) error {
return nil
}
func validateConfigPath(path string) error {
if path == "" {
return fmt.Errorf("empty path")
func validateConfigPath(pathIn string) error {
if pathIn == "" {
return errors.New("config path cannot be empty")
}
cleanPath := filepath.Clean(pathIn)
if !filepath.IsAbs(cleanPath) {
return fmt.Errorf("config path must be absolute, got: %s", cleanPath)
}
if strings.Contains(cleanPath, "..") {
return fmt.Errorf("config path contains path traversal: %s", cleanPath)
}
return nil
// TODO: add more valodation
}