mtg icon indicating copy to clipboard operation
mtg copied to clipboard

Public IP detection depends on a single hardcoded endpoint (ifconfig.co)

Open dolonet opened this issue 6 months ago • 1 comments

Problem

getIP in internal/cli/utils.go detects the server's public IP by querying a single hardcoded endpoint:

req, err := http.NewRequest(http.MethodGet, "https://ifconfig.co", nil)

This is used by mtg access (to print proxy links) and by the SNI-DNS check in mtg doctor / proxy startup. If ifconfig.co is down, rate-limiting, or blocked from the server's network, detection silently returns nil — mtg access then can't render links, and the SNI-DNS check reports "cannot detect public IP address" even though the server is perfectly fine.

public-ipv4 / public-ipv6 in config are the manual escape hatch, but most users never set them, so a single third-party endpoint is effectively a single point of failure for two user-facing features.

Options

  1. Hardcoded fallback chain — try ifconfig.co, then e.g. icanhazip.com, ifconfig.me, first success wins. No config surface, no new docs, just resilience. ~15 lines.
  2. Configurable list — add network.public-ip-endpoints so operators can point at their own endpoint (useful in restricted networks or for those who don't want to depend on third parties at all). More flexible, but it's new config surface.

I have working code for both (it was bundled into the now-closed #474). I'd rather not ship config surface you didn't ask for, so: do you want (1), (2), or neither? If (1), I'll send a small PR; if (2), I'll send it with the config option + docs.

dolonet avatar May 20 '26 17:05 dolonet

To be honest, i'm not sure that it worth to overcomplexify it. Let's have a list of such endpoints, 2-3 maybe, and that's all

9seconds avatar May 26 '26 09:05 9seconds