Skip to content

Commit

Permalink
fix: better error detection in our body size check
Browse files Browse the repository at this point in the history
  • Loading branch information
troyxmccall committed Jul 29, 2023
1 parent b4ddfd2 commit b3aba69
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions modsecurity_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package traefik_modsecurity_plugin

import (
"bytes"
"errors"
"fmt"
"io"
"net/http"
Expand All @@ -16,10 +17,10 @@ func (a *Modsecurity) HandleRequestBodyMaxSize(rw http.ResponseWriter, req *http
bodyReader := io.LimitReader(req.Body, a.maxBodySize+1)
bodyBuffer := new(bytes.Buffer)
n, err := io.Copy(bodyBuffer, bodyReader)
req.Body.Close()
err = req.Body.Close()

if err != nil {
if err == io.EOF || err == io.ErrUnexpectedEOF {
if err == io.EOF || errors.Is(err, io.ErrUnexpectedEOF) {
// Request body size is within limit.
req.Body = io.NopCloser(bodyBuffer)
return nil
Expand Down

0 comments on commit b3aba69

Please sign in to comment.