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:
parent
6e2f3e6731
commit
1c0e63e125
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/muety/wakapi/utils"
|
"github.com/muety/wakapi/utils"
|
||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -33,6 +34,11 @@ func (h *BadgeHandler) ApiGet(w http.ResponseWriter, r *http.Request) {
|
|||||||
intervalReg := regexp.MustCompile(intervalPattern)
|
intervalReg := regexp.MustCompile(intervalPattern)
|
||||||
entityFilterReg := regexp.MustCompile(entityFilterPattern)
|
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"]
|
requestedUserId := mux.Vars(r)["user"]
|
||||||
user, err := h.userSrvc.GetUserById(requestedUserId)
|
user, err := h.userSrvc.GetUserById(requestedUserId)
|
||||||
if err != nil || !user.BadgesEnabled {
|
if err != nil || !user.BadgesEnabled {
|
||||||
|
@ -1 +1 @@
|
|||||||
1.11.1
|
1.11.2
|
Loading…
Reference in New Issue
Block a user