Skip to content

Commit 6790c0e

Browse files
WeidiDengdunglas
andauthored
fastcgi: check for CONTENT_LENGTH when sending requests (#6661)
* fastcgi: check for CONTENT_LENGTH when sending requests * order imports * use strconv.ParseUint instead of strconv.ParseInt Co-authored-by: Kévin Dunglas <[email protected]> --------- Co-authored-by: Kévin Dunglas <[email protected]>
1 parent c864b82 commit 6790c0e

File tree

1 file changed

+11
-0
lines changed
  • modules/caddyhttp/reverseproxy/fastcgi

1 file changed

+11
-0
lines changed

modules/caddyhttp/reverseproxy/fastcgi/client.go

+11
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ import (
4141

4242
"go.uber.org/zap"
4343
"go.uber.org/zap/zapcore"
44+
45+
"github.com/caddyserver/caddy/v2/modules/caddyhttp"
4446
)
4547

4648
// FCGIListenSockFileno describes listen socket file number.
@@ -136,6 +138,15 @@ type client struct {
136138
// Do made the request and returns a io.Reader that translates the data read
137139
// from fcgi responder out of fcgi packet before returning it.
138140
func (c *client) Do(p map[string]string, req io.Reader) (r io.Reader, err error) {
141+
// check for CONTENT_LENGTH, since the lack of it or wrong value will cause the backend to hang
142+
if clStr, ok := p["CONTENT_LENGTH"]; !ok {
143+
return nil, caddyhttp.Error(http.StatusLengthRequired, nil)
144+
} else if _, err := strconv.ParseUint(clStr, 10, 64); err != nil {
145+
// stdlib won't return a negative Content-Length, but we check just in case,
146+
// the most likely cause is from a missing content length, which is -1
147+
return nil, caddyhttp.Error(http.StatusLengthRequired, err)
148+
}
149+
139150
writer := &streamWriter{c: c}
140151
writer.buf = bufPool.Get().(*bytes.Buffer)
141152
writer.buf.Reset()

0 commit comments

Comments
 (0)