aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2019-11-25 20:52:03 +0100
committerKim Alvefur <zash@zash.se>2019-11-25 20:52:03 +0100
commit54da2ab6f7fec145d05ac8682c50a776bb993880 (patch)
treeea506547a702c0dd195ef7c2e35289054ba52b79
parent52b7181979bcee9000acf1c90e85934976e4da6a (diff)
downloadprosody-54da2ab6f7fec145d05ac8682c50a776bb993880.tar.gz
prosody-54da2ab6f7fec145d05ac8682c50a776bb993880.zip
util.stanza: Check that argument to error_reply is NOT a stanza of type error
Replying to an error is Very Bad
-rw-r--r--spec/util_stanza_spec.lua10
-rw-r--r--util/stanza.lua2
2 files changed, 12 insertions, 0 deletions
diff --git a/spec/util_stanza_spec.lua b/spec/util_stanza_spec.lua
index 23cdbeb9..04458303 100644
--- a/spec/util_stanza_spec.lua
+++ b/spec/util_stanza_spec.lua
@@ -220,6 +220,16 @@ describe("util.stanza", function()
st.error_reply(not "a stanza", "modify", "bad-request");
end, "expected stanza");
end);
+
+ it("should reject stanzas of type error", function ()
+ assert.has.error_match(function ()
+ st.error_reply(st.message({type="error"}), "cancel", "conflict");
+ end, "got stanza of type error");
+ assert.has.error_match(function ()
+ st.error_reply(st.error_reply(st.message({type="chat"}), "modify", "forbidden"), "cancel", "service-unavailable");
+ end, "got stanza of type error");
+ end);
+
end);
describe("should reject #invalid", function ()
diff --git a/util/stanza.lua b/util/stanza.lua
index 24fd4fea..8ff1aae3 100644
--- a/util/stanza.lua
+++ b/util/stanza.lua
@@ -450,6 +450,8 @@ local xmpp_stanzas_attr = { xmlns = xmlns_stanzas };
local function error_reply(orig, error_type, condition, error_message)
if not is_stanza(orig) then
error("bad argument to error_reply: expected stanza, got "..type(orig));
+ elseif orig.attr.type == "error" then
+ error("bad argument to error_reply: got stanza of type error which must not be replied to");
end
local t = reply(orig);
t.attr.type = "error";