From b0dec83aada2326d5eb04a643b041303ac732983 Mon Sep 17 00:00:00 2001 From: ed Date: Sun, 27 Jul 2025 20:32:45 +0000 Subject: [PATCH] connect: fix ipv6 and resolve .local only; closes #202 --- copyparty/httpcli.py | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 9b43225b..9d12facb 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -4873,24 +4873,21 @@ class HttpCli(object): def tx_svcs(self) -> bool: aname = re.sub("[^0-9a-zA-Z]+", "", self.args.vname) or "a" ep = self.host - host = ep.split(":")[0] - hport = ep[ep.find(":") :] if ":" in ep else "" - - import ipaddress - try: - ipaddress.ip_address(host) - user_used_ip = True - except ValueError: - user_used_ip = False - - if user_used_ip or self.args.rclone_mdns or not self.args.zm: - rip = ( - host - if self.args.rclone_mdns or not self.args.zm - else self.conn.hsrv.nm.map(self.ip) or host - ) + sep = "]:" if "]" in ep else ":" + if sep in ep: + host, hport = ep.rsplit(":", 1) + hport = ":" + hport + else: + host = ep + hport = "" + + if host.endswith(".local") and self.args.zm and not self.args.rclone_mdns: + rip = self.conn.hsrv.nm.map(self.ip) or host + if ":" in rip and "[" not in rip: + rip = "[%s]" % (rip,) else: rip = host + # safer than html_escape/quotep since this avoids both XSS and shell-stuff pw = re.sub(r"[<>&$?`\"']", "_", self.pw or "hunter2") vp = re.sub(r"[<>&$?`\"']", "_", self.uparam["hc"] or "").lstrip("/")