Diff

mod_rest/mod_rest.lua @ 3805:683b06c0348f

mod_rest: Validate stanza kind earlier
author Kim Alvefur <zash@zash.se>
date Wed, 01 Jan 2020 07:59:18 +0100
parent 3804:d74509cd35fb
child 3806:c0caee8f54bb
line wrap: on
line diff
--- a/mod_rest/mod_rest.lua	Wed Jan 01 07:55:48 2020 +0100
+++ b/mod_rest/mod_rest.lua	Wed Jan 01 07:59:18 2020 +0100
@@ -40,6 +40,8 @@
 	end
 	if payload.attr.xmlns then
 		return errors.new({ code = 422, text = "'xmlns' attribute must be empty" });
+	elseif payload.name ~= "message" and payload.name ~= "presence" and payload.name ~= "iq" then
+		return errors.new({ code = 422, text = "Invalid stanza, must be 'message', 'presence' or 'iq'." });
 	end
 	local to = jid.prep(payload.attr.to);
 	if not to then
@@ -82,7 +84,7 @@
 					return error;
 				end
 			end);
-	elseif payload.name == "message" or payload.name == "presence" then
+	else
 		local origin = {};
 		function origin.send(stanza)
 			module:log("debug", "Sending[rest]: %s", stanza:top_tag());
@@ -95,8 +97,6 @@
 		else
 			return 500;
 		end
-	else
-		return errors.new({ code = 400, text = "Invalid stanza, must be 'message', 'presence' or 'iq'." });
 	end
 end