Skip to content

Commit 1bcbb6a

Browse files
authored
http: ensure return after writing response by respondError (#8796) (#8798)
1 parent 8ab029d commit 1bcbb6a

4 files changed

Lines changed: 5 additions & 0 deletions

File tree

command/agent/cache/handler.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func Handler(ctx context.Context, logger hclog.Logger, proxier Proxier, inmemSin
4040
if err != nil {
4141
logger.Error("failed to read request body")
4242
logical.RespondError(w, http.StatusInternalServerError, errors.New("failed to read request body"))
43+
return
4344
}
4445
if r.Body != nil {
4546
r.Body.Close()

http/logical.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ func handleLogicalRecovery(raw *vault.RawBackend, token *atomic.String) http.Han
232232
reqToken := r.Header.Get(consts.AuthHeaderName)
233233
if reqToken == "" || token.Load() == "" || reqToken != token.Load() {
234234
respondError(w, http.StatusForbidden, nil)
235+
return
235236
}
236237

237238
resp, err := raw.HandleRequest(r.Context(), req)
@@ -379,6 +380,7 @@ func handleLogicalInternal(core *vault.Core, injectDataIntoTopLevel bool, noForw
379380
case strings.HasPrefix(req.Path, "sys/metrics"):
380381
if isStandby, _ := core.Standby(); isStandby {
381382
respondError(w, http.StatusBadRequest, vault.ErrCannotForwardLocalOnly)
383+
return
382384
}
383385
}
384386

http/sys_metrics.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func handleMetricsUnauthenticated(core *vault.Core) http.Handler {
1717
case "GET":
1818
default:
1919
respondError(w, http.StatusMethodNotAllowed, nil)
20+
return
2021
}
2122

2223
// Parse form

http/sys_raft.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func handleSysRaftJoinPost(core *vault.Core, w http.ResponseWriter, r *http.Requ
3333

3434
if req.NonVoter && !nonVotersAllowed {
3535
respondError(w, http.StatusBadRequest, errors.New("non-voting nodes not allowed"))
36+
return
3637
}
3738

3839
var tlsConfig *tls.Config

0 commit comments

Comments
 (0)