The UDP relay treated the destination address as packet-scoped while
applying ACL/outbound policy only once when a new session was created.
After an authenticated client opened a UDP session using a permitted
first destination, later packets carrying a different Addr in the same
SessionID were written via the established outbound socket without
re-checking policy, allowing the client to reach destinations that ACL
should reject — including localhost and RFC1918 from the server's
network perspective. See GHSA-vgrc-hq28-p3xp.
Add a no-I/O CheckUDP method to the Outbound / PluggableOutbound
chain. The UDP session entry now consults CheckUDP for every packet
whose destination differs from the session's first one, dropping
rejected packets before WriteTo. Decisions are cached per destination
within the session (bounded at 256 entries with simple eviction) so
steady-state cost is one map lookup per packet and no extra sockets
or dials. CheckUDP propagates through the existing chain:
- aclEngine routes through the matched outbound's CheckUDP, with
aclRejectOutbound returning the rejection error.
- directOutbound / socks5Outbound / speedtestHandler return nil.
- httpOutbound returns errHTTPUDPNotSupported.
- Resolvers (system / dot / doh) run resolve() then forward to
Next.CheckUDP so IP-based ACL rules keep matching.
Regression tests in core/internal/integration_tests/udp_acl_test.go
use an in-package stub Outbound to assert that a rejected destination
is not relayed after the session is opened on a permitted one, and
that multi-destination sessions over permitted addresses still work.
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
40 lines
896 B
Go
40 lines
896 B
Go
package outbounds
|
|
|
|
import (
|
|
"net"
|
|
|
|
"github.com/apernet/hysteria/extras/v2/outbounds/speedtest"
|
|
)
|
|
|
|
const (
|
|
SpeedtestDest = "@SpeedTest"
|
|
)
|
|
|
|
// speedtestHandler is a PluggableOutbound that handles speed test requests.
|
|
// It's used to intercept speed test requests and return a pseudo connection that
|
|
// implements the speed test protocol.
|
|
type speedtestHandler struct {
|
|
Next PluggableOutbound
|
|
}
|
|
|
|
func NewSpeedtestHandler(next PluggableOutbound) PluggableOutbound {
|
|
return &speedtestHandler{
|
|
Next: next,
|
|
}
|
|
}
|
|
|
|
func (s *speedtestHandler) TCP(reqAddr *AddrEx) (net.Conn, error) {
|
|
if reqAddr.Host == SpeedtestDest {
|
|
return speedtest.NewServerConn(), nil
|
|
} else {
|
|
return s.Next.TCP(reqAddr)
|
|
}
|
|
}
|
|
|
|
func (s *speedtestHandler) UDP(reqAddr *AddrEx) (UDPConn, error) {
|
|
return s.Next.UDP(reqAddr)
|
|
}
|
|
|
|
func (s *speedtestHandler) CheckUDP(reqAddr *AddrEx) error {
|
|
return s.Next.CheckUDP(reqAddr)
|
|
}
|