diff --git a/testing/endtoend/helpers/helpers.go b/testing/endtoend/helpers/helpers.go index e1ee4b56a..89d9b3b81 100644 --- a/testing/endtoend/helpers/helpers.go +++ b/testing/endtoend/helpers/helpers.go @@ -48,7 +48,7 @@ func DeleteAndCreateFile(tmpPath, fileName string) (*os.File, error) { return nil, err } } - newFile, err := os.Create(path.Join(tmpPath, fileName)) + newFile, err := os.Create(filepath.Clean(path.Join(tmpPath, fileName))) if err != nil { return nil, err } @@ -161,7 +161,7 @@ func WritePprofFiles(testDir string, index int) error { return writeURLRespAtPath(url, filePath) } -func writeURLRespAtPath(url, filePath string) error { +func writeURLRespAtPath(url, fp string) error { resp, err := http.Get(url) // #nosec G107 -- Safe, used internally if err != nil { return err @@ -176,7 +176,7 @@ func writeURLRespAtPath(url, filePath string) error { if err != nil { return err } - file, err := os.Create(filePath) + file, err := os.Create(filepath.Clean(fp)) if err != nil { return err } diff --git a/tools/specs-checker/download.go b/tools/specs-checker/download.go index 19961aa95..f0099ba45 100644 --- a/tools/specs-checker/download.go +++ b/tools/specs-checker/download.go @@ -7,6 +7,7 @@ import ( "net/http" "os" "path" + "path/filepath" "regexp" "github.com/urfave/cli/v2" @@ -39,7 +40,7 @@ func download(cliCtx *cli.Context) error { func getAndSaveFile(specDocUrl, outFilePath string) error { // Create output file. - f, err := os.Create(outFilePath) + f, err := os.Create(filepath.Clean(outFilePath)) if err != nil { return fmt.Errorf("cannot create output file: %w", err) } diff --git a/validator/accounts/accounts_backup.go b/validator/accounts/accounts_backup.go index 9fb0a5866..e642ebacd 100644 --- a/validator/accounts/accounts_backup.go +++ b/validator/accounts/accounts_backup.go @@ -212,7 +212,7 @@ func zipKeystoresToOutputDir(keystoresToBackup []*keymanager.Keystore, outputDir return errors.Errorf("Zip file already exists in directory: %s", archivePath) } // We create a new file to store our backup.zip. - zipfile, err := os.Create(archivePath) + zipfile, err := os.Create(filepath.Clean(archivePath)) if err != nil { return errors.Wrapf(err, "could not create zip file with path: %s", archivePath) }