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(prosody): reject reserved MUC resources in muc_resource_validate (#18161)

Дамян Минковb3b5ee8b567b
diff --git a/resources/prosody-plugins/mod_muc_resource_validate.lua b/resources/prosody-plugins/mod_muc_resource_validate.lua
index cafaa3d0b6..771b824346 100644
--- a/resources/prosody-plugins/mod_muc_resource_validate.lua
+++ b/resources/prosody-plugins/mod_muc_resource_validate.lua
@@ -6,6 +6,15 @@
-- A valid resource consists only of alphanumerics and underscores and must
-- NOT start with an underscore: ^[a-zA-Z0-9][a-zA-Z0-9_]*$
--
+-- Resources listed in "reserved_resources" are rejected for every occupant of
+-- the MUC components the module is enabled on, whether or not anonymous_strict
+-- is on and whatever the occupant's domain. Clients treat these IDs as coming
+-- from server components (e.g. the bridge sends transcriptions as
+-- "transcriber"), so no occupant may use them. The match is exact and
+-- case-sensitive, as the clients' comparison is. The occupant resource becomes
+-- the bridge endpoint ID in breakout rooms too, so enable the module on the
+-- breakout rooms component as well.
+--
-- When "anonymous_strict" mode is enabled, users on domains whose
-- authentication provider is considered anonymous are additionally required
-- to use a MUC resource equal to the first 8 characters of their real JID
@@ -24,8 +33,11 @@
-- modules_enabled = { "muc_resource_validate" }
-- -- Enable strict anonymous-user check
-- anonymous_strict = true
--- -- Optional: extend the list of auth methods treated as anonymous
+-- -- Optional: replace the list of auth methods treated as anonymous
+-- -- (default: { "anonymous", "jitsi-anonymous", "token" })
-- anonymous_auth_methods = { "anonymous", "jitsi-anonymous", "token", "custom-anon" }
+-- -- Optional: replace the list of reserved resources (default: { "transcriber" })
+-- reserved_resources = { "transcriber" }
local jid_split = require "util.jid".split;
local st = require "util.stanza";
@@ -37,11 +49,14 @@ local VALID_RESOURCE_PATTERN = "^[a-zA-Z0-9][a-zA-Z0-9_]*$";
local anonymous_strict;
local anonymous_auth_methods;
+local reserved_resources;
local function load_config()
anonymous_strict = module:get_option_boolean("anonymous_strict", false);
anonymous_auth_methods = module:get_option_set(
"anonymous_auth_methods", { "anonymous", "jitsi-anonymous", "token" });
+
+ reserved_resources = module:get_option_set("reserved_resources", { "transcriber" });
end
load_config();
@@ -79,7 +94,15 @@ local function check_resource(event)
return true;
end
- -- 2. Anonymous strict mode: MUC resource must equal the 8-char UUID prefix of the real JID username.
+ -- 2. Reserved resources: IDs clients attribute to server components.
+ if reserved_resources:contains(muc_resource) then
+ module:log("warn", "Rejecting join with reserved MUC resource from %s (muc_resource: %s)",
+ stanza.attr.from, muc_resource);
+ origin.send(st.error_reply(stanza, "cancel", "not-allowed", "Reserved resource"));
+ return true;
+ end
+
+ -- 3. Anonymous strict mode: MUC resource must equal the 8-char UUID prefix of the real JID username.
if anonymous_strict and is_anonymous_domain(domain) then
local uuid_prefix = user:sub(1, 8);
if muc_resource ~= uuid_prefix then
@@ -119,7 +142,8 @@ local function reject_nick_change(event)
end
end
-module:log("info", "module loaded (anonymous_strict=%s)", tostring(anonymous_strict));
+module:log("info", "module loaded (anonymous_strict=%s, reserved_resources=%s)",
+ tostring(anonymous_strict), tostring(reserved_resources));
module:hook("muc-occupant-pre-join", check_resource, 11);
module:hook("muc-occupant-pre-change", reject_nick_change, 11);
diff --git a/tests/prosody/helpers/xmpp_client.js b/tests/prosody/helpers/xmpp_client.js
index b3be6079bc..e121f9a685 100644
--- a/tests/prosody/helpers/xmpp_client.js
+++ b/tests/prosody/helpers/xmpp_client.js
@@ -26,24 +26,27 @@ export async function joinWithJibri(roomJid) {
}
/**
- * Connects as the transcriber, joins roomJid with nick 'transcriber', and
- * returns the client. Authenticates as [email protected].
+ * Connects as the transcriber, joins roomJid with an 8 hex digit nick (as
+ * Jigasi does; 'transcriber' is a reserved resource), and returns the client.
+ * Authenticates as [email protected].
* The bare JID starts with 'transcriber@recorder.' so is_transcriber() returns
* true, matching the default transcriber_prefixes in util.lib.lua.
*
* The caller is responsible for disconnecting the returned client.
*
* @param {string} roomJid full room JID, e.g. '[email protected]'
+ * @param {object} [opts]
+ * @param {Array} [opts.extensions] presence children, forwarded to joinRoom
* @returns {Promise<XmppTestClient>}
*/
-export async function joinWithTranscriber(roomJid) {
+export async function joinWithTranscriber(roomJid, { extensions } = {}) {
const c = await createXmppClient({
domain: 'recorder.localhost',
username: 'transcriber',
password: 'transcribersecret'
});
- await c.joinRoom(roomJid, 'transcriber');
+ await c.joinRoom(roomJid, 'a1b2c3d4', { extensions });
return c;
}
diff --git a/tests/prosody/mod_filter_iq_rayo_spec.js b/tests/prosody/mod_filter_iq_rayo_spec.js
index a5db34fe86..0766494737 100644
--- a/tests/prosody/mod_filter_iq_rayo_spec.js
+++ b/tests/prosody/mod_filter_iq_rayo_spec.js
@@ -3,7 +3,7 @@ import assert from 'assert';
import http from 'http';
import { mintAsapToken } from './helpers/jwt.js';
-import { createXmppClient, joinWithFocus } from './helpers/xmpp_client.js';
+import { createXmppClient, joinWithFocus, joinWithTranscriber } from './helpers/xmpp_client.js';
let _roomCounter = 0;
const nextRoom = () => `rayo-test-${++_roomCounter}@conference.localhost`;
@@ -317,21 +317,14 @@ describe('mod_filter_iq_rayo (feature-based authorization)', () => {
* @param {string} userId
*/
async function joinAsTranscriberStartedBy(roomJid, userId) {
- const c = await createXmppClient({
- domain: 'recorder.localhost',
- username: 'transcriber',
- password: 'transcribersecret'
- });
-
- clients.push(c);
-
const initiator = xml('initiator', { xmlns: 'http://jitsi.org/protocol/jigasi' },
xml('header', { xmlns: 'urn:xmpp:rayo:1',
name: 'X-outbound-call-initiator-user',
value: userId })
);
+ const c = await joinWithTranscriber(roomJid, { extensions: [ initiator ] });
- await c.joinRoom(roomJid, 'transcriber', { extensions: [ initiator ] });
+ clients.push(c);
return c;
}
diff --git a/tests/prosody/mod_muc_resource_validate_spec.js b/tests/prosody/mod_muc_resource_validate_spec.js
index 52ade03648..863dde63ea 100644
--- a/tests/prosody/mod_muc_resource_validate_spec.js
+++ b/tests/prosody/mod_muc_resource_validate_spec.js
@@ -34,6 +34,21 @@ async function setStrictMode(enabled) {
await new Promise(resolve => setTimeout(resolve, 500));
}
+/**
+ * Asserts that a join was rejected by the reserved-resource check, which
+ * (unlike the format and strict-mode checks) says "Reserved resource".
+ *
+ * @param {Element} presence
+ */
+function assertReservedRejection(presence) {
+ assert.equal(presence.attrs.type, 'error', 'reserved resource must be rejected');
+
+ const error = presence.getChild('error');
+
+ assert.ok(error?.getChild('not-allowed'), 'error stanza must contain <not-allowed/>');
+ assert.equal(error.getChildText('text'), 'Reserved resource', 'rejection must come from the reserved check');
+}
+
describe('mod_muc_resource_validate', () => {
let ctx;
@@ -115,6 +130,79 @@ describe('mod_muc_resource_validate', () => {
);
});
+ // ── Reserved resources ────────────────────────────────────────────────────
+ //
+ // Reserved resources must be rejected even when anonymous_strict is off, so
+ // these tests disable strict mode to make sure the reserved check alone
+ // rejects them.
+
+ it('rejects the reserved transcriber resource', async () => {
+ const r = room();
+
+ await ctx.connectFocus(r);
+ await setStrictMode(false);
+ try {
+ const c = await ctx.connect();
+ const presence = await c.joinRoom(r, 'transcriber');
+
+ assertReservedRejection(presence);
+ } finally {
+ await setStrictMode(true);
+ }
+ });
+
+ // Backend accounts (here the transcriber's, on recorder.localhost) are not
+ // anonymous, so strict mode does not apply to them; the reserved check must
+ // still reject the resource.
+ it('rejects the reserved transcriber resource for the transcriber account', async () => {
+ const r = room();
+
+ await ctx.connectFocus(r);
+ const c = await ctx.connect({
+ domain: 'recorder.localhost',
+ username: 'transcriber',
+ password: 'transcribersecret'
+ });
+ const presence = await c.joinRoom(r, 'transcriber');
+
+ assertReservedRejection(presence);
+ });
+
+ // Jigasi with org.jitsi.jigasi.USE_SIP_USER_AS_XMPP_RESOURCE joins its
+ // transcriber as "Transcriber" (its display name); the exact match must
+ // let it in.
+ it('allows a reserved resource in a different case', async () => {
+ const r = room();
+
+ await ctx.connectFocus(r);
+ await setStrictMode(false);
+ try {
+ const c = await ctx.connect();
+ const presence = await c.joinRoom(r, 'Transcriber');
+
+ assert.ok(isAvailablePresence(presence),
+ 'reserved resource in a different case must be allowed');
+ } finally {
+ await setStrictMode(true);
+ }
+ });
+
+ it('allows a resource that only starts with a reserved one', async () => {
+ const r = room();
+
+ await ctx.connectFocus(r);
+ await setStrictMode(false);
+ try {
+ const c = await ctx.connect();
+ const presence = await c.joinRoom(r, 'transcriber2');
+
+ assert.ok(isAvailablePresence(presence),
+ 'resource that only starts with a reserved one must be allowed');
+ } finally {
+ await setStrictMode(true);
+ }
+ });
+
// ── Anonymous strict mode ─────────────────────────────────────────────────
//
// anonymous_strict = true is the default in the test config, so no toggle