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
3
3
import (
4
4
"encoding/base64"
5
5
"strconv"
6
+ "strings"
6
7
7
8
"github.com/labstack/echo"
8
9
)
27
28
)
28
29
29
30
const (
30
- basic = "Basic "
31
+ basic = "basic "
31
32
defaultRealm = "Restricted"
32
33
)
33
34
@@ -72,7 +73,7 @@ func BasicAuthWithConfig(config BasicAuthConfig) echo.MiddlewareFunc {
72
73
auth := c .Request ().Header .Get (echo .HeaderAuthorization )
73
74
l := len (basic )
74
75
75
- if len (auth ) > l + 1 && auth [:l ] == basic {
76
+ if len (auth ) > l + 1 && strings . ToLower ( auth [:l ]) == basic {
76
77
b , err := base64 .StdEncoding .DecodeString (auth [l + 1 :])
77
78
if err != nil {
78
79
return err
Original file line number Diff line number Diff line change 4
4
"encoding/base64"
5
5
"net/http"
6
6
"net/http/httptest"
7
+ "strings"
7
8
"testing"
8
9
9
10
"github.com/labstack/echo"
@@ -30,6 +31,11 @@ func TestBasicAuth(t *testing.T) {
30
31
req .Header .Set (echo .HeaderAuthorization , auth )
31
32
assert .NoError (t , h (c ))
32
33
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
+
33
39
// Invalid credentials
34
40
auth = basic + " " + base64 .StdEncoding .EncodeToString ([]byte ("joe:invalid-password" ))
35
41
req .Header .Set (echo .HeaderAuthorization , auth )
You can’t perform that action at this time.
0 commit comments