From c9aa2eeb9852047e4f41915eb30726bd25f07ecd Mon Sep 17 00:00:00 2001 From: CorrectRoadH Date: Fri, 30 Jun 2023 22:59:52 +0800 Subject: [PATCH] fix: validate access token (#1867) * fix/to_valid_token * eslint * revert * Update server/jwt.go --------- Co-authored-by: boojack --- server/jwt.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/jwt.go b/server/jwt.go index 4f6a31aa..2cb9af44 100644 --- a/server/jwt.go +++ b/server/jwt.go @@ -111,6 +111,11 @@ func JWTMiddleware(server *Server, next echo.HandlerFunc, secret string) echo.Ha } return nil, errors.Errorf("unexpected access token kid=%v", t.Header["kid"]) }) + + if !accessToken.Valid { + return echo.NewHTTPError(http.StatusUnauthorized, "Invalid access token.") + } + if !audienceContains(claims.Audience, auth.AccessTokenAudienceName) { return echo.NewHTTPError(http.StatusUnauthorized, fmt.Sprintf("Invalid access token, audience mismatch, got %q, expected %q.", claims.Audience, auth.AccessTokenAudienceName)) }