Skip to content

Commit

Permalink
fix: Add missing body close calls after reading from request
Browse files Browse the repository at this point in the history
Signed-off-by: jay-dee7 <[email protected]>
  • Loading branch information
jay-dee7 committed Dec 7, 2023
1 parent b0bf038 commit 0d89fdc
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion auth/server/webauthn_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ func (wa *webauthn_server) BeginLogin(ctx echo.Context) error {
},
}

defer func() {
ctx.Request().Body.Close()
}()

credentialAssertion, err := wa.webauthn.BeginLogin(ctx.Request().Context(), opts)
if err != nil {
if werr := wa.webauthn.RemoveSessionData(ctx.Request().Context(), user.ID); werr != nil {
Expand All @@ -366,7 +370,6 @@ func (wa *webauthn_server) BeginLogin(ctx echo.Context) error {
wa.logger.Log(ctx, err).Send()
return echoErr
}
defer ctx.Request().Body.Close()

echoErr := ctx.JSON(http.StatusOK, echo.Map{
"options": credentialAssertion,
Expand Down
2 changes: 1 addition & 1 deletion auth/signup.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
func (a *auth) parseSignUpRequest(ctx echo.Context) (*types.User, error) {
var user types.User
if err := json.NewDecoder(ctx.Request().Body).Decode(&user); err != nil {
return nil, err
return nil, fmt.Errorf("error parsing signup request: %w", err)
}
defer ctx.Request().Body.Close()

Expand Down
1 change: 1 addition & 0 deletions orgmode/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func (o *orgMode) AllowOrgAdmin() echo.MiddlewareFunc {
o.logger.Log(ctx, err).Send()
return echoErr
}
defer ctx.Request().Body.Close()

// only allow self-migrate
if !strings.EqualFold(user.ID.String(), body.UserID.String()) {
Expand Down
1 change: 1 addition & 0 deletions registry/v2/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (r *registry) CreateRepository(ctx echo.Context) error {
"message": "error parsing request input",
})
}
defer ctx.Request().Body.Close()

if err = body.Validate(); err != nil {
return ctx.JSON(http.StatusBadRequest, echo.Map{
Expand Down

0 comments on commit 0d89fdc

Please sign in to comment.