1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

chore: restrict badge access by user agent

This commit is contained in:
Ferdinand Mütsch 2020-09-12 16:58:19 +02:00
parent 6e2f3e6731
commit 1c0e63e125
2 changed files with 7 additions and 1 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/muety/wakapi/utils"
"net/http"
"regexp"
"strings"
)
const (
@ -33,6 +34,11 @@ func (h *BadgeHandler) ApiGet(w http.ResponseWriter, r *http.Request) {
intervalReg := regexp.MustCompile(intervalPattern)
entityFilterReg := regexp.MustCompile(entityFilterPattern)
if userAgent := r.Header.Get("user-agent"); !strings.HasPrefix(userAgent, "Shields.io/") && !h.config.IsDev() {
w.WriteHeader(http.StatusForbidden)
return
}
requestedUserId := mux.Vars(r)["user"]
user, err := h.userSrvc.GetUserById(requestedUserId)
if err != nil || !user.BadgesEnabled {

View File

@ -1 +1 @@
1.11.1
1.11.2