Skip to content

Commit

Permalink
chore: increase io.ReadAll size limit for variable use cases (#2055)
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Wang <whynowy@gmail.com>
  • Loading branch information
whynowy committed Jun 28, 2022
1 parent 92f2f32 commit a58a677
Show file tree
Hide file tree
Showing 9 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions eventsources/sources/awssns/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func (router *Router) HandleRoute(writer http.ResponseWriter, request *http.Requ
route.Metrics.EventProcessingDuration(route.EventSourceName, route.EventName, float64(time.Since(start)/time.Millisecond))
}(time.Now())

request.Body = http.MaxBytesReader(writer, request.Body, 65536)
request.Body = http.MaxBytesReader(writer, request.Body, 256*1024) // SNS message size limit is 256KB
body, err := io.ReadAll(request.Body)
if err != nil {
logger.Errorw("failed to parse the request body", zap.Error(err))
Expand Down Expand Up @@ -319,7 +319,7 @@ func (m *httpNotification) verify() error {
}
defer res.Body.Close()

body, err := io.ReadAll(io.LimitReader(res.Body, 65536))
body, err := io.ReadAll(io.LimitReader(res.Body, 65*1024))
if err != nil {
return errors.Wrap(err, "failed to read signing cert body")
}
Expand Down
2 changes: 1 addition & 1 deletion eventsources/sources/bitbucket/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (router *Router) HandleRoute(writer http.ResponseWriter, request *http.Requ
return
}

request.Body = http.MaxBytesReader(writer, request.Body, 65536)
request.Body = http.MaxBytesReader(writer, request.Body, 256*1024)
body, err := io.ReadAll(request.Body)
if err != nil {
logger.Desugar().Error("failed to parse request body", zap.Error(err))
Expand Down
2 changes: 1 addition & 1 deletion eventsources/sources/bitbucketserver/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ func (router *Router) createRequestBodyFromWebhook(hook bitbucketv1.Webhook) ([]
}

func (router *Router) parseAndValidateBitbucketServerRequest(writer http.ResponseWriter, request *http.Request) ([]byte, error) {
request.Body = http.MaxBytesReader(writer, request.Body, 65536)
request.Body = http.MaxBytesReader(writer, request.Body, 256*1024)
body, err := io.ReadAll(request.Body)
if err != nil {
return nil, errors.Wrap(err, "failed to parse request body")
Expand Down
2 changes: 1 addition & 1 deletion eventsources/sources/gitlab/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func (router *Router) HandleRoute(writer http.ResponseWriter, request *http.Requ
return
}
}
request.Body = http.MaxBytesReader(writer, request.Body, 65536)
request.Body = http.MaxBytesReader(writer, request.Body, 256*1024)
body, err := io.ReadAll(request.Body)
if err != nil {
logger.Errorw("failed to parse request body", zap.Error(err))
Expand Down
2 changes: 1 addition & 1 deletion eventsources/sources/storagegrid/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (router *Router) HandleRoute(writer http.ResponseWriter, request *http.Requ
}

logger.Info("parsing the request body...")
request.Body = http.MaxBytesReader(writer, request.Body, 65536)
request.Body = http.MaxBytesReader(writer, request.Body, 1024*1024)
body, err := io.ReadAll(request.Body)
if err != nil {
logger.Errorw("failed to parse request body", zap.Error(err))
Expand Down
2 changes: 1 addition & 1 deletion eventsources/sources/stripe/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (rc *Router) HandleRoute(writer http.ResponseWriter, request *http.Request)
route.Metrics.EventProcessingDuration(route.EventSourceName, route.EventName, float64(time.Since(start)/time.Millisecond))
}(time.Now())

const MaxBodyBytes = int64(65536)
const MaxBodyBytes = int64(1024 * 1024)
request.Body = http.MaxBytesReader(writer, request.Body, MaxBodyBytes)
payload, err := io.ReadAll(request.Body)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion eventsources/sources/webhook/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func GetBody(writer *http.ResponseWriter, request *http.Request, route *webhook.
return &ret, nil
// default including "application/json" is parsing body as JSON
default:
request.Body = http.MaxBytesReader(*writer, request.Body, 65536)
request.Body = http.MaxBytesReader(*writer, request.Body, 1024*1024)
body, err := getRequestBody(request)
if err != nil {
logger.Errorw("failed to read request body", zap.Error(err))
Expand Down
2 changes: 1 addition & 1 deletion sensors/artifacts/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (reader *S3Reader) Read() ([]byte, error) {
}
}()

b, err := io.ReadAll(io.LimitReader(obj, 65536))
b, err := io.ReadAll(io.LimitReader(obj, 1024*1224))
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion sensors/artifacts/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func (reader *URLReader) Read() ([]byte, error) {
return nil, errors.Errorf("status code %v", resp.StatusCode)
}

content, err := io.ReadAll(io.LimitReader(resp.Body, 65536))
content, err := io.ReadAll(io.LimitReader(resp.Body, 512*1024))
if err != nil {
log.Warnf("failed to read url body for %s: %s", reader.urlArtifact.Path, err)
return nil, err
Expand Down

0 comments on commit a58a677

Please sign in to comment.