Skip to content

Commit 98367ab

Browse files
author
raulgzm
committed
Workaround for Critical vulnerabilities in JSON Web Token libraries. Algorithm verification in middleware.
1 parent 5d6f823 commit 98367ab

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

core/authentication/middlewares.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package authentication
22

33
import (
4+
"fmt"
45
jwt "github.com/dgrijalva/jwt-go"
56
"net/http"
67
)
@@ -9,7 +10,12 @@ func RequireTokenAuthentication(rw http.ResponseWriter, req *http.Request, next
910
authBackend := InitJWTAuthenticationBackend()
1011

1112
token, err := jwt.ParseFromRequest(req, func(token *jwt.Token) (interface{}, error) {
12-
return authBackend.PublicKey, nil
13+
if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok {
14+
fmt.Println("Unexpected signing method")
15+
return nil, fmt.Errorf("Unexpected signing method: %v", token.Header["alg"])
16+
} else {
17+
return authBackend.PublicKey, nil
18+
}
1319
})
1420

1521
if err == nil && token.Valid && !authBackend.IsInBlacklist(req.Header.Get("Authorization")) {

0 commit comments

Comments
 (0)