Skip to content

Commit

Permalink
fix(sigmap-EDAP-04): Add IO parsing size constraint on incoming reque…
Browse files Browse the repository at this point in the history
…st bodies
  • Loading branch information
epociask committed Jan 9, 2025
1 parent 0fb5ae8 commit 692f8e8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion server/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import (
"github.com/gorilla/mux"
)

const (
// limit requests to only 32 mib to mitigate potential DoS attacks
maxRequestBodySize int64 = 1048576 * 32
)

func (svr *Server) handleHealth(w http.ResponseWriter, _ *http.Request) error {
w.WriteHeader(http.StatusOK)
return nil
Expand Down Expand Up @@ -164,7 +169,7 @@ func (svr *Server) handlePostOPGenericCommitment(w http.ResponseWriter, r *http.

func (svr *Server) handlePostShared(w http.ResponseWriter, r *http.Request, comm []byte, meta commitments.CommitmentMeta) error {
svr.log.Info("Processing POST request", "commitment", hex.EncodeToString(comm), "commitmentMeta", meta)
input, err := io.ReadAll(r.Body)
input, err := io.ReadAll(http.MaxBytesReader(w, r.Body, maxRequestBodySize))
if err != nil {
err = MetaError{
Err: fmt.Errorf("failed to read request body: %w", err),
Expand Down

0 comments on commit 692f8e8

Please sign in to comment.