Backport fix (#42979) (#42984)

* fixes

(cherry picked from commit a2c386915ce11b9422f4af8ae181eaa1a22bc5c3)
(cherry picked from commit 06706efbbe)

* fix regex

(cherry picked from commit a259213a3badc9618e969f2c8db0a0143f00faee)
(cherry picked from commit 1d7105c095)

* lint (#42970)

(cherry picked from commit afb9e8e5f3)

Co-authored-by: Will Browne <will.browne@grafana.com>
Co-authored-by: malcolmholmes <42545407+malcolmholmes@users.noreply.github.com>
(cherry picked from commit d6ec6f8ad2)

Co-authored-by: Marcus Efraimsson <marcus.efraimsson@gmail.com>
This commit is contained in:
Grot (@grafanabot)
2021-12-10 16:30:18 +01:00
committed by GitHub
co-authored by Marcus Efraimsson
parent 2f9153c95e
commit 361ad74acf
2 changed files with 13 additions and 8 deletions
+3 -2
View File
@@ -73,13 +73,14 @@ func (s *Service) handleCsvFileScenario(ctx context.Context, req *backend.QueryD
}
func (s *Service) loadCsvFile(fileName string) (*data.Frame, error) {
validFileName := regexp.MustCompile(`([\w_]+)\.csv`)
validFileName := regexp.MustCompile(`^\w+\.csv$`)
if !validFileName.MatchString(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