(cherry picked from commit a2c386915ce11b9422f4af8ae181eaa1a22bc5c3)
This commit is contained in:
Will Browne
2021-12-10 10:56:25 +01:00
committed by Marcus Efraimsson
parent 7183b01df1
commit 06706efbbe
2 changed files with 13 additions and 11 deletions
+3 -5
View File
@@ -8,7 +8,6 @@ import (
"io"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"
@@ -73,13 +72,12 @@ func (s *Service) handleCsvFileScenario(ctx context.Context, req *backend.QueryD
}
func (s *Service) loadCsvFile(fileName string) (*data.Frame, error) {
validFileName := regexp.MustCompile(`([\w_]+)\.csv`)
if !validFileName.MatchString(fileName) {
if filepath.Ext(fileName) != ".csv" || strings.Contains(fileName, "..") {
return nil, fmt.Errorf("invalid csv file name: %q", fileName)
}
filePath := filepath.Join(s.cfg.StaticRootPath, "testdata", fileName)
csvFilepath := filepath.Clean(filepath.Join("/", fileName))
filePath := filepath.Join(s.cfg.StaticRootPath, "testdata", csvFilepath)
// Can ignore gosec G304 here, because we check the file pattern above
// nolint:gosec