Skip to content

Commit

Permalink
Ignore case of auth scheme in request header
Browse files Browse the repository at this point in the history
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/
  • Loading branch information
philippthun authored and aldas committed Aug 10, 2021
1 parent fcda0e8 commit 499097e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion middleware/jwt.go
Expand Up @@ -295,7 +295,7 @@ func jwtFromHeader(header string, authScheme string) jwtExtractor {
return func(c echo.Context) (string, error) {
auth := c.Request().Header.Get(header)
l := len(authScheme)
if len(auth) > l+1 && auth[:l] == authScheme {
if len(auth) > l+1 && strings.EqualFold(auth[:l], authScheme) {
return auth[l+1:], nil
}
return "", ErrJWTMissing
Expand Down
5 changes: 5 additions & 0 deletions middleware/jwt_test.go
Expand Up @@ -261,6 +261,11 @@ func TestJWT(t *testing.T) {
expErrCode: http.StatusUnauthorized,
info: "Token verification does not pass using a user-defined KeyFunc",
},
{
hdrAuth: strings.ToLower(DefaultJWTConfig.AuthScheme) + " " + token,
config: JWTConfig{SigningKey: validKey},
info: "Valid JWT with lower case AuthScheme",
},
} {
if tc.reqURL == "" {
tc.reqURL = "/"
Expand Down

0 comments on commit 499097e

Please sign in to comment.