Commit Graph
5 Commits
  • fix(panel-proxy): route custom geo and http(s) Telegram through panelProxy
    Custom geosite/geoip downloads built their own ssrfSafeTransport and never used the configured Panel Network Proxy, so geo updates failed on servers where GitHub is filtered. Route all custom-geo HTTP (startup probes + downloads) through panelProxy when set, falling back to the direct SSRF-guarded transport otherwise; the target URL stays SSRF-validated.
    
    The Telegram bot only honored a socks5:// panel proxy and silently rejected http(s)://, despite the setting advertising both. Branch the fasthttp dialer (FasthttpHTTPDialer for http(s), FasthttpSocksDialer for socks5) and accept all three schemes in the fallback and NewBot validation.
    
    Add tests proving the panel proxy is used by custom geo and that the bot dialer speaks HTTP CONNECT vs SOCKS5 per scheme.
  • 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.
  • v3
  • Add SSRF protection (#4044)
    * Add SSRF protection for custom geo downloads
    
    Introduce SSRF-safe HTTP transport for custom geo operations by adding ssrfSafeTransport and isBlockedIP helpers. The transport resolves hosts and blocks loopback, private, link-local and unspecified addresses, returning ErrCustomGeoSSRFBlocked on violations. Update probeCustomGeoURLWithGET, probeCustomGeoURL and downloadToPathOnce to use the safe transport. Also add the new error ErrCustomGeoSSRFBlocked and necessary imports. Minor whitespace/formatting adjustments in subClashService.go, web/entity/entity.go and web/service/setting.go.
    
    * Add path traversal protection for custom geo
    
    Prevent path traversal when handling custom geo downloads by adding ErrCustomGeoPathTraversal and a validateDestPath() helper that ensures destination paths stay inside the bin folder. Call validateDestPath from downloadToPathOnce, Update and Delete paths and wrap errors appropriately. Reconstruct sanitized URLs in sanitizeURL to break taint propagation before use. Map the new path-traversal error to a user-facing i18n message in the controller.
    
    * fix
  • Add custom geosite/geoip URL sources (#3980)
    * feat: add custom geosite/geoip URL sources
    
    Register DB model, panel API, index/xray UI, and i18n.
    
    * fix