Skip to content

Commit 499097e

Browse files
philippthunaldas
authored andcommitted
Ignore case of auth scheme in request header
Some clients send an authorization header containing the "bearer" keyword in lower case. This led to echo responding with "missing or malformed jwt". Request.BasicAuth (net/http) ignores the basic auth scheme's case since a while: https://go-review.googlesource.com/c/go/+/111516/
1 parent fcda0e8 commit 499097e

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

middleware/jwt.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ func jwtFromHeader(header string, authScheme string) jwtExtractor {
295295
return func(c echo.Context) (string, error) {
296296
auth := c.Request().Header.Get(header)
297297
l := len(authScheme)
298-
if len(auth) > l+1 && auth[:l] == authScheme {
298+
if len(auth) > l+1 && strings.EqualFold(auth[:l], authScheme) {
299299
return auth[l+1:], nil
300300
}
301301
return "", ErrJWTMissing

middleware/jwt_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,11 @@ func TestJWT(t *testing.T) {
261261
expErrCode: http.StatusUnauthorized,
262262
info: "Token verification does not pass using a user-defined KeyFunc",
263263
},
264+
{
265+
hdrAuth: strings.ToLower(DefaultJWTConfig.AuthScheme) + " " + token,
266+
config: JWTConfig{SigningKey: validKey},
267+
info: "Valid JWT with lower case AuthScheme",
268+
},
264269
} {
265270
if tc.reqURL == "" {
266271
tc.reqURL = "/"

0 commit comments

Comments
 (0)