Files
CLIProxyAPI/internal/api/buffered_conn.go
Luis Pater 477605dc6d fix(api): prevent incomplete unauthenticated request bodies from exhausting descriptors
Defer eager request body reads and temporary file creation until after authentication or over the 1 MiB in-memory threshold, expire read deadlines and close connections when responses finish with unconsumed request bodies, bound HTTP header and unauthenticated RESP setup reads, and retry transient EMFILE/ENFILE accept errors with exponential backoff.

Fixes GHSA-j4xx-x47j-7h54
2026-10-27 23:11:21 +08:00

43 lines
769 B
Go

package api
import (
"bufio"
"crypto/tls"
"net"
)
type bufferedConn struct {
net.Conn
reader *bufio.Reader
}
func (c *bufferedConn) Read(p []byte) (int, error) {
if c == nil {
return 0, net.ErrClosed
}
if c.reader == nil {
return c.Conn.Read(p)
}
return c.reader.Read(p)
}
func (c *bufferedConn) ConnectionState() tls.ConnectionState {
if c == nil || c.Conn == nil {
return tls.ConnectionState{}
}
if stater, ok := c.Conn.(interface{ ConnectionState() tls.ConnectionState }); ok {
return stater.ConnectionState()
}
return tls.ConnectionState{}
}
func (c *bufferedConn) CloseWrite() error {
if c == nil || c.Conn == nil {
return nil
}
if cw, ok := c.Conn.(interface{ CloseWrite() error }); ok {
return cw.CloseWrite()
}
return nil
}