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 4
4
"encoding/base64"
5
5
"strconv"
6
6
"strings"
7
+ "net/http"
7
8
8
9
"github.com/labstack/echo/v4"
9
10
)
@@ -76,7 +77,11 @@ func BasicAuthWithConfig(config BasicAuthConfig) echo.MiddlewareFunc {
76
77
if len (auth ) > l + 1 && strings .EqualFold (auth [:l ], basic ) {
77
78
// Invalid base64 shouldn't be treated as error
78
79
// 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
+
80
85
cred := string (b )
81
86
for i := 0 ; i < len (cred ); i ++ {
82
87
if cred [i ] == ':' {
Original file line number Diff line number Diff line change @@ -62,8 +62,7 @@ func TestBasicAuth(t *testing.T) {
62
62
auth = basic + " invalidString"
63
63
req .Header .Set (echo .HeaderAuthorization , auth )
64
64
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 )
67
66
68
67
// Missing Authorization header
69
68
req .Header .Del (echo .HeaderAuthorization )
You can’t perform that action at this time.
0 commit comments