Add safe guards for relative paths
This commit adds multiple safe guards for relative paths, ensuring they never traverse outside the working directory. The `SafeRelativePath` flag calculates the safe relative path based on a relative base dir, which results in a flattened path. The write methods of `manifestgen` make use of the `SecureJoin` as well, to ensure writes are never outside of the given directory when used as a lib outside of the CLI. Signed-off-by: Hidde Beydals <hello@hidde.co>
This commit is contained in:
@@ -24,6 +24,8 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
securejoin "github.com/cyphar/filepath-securejoin"
|
||||
|
||||
"github.com/fluxcd/flux2/pkg/manifestgen"
|
||||
)
|
||||
|
||||
@@ -40,7 +42,10 @@ func Generate(options Options) (*manifestgen.Manifest, error) {
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
output := path.Join(tmpDir, options.ManifestFile)
|
||||
output, err := securejoin.SecureJoin(tmpDir, options.ManifestFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(options.BaseURL, "http") {
|
||||
if err := build(options.BaseURL, output); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user