浏览代码

control: fix body rejection guard for empty POST requests

rejectBody() returns true when the request body is acceptable and false when a body must be rejected. The TX and fault-reset handlers treated the return value the wrong way around and returned early on valid empty POST requests. This prevented actions like /tx/stop from running in the normal no-body case.

Update the handlers to only abort when rejectBody() reports an actual rejection, so empty POST control actions proceed as intended.
main
Jan 1 个月前
父节点
当前提交
1d683d1d8f
共有 1 个文件被更改,包括 5 次插入2 次删除
  1. +5
    -2
      internal/control/control.go

+ 5
- 2
internal/control/control.go 查看文件

@@ -155,12 +155,15 @@ func hasRequestBody(r *http.Request) bool {
}

func (s *Server) rejectBody(w http.ResponseWriter, r *http.Request) bool {
// Returns true when the request has an unexpected body and the error response
// has already been written — callers should return immediately in that case.
// Returns false when there is no body (happy path — request should proceed).
if !hasRequestBody(r) {
return true
return false
}
s.recordAudit(auditUnexpectedBody)
http.Error(w, noBodyErrMsg, http.StatusBadRequest)
return false
return true
}

func (s *Server) recordAudit(evt auditEvent) {


正在加载...
取消
保存