fix(server): fix auth failure when complex characters in token (#42)

Co-authored-by: E99p1ant <[email protected]>
Co-authored-by: Li4n0 <[email protected]>
This commit is contained in:
tardc
2021-12-24 21:11:00 +08:00
committed by GitHub
co-authored by E99p1ant Li4n0
parent b88bcd9113
commit 3242a49b27
+5 -2
View File
@@ -31,8 +31,11 @@ func (revsuit *Revsuit) registerPlatformRouter() {
// /api need Authorization
api := revsuit.http.Router.Group(revsuit.config.AdminPathPrefix + "/api")
api.Use(func(c *gin.Context) {
cookieToken, err := c.Request.Cookie("token")
if !(c.Request.Header.Get("Token") == revsuit.http.Token || err == nil && cookieToken.Value == revsuit.http.Token) {
token, err := c.Cookie("token")
if err == http.ErrNoCookie {
token = c.Request.Header.Get("Token")
}
if token != revsuit.http.Token {
c.Abort()
c.Status(403)
}