3x-ui/util
MHSanaei 38da210ded
fix(security): SSRF-guard node and remote HTTP clients
The Node.Probe and Remote.do paths built outbound URLs by string-
formatting admin-controlled fields (Scheme/Address/Port/BasePath)
straight into requests, then dialed the result with the default
transport. CodeQL flagged this as go/request-forgery — an admin
(or anyone who compromises the admin account) could point a node
at internal infrastructure (cloud metadata, RFC1918 ranges, etc.)
and the panel would dutifully fetch it.

Add util/netsafe with a shared TOCTOU-safe DialContext that
resolves the host, rejects private/internal IPs unless the
per-request context whitelists them (per-node AllowPrivateAddress
flag, plumbed through context.Value), and dials the resolved IP
directly so the IP that passed the check is the IP we connect to.
This closes the DNS-rebinding window where a hostname could
resolve to a public IP at check time and a private one at dial.

Also tighten address validation (NormalizeHost rejects anything
that isn't a bare hostname or IP literal — no embedded paths,
userinfo, schemes) and switch URL construction from fmt.Sprintf to
url.URL{} + net.JoinHostPort so admin-supplied values can't smuggle
URL components.

custom_geo.go's isBlockedIP now delegates to netsafe so there's
one source of truth.
2026-05-13 13:33:53 +02:00
..
common v3 2026-05-10 02:13:42 +02:00
crypto Refactor code and fix linter warnings (#3627) 2026-01-05 05:54:56 +01:00
json_util docs: add comments for all functions 2025-09-20 09:35:50 +02:00
ldap Refactor code and fix linter warnings (#3627) 2026-01-05 05:54:56 +01:00
netsafe fix(security): SSRF-guard node and remote HTTP clients 2026-05-13 13:33:53 +02:00
random Refactor code and fix linter warnings (#3627) 2026-01-05 05:54:56 +01:00
reflect_util Refactor code and fix linter warnings (#3627) 2026-01-05 05:54:56 +01:00
sys fix windows build 2026-02-20 02:07:46 +01:00