Changeset

13465:54a936345aaa 0.12

prosodyctl check: Warn about invalid domain names in the config file This ensures that domain names of virtual hosts and components are valid in XMPP, and that they are encoded correctly.
author Matthew Wild <mwild1@gmail.com>
date Wed, 27 Mar 2024 15:35:15 +0000
parents 13445:360e05f33835
children 13466:5d9ec2e55d74 13470:19a9ec94f575
files util/prosodyctl/check.lua
diffstat 1 files changed, 51 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/util/prosodyctl/check.lua	Tue Feb 27 17:14:16 2024 +0100
+++ b/util/prosodyctl/check.lua	Wed Mar 27 15:35:15 2024 +0000
@@ -738,6 +738,57 @@
 			end
 		end
 
+		-- Check hostname validity
+		do
+			local idna = require "util.encodings".idna;
+			local invalid_hosts = {};
+			local alabel_hosts = {};
+			for host in it.filter("*", pairs(configmanager.getconfig())) do
+				local _, h, _ = jid_split(host);
+				if not h or not idna.to_ascii(h) then
+					table.insert(invalid_hosts, host);
+				else
+					for label in h:gmatch("[^%.]+") do
+						if label:match("^xn%-%-") then
+							table.insert(alabel_hosts, host);
+							break;
+						end
+					end
+				end
+			end
+
+			if #invalid_hosts > 0 then
+				table.sort(invalid_hosts);
+				print("");
+				print("    Your configuration contains invalid host names:");
+				print("        "..table.concat(invalid_hosts, "\n        "));
+				print("");
+				print("    Clients may not be able to log in to these hosts, or you may not be able to");
+				print("    communicate with remote servers.");
+				print("    Use a valid domain name to correct this issue.");
+			end
+
+			if #alabel_hosts > 0 then
+				table.sort(alabel_hosts);
+				print("");
+				print("    Your configuration contains incorrectly-encoded hostnames:");
+				for _, ahost in ipairs(alabel_hosts) do
+					print(("        '%s' (should be '%s')"):format(ahost, idna.to_unicode(ahost)));
+				end
+				print("");
+				print("    Clients may not be able to log in to these hosts, or you may not be able to");
+				print("    communicate with remote servers.");
+				print("    To correct this issue, use the Unicode version of the domain in Prosody's config file.");
+			end
+
+			if #invalid_hosts > 0 or #alabel_hosts > 0 then
+				print("");
+				print("WARNING: Changing the name of a VirtualHost in Prosody's config file");
+				print("         WILL NOT migrate any existing data (user accounts, etc.) to the new name.");
+				ok = false;
+			end
+		end
+
 		print("Done.\n");
 	end
 	if not what or what == "dns" then