# HG changeset patch # User Kim Alvefur # Date 1577861958 -3600 # Node ID 683b06c0348fb21ddd22c278ce8a285df22542bb # Parent d74509cd35fb408fbaa2455545cbdb65aa9a2620 mod_rest: Validate stanza kind earlier diff -r d74509cd35fb -r 683b06c0348f mod_rest/mod_rest.lua --- 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