@@ -68,12 +68,12 @@ var (
6868)
6969
7070const (
71- DefaultMaxBodyLength = 2 * 1024 * 1024 * 1024 // 2Gb
72- DefaultMaxUnauthBodyLength = 8 * 1024 * 1024 // 8Mb
73- DefaultHTTPTimeout = time .Minute
74- DefaultLongPollTimeout = time .Second
75- DefaultLongPollJitter = time .Second
76- minPollTimeout = time .Second
71+ DefaultMaxBodyLength = 2 * 1024 * 1024 * 1024 // 2Gb
72+ DefaultMaxUnauthBodyLength = 8 * 1024 * 1024 // 8Mb
73+ DefaultHTTPTimeout = time .Minute
74+ DefaultLongPollTimeout = time .Second
75+ DefaultLongPollJitter = time .Second
76+ minPollTimeout = time .Second
7777)
7878
7979var (
@@ -574,7 +574,7 @@ func (s *SliverHTTPC2) startSessionHandler(resp http.ResponseWriter, req *http.R
574574 s .defaultHandler (resp , req )
575575 return
576576 }
577- data , err := encoder . Decode ( body )
577+ data , err := decodeReqBodyWithMaxLen ( encoder , body , int64 ( DefaultMaxUnauthBodyLength ) )
578578 if err != nil {
579579 httpLog .Errorf ("Failed to decode body %s" , err )
580580 s .defaultHandler (resp , req )
@@ -720,7 +720,7 @@ func (s *SliverHTTPC2) readReqBody(httpSession *HTTPSession, resp http.ResponseW
720720 return nil , err
721721 }
722722
723- data , err := encoder . Decode ( body )
723+ data , err := decodeReqBodyWithMaxLen ( encoder , body , int64 ( DefaultMaxBodyLength ) )
724724 if err != nil {
725725 httpLog .Warnf ("Failed to decode body %s" , err )
726726 s .defaultHandler (resp , req )
@@ -735,6 +735,13 @@ func (s *SliverHTTPC2) readReqBody(httpSession *HTTPSession, resp http.ResponseW
735735 return plaintext , err
736736}
737737
738+ func decodeReqBodyWithMaxLen (encoder sliverEncoders.Encoder , body []byte , maxDecodedLen int64 ) ([]byte , error ) {
739+ if limitedDecoder , ok := encoder .(sliverEncoders.LimitedDecoder ); ok {
740+ return limitedDecoder .DecodeWithMaxLen (body , maxDecodedLen )
741+ }
742+ return encoder .Decode (body )
743+ }
744+
738745func (s * SliverHTTPC2 ) getServerPollTimeout () time.Duration {
739746 min := s .ServerConf .LongPollTimeout
740747 max := s .ServerConf .LongPollTimeout + s .ServerConf .LongPollJitter
0 commit comments