Skip to content

Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.

feat: Adds additional set admin filtering.

damencho6ce0b249dc1b
diff --git a/resources/prosody-plugins/mod_muc_meeting_id.lua b/resources/prosody-plugins/mod_muc_meeting_id.lua
index ebd8fba931..9e5a62e8e9 100644
--- a/resources/prosody-plugins/mod_muc_meeting_id.lua
+++ b/resources/prosody-plugins/mod_muc_meeting_id.lua
@@ -187,6 +187,53 @@ end
module:hook('jicofo-unlock-room', handle_jicofo_unlock);
+-- Prevents some participant from being modified in any way through a
+-- muc#admin set IQ (kick, ban, role/affiliation change, ...). This runs at a high
+-- priority (10) so it precedes prosody's own admin-query handler (default priority
+-- -2) and any other module hooks (e.g. allowners at 5). There is no legitimate
+-- reason for a client/moderator to target certain participants, so any such item is rejected.
+local function filter_admin_set(event)
+ local origin, stanza = event.origin, event.stanza;
+ local room = get_room_from_jid(jid.bare(stanza.attr.to));
+
+ if not room then
+ return;
+ end
+
+ local query = stanza.tags[1];
+ if not query then
+ return;
+ end
+
+ for item in query:childtags('item') do
+ local target_nick;
+
+ if item.attr.nick then
+ -- role changes target the occupant nick
+ target_nick = room.jid .. '/' .. item.attr.nick;
+ elseif item.attr.jid then
+ -- affiliation changes target the real jid, resolve the occupant
+ local target_bare_jid = jid.bare(item.attr.jid);
+ for _, occupant in room:each_occupant() do
+ if occupant.bare_jid == target_bare_jid then
+ target_nick = occupant.nick;
+ break;
+ end
+ end
+ end
+
+ -- block any admin operation on that target
+ if target_nick and is_focus(target_nick) then
+ module:log('warn', 'Blocking attempt to modify %s in room %s', target_nick,room.jid);
+ origin.send(st.error_reply(stanza, 'cancel', 'not-allowed'));
+ return true;
+ end
+ end
+end
+
+module:hook('iq-set/bare/http://jabber.org/protocol/muc#admin:query', filter_admin_set, 10);
+module:hook('iq-set/host/http://jabber.org/protocol/muc#admin:query', filter_admin_set, 10);
+
-- make sure we remove nick if someone is sending it with a message to protect
-- forgery of display name
module:hook("muc-occupant-groupchat", function(event)
diff --git a/tests/prosody/helpers/xmpp_client.js b/tests/prosody/helpers/xmpp_client.js
index a0c6a3e013..3e6e78b875 100644
--- a/tests/prosody/helpers/xmpp_client.js
+++ b/tests/prosody/helpers/xmpp_client.js
@@ -532,6 +532,33 @@ export async function createXmppClient({ host = 'localhost', domain, params, use
);
},
+ /**
+ * Sends a muc#admin set IQ carrying a single <item> with the given
+ * attributes and resolves with the server's IQ response. Use to attempt
+ * a kick (role='none'), ban (affiliation='outcast'), or any other
+ * role/affiliation change on an occupant.
+ *
+ * Normally the caller must be a room moderator/owner, but hooks that run
+ * before Prosody's permission check (e.g. the set admin filtering in
+ * mod_muc_meeting_id) may reject the request regardless of privilege.
+ *
+ * @param {string} roomJid e.g. '[email protected]'
+ * @param {object} itemAttrs attributes for the <item>, e.g.
+ * { nick: 'focus', role: 'none' } or
+ * { jid: '[email protected]', affiliation: 'outcast' }
+ */
+ sendMucAdmin(roomJid, itemAttrs) {
+ return sendIq(xmpp, pendingIqs,
+ xml('iq', { type: 'set',
+ to: roomJid,
+ id: `admin-${++_counter}` },
+ xml('query', { xmlns: 'http://jabber.org/protocol/muc#admin' },
+ xml('item', itemAttrs)
+ )
+ )
+ );
+ },
+
/**
* Destroys a MUC room. The client must be the room owner.
* Resolves when the server acknowledges the destroy IQ.
diff --git a/tests/prosody/mod_muc_meeting_id_spec.js b/tests/prosody/mod_muc_meeting_id_spec.js
index 3739a3a00f..441e320cb7 100644
--- a/tests/prosody/mod_muc_meeting_id_spec.js
+++ b/tests/prosody/mod_muc_meeting_id_spec.js
@@ -1,6 +1,7 @@
import assert from 'assert';
import { createTestContext } from './helpers/test_context.js';
+import { getRoomState } from './helpers/test_observer.js';
import { joinWithTranscriber } from './helpers/xmpp_client.js';
import { isAvailablePresence } from './helpers/xmpp_utils.js';
@@ -10,6 +11,21 @@ let _roomCounter = 0;
const room = () => `meeting-id-${++_roomCounter}@${CONFERENCE}`;
const healthRoom = () => `__jicofo-health-check-mid-${++_roomCounter}@${CONFERENCE}`;
+/**
+ * Asserts that an IQ response is a 'cancel'/'not-allowed' error.
+ *
+ * @param {object} iq the IQ stanza returned by sendMucAdmin
+ * @returns {void}
+ */
+function assertNotAllowed(iq) {
+ assert.strictEqual(iq.attrs.type, 'error', 'IQ must be rejected');
+ const error = iq.getChild('error');
+
+ assert.ok(error, 'response must carry an <error>');
+ assert.strictEqual(error.attrs.type, 'cancel');
+ assert.ok(error.getChild('not-allowed'), 'error condition must be not-allowed');
+}
+
describe('mod_muc_meeting_id', () => {
let ctx;
@@ -54,6 +70,93 @@ describe('mod_muc_meeting_id', () => {
// users arrive after the room is unlocked.
});
+ // -------------------------------------------------------------------------
+ // set admin filtering
+ // -------------------------------------------------------------------------
+ //
+ // filter_admin_set in mod_muc_meeting_id intercepts muc#admin set IQs at a
+ // high priority (before Prosody's own handler) and rejects any item that
+ // targets certain occupants — by nick (role changes) or by real JID
+ // (affiliation changes).
+
+ describe('set admin filtering', () => {
+
+ it('a kick (role=none by nick) targeting certain participant is rejected', async () => {
+ const r = room();
+
+ await ctx.connectFocus(r);
+ const attacker = await ctx.connect();
+
+ await attacker.joinRoom(r);
+
+ const resp = await attacker.sendMucAdmin(r, { nick: 'focus',
+ role: 'none' });
+
+ assertNotAllowed(resp);
+
+ const state = await getRoomState(r);
+
+ assert.strictEqual(state.occupant_count, 2, 'must remain in the room after a blocked kick');
+ });
+
+ it('a ban (affiliation=outcast by jid) targeting certain participant is rejected', async () => {
+ const r = room();
+
+ const focus = await ctx.connectFocus(r);
+ const focusBareJid = focus.jid.split('/')[0];
+ const attacker = await ctx.connect();
+
+ await attacker.joinRoom(r);
+
+ const resp = await attacker.sendMucAdmin(r, { jid: focusBareJid,
+ affiliation: 'outcast' });
+
+ assertNotAllowed(resp);
+
+ const state = await getRoomState(r);
+
+ assert.strictEqual(state.occupant_count, 2, 'must remain in the room after a blocked ban');
+ });
+
+ it('a role demotion (role=participant) targeting certain participant is rejected', async () => {
+ const r = room();
+
+ await ctx.connectFocus(r);
+ const attacker = await ctx.connect();
+
+ await attacker.joinRoom(r);
+
+ const resp = await attacker.sendMucAdmin(r, { nick: 'focus',
+ role: 'participant' });
+
+ assertNotAllowed(resp);
+ });
+
+ it('admin operations targeting a non-focus occupant are not blocked by this hook', async () => {
+ const r = room();
+
+ // focus is the room owner, so it is allowed to kick a regular user.
+ // This verifies the filtering is scoped and does not
+ // block legitimate moderation of other participants.
+ const focus = await ctx.connectFocus(r);
+ const user = await ctx.connect();
+
+ await user.joinRoom(r);
+ const { nick } = user;
+
+ const resp = await focus.sendMucAdmin(r, { nick,
+ role: 'none' });
+
+ assert.strictEqual(resp.attrs.type, 'result',
+ 'must be able to kick a regular participant');
+
+ const state = await getRoomState(r);
+
+ assert.strictEqual(state.occupant_count, 1,
+ 'kicked regular user should be gone, only focus remains');
+ });
+ });
+
// -------------------------------------------------------------------------
// transcription filter robustness
// -------------------------------------------------------------------------