stanza_router: Bounce stanzas to/from invalid JIDs with a jid-malformed error

Wed, 13 May 2009 16:54:46 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Wed, 13 May 2009 16:54:46 +0100
changeset 1143
5bab3eb566ad
parent 1130
442c87de8e2d
child 1144
fbd65e966316
child 1186
078eb3b109e9

stanza_router: Bounce stanzas to/from invalid JIDs with a jid-malformed error

core/stanza_router.lua file | annotate | diff | comparison | revisions
--- a/core/stanza_router.lua	Wed May 06 21:45:02 2009 +0100
+++ b/core/stanza_router.lua	Wed May 13 16:54:46 2009 +0100
@@ -77,16 +77,21 @@
 	if to then
 		node, host, resource = jid_prepped_split(to);
 		if not host then
-			error("Invalid to JID");
+			log("warn", "Received stanza with invalid destination JID: %s", to);
+			origin.send(st.error_reply(stanza, "modify", "jid-malformed", "The destination address is invalid: "..to));
+			return;
 		end
 		to_bare = node and (node.."@"..host) or host; -- bare JID
 		if resource then to = to_bare.."/"..resource; else to = to_bare; end
 		stanza.attr.to = to;
 	end
 	if from then
+		-- We only stamp the 'from' on c2s stanzas, so we still need to check validity
 		from_node, from_host, from_resource = jid_prepped_split(from);
 		if not from_host then
-			error("Invalid from JID");
+			log("warn", "Received stanza with invalid source JID: %s", from);
+			origin.send(st.error_reply(stanza, "modify", "jid-malformed", "The source address is invalid: "..from));
+			return;
 		end
 		from_bare = from_node and (from_node.."@"..from_host) or from_host; -- bare JID
 		if from_resource then from = from_bare.."/"..from_resource; else from = from_bare; end

mercurial