File tree Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Expand file tree Collapse file tree 2 files changed +10
-4
lines changed Original file line number Diff line number Diff line change @@ -74,10 +74,9 @@ func BasicAuthWithConfig(config BasicAuthConfig) echo.MiddlewareFunc {
74
74
l := len (basic )
75
75
76
76
if len (auth ) > l + 1 && strings .EqualFold (auth [:l ], basic ) {
77
- b , err := base64 .StdEncoding .DecodeString (auth [l + 1 :])
78
- if err != nil {
79
- return err
80
- }
77
+ // Invalid base64 shouldn't be treated as error
78
+ // instead should be treated as invalid client input
79
+ b , _ := base64 .StdEncoding .DecodeString (auth [l + 1 :])
81
80
cred := string (b )
82
81
for i := 0 ; i < len (cred ); i ++ {
83
82
if cred [i ] == ':' {
Original file line number Diff line number Diff line change @@ -58,6 +58,13 @@ func TestBasicAuth(t *testing.T) {
58
58
assert .Equal (http .StatusUnauthorized , he .Code )
59
59
assert .Equal (basic + ` realm="someRealm"` , res .Header ().Get (echo .HeaderWWWAuthenticate ))
60
60
61
+ // Invalid base64 string
62
+ auth = basic + " invalidString"
63
+ req .Header .Set (echo .HeaderAuthorization , auth )
64
+ he = h (c ).(* echo.HTTPError )
65
+ assert .Equal (http .StatusUnauthorized , he .Code )
66
+ assert .Equal (basic + ` realm="someRealm"` , res .Header ().Get (echo .HeaderWWWAuthenticate ))
67
+
61
68
// Missing Authorization header
62
69
req .Header .Del (echo .HeaderAuthorization )
63
70
he = h (c ).(* echo.HTTPError )
You can’t perform that action at this time.
0 commit comments