Skip to content

Commit

Permalink
Merge pull request #34 from simonpasquier/bz-1843777-4.5
Browse files Browse the repository at this point in the history
Bug 1847310: only allow 32 hexadecimal digits for the avatar hash
  • Loading branch information
openshift-merge-robot committed Jun 17, 2020
2 parents de5d6c0 + 3f9b80d commit f653596
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions pkg/api/avatar/avatar.go
Expand Up @@ -15,14 +15,15 @@ import (
"net/http"
"net/url"
"path/filepath"
"regexp"
"strconv"
"strings"
"sync"
"time"

"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/models"
"github.com/grafana/grafana/pkg/setting"
"gopkg.in/macaron.v1"

gocache "github.com/patrickmn/go-cache"
)
Expand Down Expand Up @@ -83,9 +84,15 @@ type CacheServer struct {
cache *gocache.Cache
}

func (this *CacheServer) Handler(ctx *macaron.Context) {
urlPath := ctx.Req.URL.Path
hash := urlPath[strings.LastIndex(urlPath, "/")+1:]
var validMD5 = regexp.MustCompile("^[a-fA-F0-9]{32}$")

func (this *CacheServer) Handler(ctx *models.ReqContext) {
hash := ctx.Params("hash")

if len(hash) != 32 || !validMD5.MatchString(hash) {
ctx.JsonApiErr(404, "Avatar not found", nil)
return
}

var avatar *Avatar
obj, exists := this.cache.Get(hash)
Expand Down

0 comments on commit f653596

Please sign in to comment.