crowdsec/pkg/cwhub/cwhub.go
mmetc 2c652ef92f
pkg/cwhub documentation (#2607)
* pkg/cwhub: package documentation

* Don't repeat local state in "cscli... inspect"

* lint

* use proper name of the hub item instead of the filename for local items

* hub update: avoid reporting local items as tainted
2023-11-21 17:43:10 +01:00

33 lines
639 B
Go

package cwhub
import (
"fmt"
"net/http"
"path/filepath"
"strings"
"time"
)
var hubClient = &http.Client{
Timeout: 120 * time.Second,
}
// safePath returns a joined path and ensures that it does not escape the base directory.
func safePath(dir, filePath string) (string, error) {
absBaseDir, err := filepath.Abs(filepath.Clean(dir))
if err != nil {
return "", err
}
absFilePath, err := filepath.Abs(filepath.Join(dir, filePath))
if err != nil {
return "", err
}
if !strings.HasPrefix(absFilePath, absBaseDir) {
return "", fmt.Errorf("path %s escapes base directory %s", filePath, dir)
}
return absFilePath, nil
}