This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
package blocker
|
package blocker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func validateIP(ip string) error {
|
func validateIP(ip string) error {
|
||||||
@@ -17,10 +20,20 @@ func validateIP(ip string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateConfigPath(path string) error {
|
func validateConfigPath(pathIn string) error {
|
||||||
if path == "" {
|
if pathIn == "" {
|
||||||
return fmt.Errorf("empty path")
|
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
|
return nil
|
||||||
// TODO: add more valodation
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user