Match basepath against regexp to ensure proper format

pull/10616/head
Jared Scheib 2018-04-20 11:39:42 -07:00
parent 923d73a418
commit 094f96a73b
1 changed files with 4 additions and 3 deletions

View File

@ -11,9 +11,9 @@ import (
"net/url" "net/url"
"os" "os"
"path" "path"
"regexp"
"runtime" "runtime"
"strconv" "strconv"
"strings"
"time" "time"
"github.com/influxdata/chronograf" "github.com/influxdata/chronograf"
@ -346,8 +346,9 @@ func (s *Server) Serve(ctx context.Context) error {
return err return err
} }
if strings.HasPrefix(s.Basepath, "/") { re := regexp.MustCompile(`(\/{1}\w+)+`)
err := fmt.Errorf("Basepath must begin with '/'") if len(re.ReplaceAllLiteralString(s.Basepath, "")) > 0 {
err := fmt.Errorf("Invalid basepath, must follow format \"/mybasepath\"")
logger. logger.
WithField("component", "server"). WithField("component", "server").
WithField("basepath", "invalid"). WithField("basepath", "invalid").