Software /
code /
prosody
Comparison
plugins/muc/muc.lib.lua @ 11246:ab189e707705
MUC: Reject probes from non-occupants
Also test for self-probes
author | JC Brand <jc@opkode.com> |
---|---|
date | Fri, 02 Oct 2020 16:12:47 +0200 |
parent | 11245:43b43e7156b8 |
child | 11498:d61ec5e6ee16 |
comparison
equal
deleted
inserted
replaced
11245:43b43e7156b8 | 11246:ab189e707705 |
---|---|
593 } | 593 } |
594 module:fire_event("muc-build-occupant-presence", event); | 594 module:fire_event("muc-build-occupant-presence", event); |
595 return event.stanza; | 595 return event.stanza; |
596 end | 596 end |
597 | 597 |
598 function room_mt:respond_to_probe(origin, stanza, probing_occupant) | |
599 if probing_occupant == nil then | |
600 origin.send(st.error_reply(stanza, "cancel", "not-acceptable", "You are not currently connected to this chat", self.jid)); | |
601 return; | |
602 end | |
603 | |
604 local from_muc_jid = stanza.attr.to; | |
605 local probed_occupant = self:get_occupant_by_nick(from_muc_jid); | |
606 if probed_occupant == nil then | |
607 local to_jid = stanza.attr.from; | |
608 local pr = self:build_unavailable_presence(from_muc_jid, to_jid); | |
609 if pr then | |
610 self:route_stanza(pr); | |
611 end | |
612 return; | |
613 end | |
614 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"}); | |
615 self:publicise_occupant_status(probed_occupant, x, nil, nil, nil, nil, false, probing_occupant); | |
616 end | |
617 | |
598 | 618 |
599 function room_mt:handle_normal_presence(origin, stanza) | 619 function room_mt:handle_normal_presence(origin, stanza) |
600 local type = stanza.attr.type; | 620 local type = stanza.attr.type; |
601 local real_jid = stanza.attr.from; | 621 local real_jid = stanza.attr.from; |
602 local bare_jid = jid_bare(real_jid); | 622 local bare_jid = jid_bare(real_jid); |
614 local dest_occupant; | 634 local dest_occupant; |
615 if type == "unavailable" then | 635 if type == "unavailable" then |
616 if orig_occupant == nil then return true; end -- Unavailable from someone not in the room | 636 if orig_occupant == nil then return true; end -- Unavailable from someone not in the room |
617 -- dest_occupant = nil | 637 -- dest_occupant = nil |
618 elseif type == "probe" then | 638 elseif type == "probe" then |
619 local occupant = self:get_occupant_by_nick(stanza.attr.to); | 639 self:respond_to_probe(origin, stanza, orig_occupant) |
620 if occupant == nil then | |
621 local from_muc_jid = stanza.attr.to; | |
622 local to_jid = real_jid; | |
623 local pr = self:build_unavailable_presence(from_muc_jid, to_jid); | |
624 if pr then | |
625 self:route_stanza(pr); | |
626 end | |
627 return true; | |
628 end | |
629 local x = st.stanza("x", {xmlns = "http://jabber.org/protocol/muc#user"}); | |
630 self:publicise_occupant_status(occupant, x, nil, nil, nil, nil, false, orig_occupant); | |
631 return true; | 640 return true; |
632 elseif orig_occupant and orig_occupant.nick == stanza.attr.to then -- Just a presence update | 641 elseif orig_occupant and orig_occupant.nick == stanza.attr.to then -- Just a presence update |
633 log("debug", "presence update for %s from session %s", orig_occupant.nick, real_jid); | 642 log("debug", "presence update for %s from session %s", orig_occupant.nick, real_jid); |
634 dest_occupant = orig_occupant; | 643 dest_occupant = orig_occupant; |
635 else | 644 else |