Changeset

9741:d46c376dfe2c

mod_admin_telnet: Validate hostnames in xmpp:ping command Attempt to ping some invalid hostnames cause weird behavior
author Kim Alvefur <zash@zash.se>
date Sat, 29 Dec 2018 03:21:13 +0100
parents 9740:4b34687ede3f
children 9743:73e8668321e9
files plugins/mod_admin_telnet.lua
diffstat 1 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_admin_telnet.lua	Fri Dec 28 00:04:26 2018 +0100
+++ b/plugins/mod_admin_telnet.lua	Sat Dec 29 03:21:13 2018 +0100
@@ -1088,8 +1088,17 @@
 local st = require "util.stanza";
 local new_id = require "util.id".medium;
 function def_env.xmpp:ping(localhost, remotehost, timeout)
-	if not prosody.hosts[localhost] then
-		return nil, "No such host";
+	localhost = select(2, jid_split(localhost));
+	remotehost = select(2, jid_split(remotehost));
+	if not localhost then
+		return nil, "Invalid sender hostname";
+	elseif not prosody.hosts[localhost] then
+		return nil, "No such local host";
+	end
+	if not remotehost then
+		return nil, "Invalid destination hostname";
+	elseif prosody.hosts[remotehost] then
+		return nil, "Both hosts are local";
 	end
 	local iq = st.iq{ from=localhost, to=remotehost, type="get", id=new_id()}
 			:tag("ping", {xmlns="urn:xmpp:ping"});