Limit HTTP request header size in HTTP and mixed inbounds

This commit is contained in:
世界
2026-11-27 21:18:25 +08:00
parent 593b9b2e6b
commit 5c03f548d5
4 changed files with 6 additions and 8 deletions
+1 -2
View File
@@ -1,7 +1,6 @@
package http
import (
std_bufio "bufio"
"context"
"net"
@@ -95,7 +94,7 @@ func (h *Inbound) NewConnection(ctx context.Context, conn net.Conn, metadata ada
}
conn = tlsConn
}
err := http.HandleConnectionEx(ctx, conn, std_bufio.NewReader(conn), h.authenticator, adapter.NewUpstreamHandler(metadata, h.newUserConnection, h.streamUserPacketConnection), metadata.Source, onClose)
err := http.HandleConnectionEx(ctx, conn, http.NewReader(conn), h.authenticator, adapter.NewUpstreamHandler(metadata, h.newUserConnection, h.streamUserPacketConnection), metadata.Source, onClose)
if err != nil {
conn.Close()
if onClose != nil {
+2 -3
View File
@@ -1,7 +1,6 @@
package mixed
import (
std_bufio "bufio"
"context"
"net"
"time"
@@ -119,7 +118,7 @@ func (h *Inbound) newConnection(ctx context.Context, conn net.Conn, metadata ada
}
conn = tlsConn
}
reader := std_bufio.NewReader(conn)
reader := http.NewReader(conn)
headerBytes, err := reader.Peek(1)
if err != nil {
err = E.Cause(err, "peek first byte")
@@ -128,7 +127,7 @@ func (h *Inbound) newConnection(ctx context.Context, conn net.Conn, metadata ada
}
switch headerBytes[0] {
case socks4.Version, socks5.Version:
err = socks.HandleConnectionEx(ctx, conn, reader, h.authenticator, adapter.NewUpstreamHandler(metadata, h.newUserConnection, h.streamUserPacketConnection), h.listener, h.udpTimeout, metadata.Source, onClose)
err = socks.HandleConnectionEx(ctx, conn, reader.Reader, h.authenticator, adapter.NewUpstreamHandler(metadata, h.newUserConnection, h.streamUserPacketConnection), h.listener, h.udpTimeout, metadata.Source, onClose)
N.CloseOnHandshakeFailure(conn, onClose, err)
default:
err = http.HandleConnectionEx(ctx, conn, reader, h.authenticator, adapter.NewUpstreamHandler(metadata, h.newUserConnection, h.streamUserPacketConnection), metadata.Source, onClose)