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 -1
View File
@@ -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
+2 -2
View File
@@ -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=
+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)