File tree Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Expand file tree Collapse file tree 2 files changed +7
-3
lines changed Original file line number Diff line number Diff line change 44 "encoding/base64"
55 "strconv"
66 "strings"
7+ "net/http"
78
89 "github.com/labstack/echo/v4"
910)
@@ -76,7 +77,11 @@ func BasicAuthWithConfig(config BasicAuthConfig) echo.MiddlewareFunc {
7677 if len (auth ) > l + 1 && strings .EqualFold (auth [:l ], basic ) {
7778 // Invalid base64 shouldn't be treated as error
7879 // instead should be treated as invalid client input
79- b , _ := base64 .StdEncoding .DecodeString (auth [l + 1 :])
80+ b , err := base64 .StdEncoding .DecodeString (auth [l + 1 :])
81+ if err != nil {
82+ return echo .NewHTTPError (http .StatusBadRequest ).SetInternal (err )
83+ }
84+
8085 cred := string (b )
8186 for i := 0 ; i < len (cred ); i ++ {
8287 if cred [i ] == ':' {
Original file line number Diff line number Diff line change @@ -62,8 +62,7 @@ func TestBasicAuth(t *testing.T) {
6262 auth = basic + " invalidString"
6363 req .Header .Set (echo .HeaderAuthorization , auth )
6464 he = h (c ).(* echo.HTTPError )
65- assert .Equal (http .StatusUnauthorized , he .Code )
66- assert .Equal (basic + ` realm="someRealm"` , res .Header ().Get (echo .HeaderWWWAuthenticate ))
65+ assert .Equal (http .StatusBadRequest , he .Code )
6766
6867 // Missing Authorization header
6968 req .Header .Del (echo .HeaderAuthorization )
You can’t perform that action at this time.
0 commit comments