From 25135bbd16bd852379f63923bc3edfdc63a3145f Mon Sep 17 00:00:00 2001 From: JC Brand Date: Fri, 2 Oct 2020 16:12:47 +0200 Subject: MUC: Reject probes from non-occupants Also test for self-probes --- plugins/muc/muc.lib.lua | 33 +++++++++++------- spec/scansion/muc_presence_probe.scs | 65 +++++++++++++++++++++++++++++++++++- 2 files changed, 85 insertions(+), 13 deletions(-) diff --git a/plugins/muc/muc.lib.lua b/plugins/muc/muc.lib.lua index 5bbc28f1..d1449af1 100644 --- a/plugins/muc/muc.lib.lua +++ b/plugins/muc/muc.lib.lua @@ -595,6 +595,26 @@ function room_mt:build_unavailable_presence(from_muc_jid, to_jid) return event.stanza; end +function room_mt:respond_to_probe(origin, stanza, probing_occupant) + if probing_occupant == nil then + origin.send(st.error_reply(stanza, "cancel", "not-acceptable", "You are not currently connected to this chat", self.jid)); + return; + end + + local from_muc_jid = stanza.attr.to; + local probed_occupant = self:get_occupant_by_nick(from_muc_jid); + if probed_occupant == nil then + local to_jid = stanza.attr.from; + local pr = self:build_unavailable_presence(from_muc_jid, to_jid); + if pr then + self:route_stanza(pr); + end + return; + end + local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"}); + self:publicise_occupant_status(probed_occupant, x, nil, nil, nil, nil, false, probing_occupant); +end + function room_mt:handle_normal_presence(origin, stanza) local type = stanza.attr.type; @@ -616,18 +636,7 @@ function room_mt:handle_normal_presence(origin, stanza) if orig_occupant == nil then return true; end -- Unavailable from someone not in the room -- dest_occupant = nil elseif type == "probe" then - local occupant = self:get_occupant_by_nick(stanza.attr.to); - if occupant == nil then - local from_muc_jid = stanza.attr.to; - local to_jid = real_jid; - local pr = self:build_unavailable_presence(from_muc_jid, to_jid); - if pr then - self:route_stanza(pr); - end - return true; - end - local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"}); - self:publicise_occupant_status(occupant, x, nil, nil, nil, nil, false, orig_occupant); + self:respond_to_probe(origin, stanza, orig_occupant) return true; elseif orig_occupant and orig_occupant.nick == stanza.attr.to then -- Just a presence update log("debug", "presence update for %s from session %s", orig_occupant.nick, real_jid); diff --git a/spec/scansion/muc_presence_probe.scs b/spec/scansion/muc_presence_probe.scs index ffd61dba..1fb5d9f5 100644 --- a/spec/scansion/muc_presence_probe.scs +++ b/spec/scansion/muc_presence_probe.scs @@ -16,6 +16,8 @@ Romeo connects +# Romeo joins the MUC + Romeo sends: @@ -52,9 +54,52 @@ Romeo receives: -# Juliet connects, and joins the room +# Romeo probes himself + +Romeo sends: + + + + +Romeo receives: + + + + + + +# Juliet tries to probe Romeo before joining the room + Juliet connects +Juliet sends: + + + + +Juliet receives: + + + + + + +# Juliet tries to probe Mercutio (who's not in the MUC) before joining the room + +Juliet sends: + + + + +Juliet receives: + + + + + + +# Juliet joins the room + Juliet sends: @@ -80,6 +125,24 @@ Romeo receives: + +# Mercutio tries to probe himself in a MUC before joining + +Mercutio connects + +Mercutio sends: + + + + +Mercutio receives: + + + + + + + # Romeo makes Mercutio a member and registers his nickname Romeo sends: -- cgit v1.2.3