From 1d7105c0959df2083814237024f7ec098a76099b Mon Sep 17 00:00:00 2001 From: Will Browne Date: Thu, 9 Dec 2021 18:59:46 +0000 Subject: [PATCH] fix regex (cherry picked from commit a259213a3badc9618e969f2c8db0a0143f00faee) --- pkg/tsdb/testdatasource/csv_data.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pkg/tsdb/testdatasource/csv_data.go b/pkg/tsdb/testdatasource/csv_data.go index e45ded815b4..6cb812e0ee5 100644 --- a/pkg/tsdb/testdatasource/csv_data.go +++ b/pkg/tsdb/testdatasource/csv_data.go @@ -8,6 +8,7 @@ import ( "io" "os" "path/filepath" + "regexp" "strconv" "strings" "time" @@ -72,7 +73,9 @@ func (s *Service) handleCsvFileScenario(ctx context.Context, req *backend.QueryD } func (s *Service) loadCsvFile(fileName string) (*data.Frame, error) { - if filepath.Ext(fileName) != ".csv" || strings.Contains(fileName, "..") { + validFileName := regexp.MustCompile(`^\w+\.csv$`) + + if !validFileName.MatchString(fileName) { return nil, fmt.Errorf("invalid csv file name: %q", fileName) }