File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ package middleware
33import (
44 "encoding/base64"
55 "strconv"
6+ "strings"
67
78 "github.com/labstack/echo"
89)
2728)
2829
2930const (
30- basic = "Basic "
31+ basic = "basic "
3132 defaultRealm = "Restricted"
3233)
3334
@@ -72,7 +73,7 @@ func BasicAuthWithConfig(config BasicAuthConfig) echo.MiddlewareFunc {
7273 auth := c .Request ().Header .Get (echo .HeaderAuthorization )
7374 l := len (basic )
7475
75- if len (auth ) > l + 1 && auth [:l ] == basic {
76+ if len (auth ) > l + 1 && strings . ToLower ( auth [:l ]) == basic {
7677 b , err := base64 .StdEncoding .DecodeString (auth [l + 1 :])
7778 if err != nil {
7879 return err
Original file line number Diff line number Diff line change 44 "encoding/base64"
55 "net/http"
66 "net/http/httptest"
7+ "strings"
78 "testing"
89
910 "github.com/labstack/echo"
@@ -30,6 +31,11 @@ func TestBasicAuth(t *testing.T) {
3031 req .Header .Set (echo .HeaderAuthorization , auth )
3132 assert .NoError (t , h (c ))
3233
34+ // Case-insensitive header scheme
35+ auth = strings .ToUpper (basic ) + " " + base64 .StdEncoding .EncodeToString ([]byte ("joe:secret" ))
36+ req .Header .Set (echo .HeaderAuthorization , auth )
37+ assert .NoError (t , h (c ))
38+
3339 // Invalid credentials
3440 auth = basic + " " + base64 .StdEncoding .EncodeToString ([]byte ("joe:invalid-password" ))
3541 req .Header .Set (echo .HeaderAuthorization , auth )
You can’t perform that action at this time.
0 commit comments