From 5c03f548d50db0ca6449b5d67d29d85f75eab7a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Fri, 27 Nov 2026 21:14:55 +0800 Subject: [PATCH] Limit HTTP request header size in HTTP and mixed inbounds --- go.mod | 2 +- go.sum | 4 ++-- protocol/http/inbound.go | 3 +-- protocol/mixed/inbound.go | 5 ++--- 4 files changed, 6 insertions(+), 8 deletions(-) diff --git a/go.mod b/go.mod index 46d0ab6b..0e2f2c85 100644 --- a/go.mod +++ b/go.mod @@ -45,7 +45,7 @@ require ( github.com/sagernet/netlink v0.0.0-20261125120807-b006b90aa077 github.com/sagernet/nftables v0.3.0-mod.4.0.20261114074246-0b310c3e010b github.com/sagernet/quic-go v0.61.0-sing-box-mod.15 - github.com/sagernet/sing v0.9.7-0.20261125120655-610c8699131b + github.com/sagernet/sing v0.9.7-0.20261127131305-db09250ecaed github.com/sagernet/sing-cloudflared v0.1.4-0.20261125132439-71e2e5ed8ed0 github.com/sagernet/sing-mux v0.3.10-0.20261125130604-6c5b46f55eeb github.com/sagernet/sing-openconnect v0.1.1-0.20261126032024-f641df2c35c6 diff --git a/go.sum b/go.sum index e694826a..0e354e63 100644 --- a/go.sum +++ b/go.sum @@ -318,8 +318,8 @@ github.com/sagernet/nftables v0.3.0-mod.4.0.20261114074246-0b310c3e010b h1:dgnXJ github.com/sagernet/nftables v0.3.0-mod.4.0.20261114074246-0b310c3e010b/go.mod h1:8kslHG4VvYNihcco+i6uxIX7qbT8A56T0y5q7U44ZaQ= github.com/sagernet/quic-go v0.61.0-sing-box-mod.15 h1:bBw8CvMTBPw5kwJiF8dqZRUgJaJFnDkQxRxXv78mlEM= github.com/sagernet/quic-go v0.61.0-sing-box-mod.15/go.mod h1:hmLC8GJPp+BrpBgrgJnacvI4fZGIhasuy1ROJJ8GR4E= -github.com/sagernet/sing v0.9.7-0.20261125120655-610c8699131b h1:MRuIq4f+ode18cs5UqZLXL+4Di3WxjA/l8ehLFHf76M= -github.com/sagernet/sing v0.9.7-0.20261125120655-610c8699131b/go.mod h1:K3Owt3xPhHugvlnlPPxZJ/exXdaJfEPOTNorGk4AXjo= +github.com/sagernet/sing v0.9.7-0.20261127131305-db09250ecaed h1:gqJ4tOSPOhEwSU7hPrjojkLjAIJGS4FUMmsvcJb51JU= +github.com/sagernet/sing v0.9.7-0.20261127131305-db09250ecaed/go.mod h1:K3Owt3xPhHugvlnlPPxZJ/exXdaJfEPOTNorGk4AXjo= github.com/sagernet/sing-cloudflared v0.1.4-0.20261125132439-71e2e5ed8ed0 h1:xGM1kyl4+0Tq2AIjGgKjRROd+Nwb4RGYA4UbyEg5Pq4= github.com/sagernet/sing-cloudflared v0.1.4-0.20261125132439-71e2e5ed8ed0/go.mod h1:XEqEDYRCAYLaoPjZ1ifVWJg5iWAJHL2gOAXe/PM28Cg= github.com/sagernet/sing-mux v0.3.10-0.20261125130604-6c5b46f55eeb h1:iK0uoxfzEEDhez9zXj/Pvu4zEqAwNFzc6nAZzdaaC1Q= diff --git a/protocol/http/inbound.go b/protocol/http/inbound.go index 898d5e1a..5d1c6e57 100644 --- a/protocol/http/inbound.go +++ b/protocol/http/inbound.go @@ -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 { diff --git a/protocol/mixed/inbound.go b/protocol/mixed/inbound.go index 4810107e..a0adcc2c 100644 --- a/protocol/mixed/inbound.go +++ b/protocol/mixed/inbound.go @@ -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)