Jitsi Meet - Secure, Simple and Scalable Video Conferences that you use as a standalone app or embed in your web application.
TypeScript debiandeep-videojitsijitsi-meetscalable-video-conferencessfuvideovideo-communicationvideo-conferencingwebrtc
fix(prosody): apply max_number_outgoing_calls to transcription dials (#18011)
bgrozevf4a1c17e45a7
diff --git a/resources/prosody-plugins/mod_filter_iq_rayo.lua b/resources/prosody-plugins/mod_filter_iq_rayo.luaindex 9f2ad3214e..b64810a393 100644--- a/resources/prosody-plugins/mod_filter_iq_rayo.lua+++ b/resources/prosody-plugins/mod_filter_iq_rayo.lua@@ -2,8 +2,9 @@-- on the main VirtualHost. Allows a stanza through only when the sender's JWT token-- grants the required feature ('outbound-call' or 'transcription'), or, absent token-- features, when the sender holds owner affiliation in the room. Blocked stanzas--- receive an auth/forbidden error reply. Optionally rate-limits outgoing calls per--- session when max_number_outgoing_calls is configured.+-- receive an auth/forbidden error reply. When max_number_outgoing_calls is+-- configured, it also limits the dials (outbound calls and transcriptions) that a+-- session sends per minute, and the concurrent Jigasi sessions of a user.-- This module is enabled under the main virtual host.local new_throttle = require "util.throttle".create;local st = require "util.stanza";@@ -53,8 +54,9 @@ if token_util == nil thenreturn;end--- The maximum number of simultaneous calls,--- and also the maximum number of new calls per minute that a session is allowed to create.+-- The maximum number of simultaneous Jigasi sessions (outbound calls and transcriptions)+-- of a user, and also the maximum number of new dials per minute that a session is allowed+-- to send.local limit_outgoing_calls;local function load_config()limit_outgoing_calls = module:get_option_number("max_number_outgoing_calls", -1);@@ -150,8 +152,10 @@ module:hook("pre-iq/full", function(event)group_id = session.granted_jitsi_meet_context_group_id;end- -- now lets check any limits for outgoing calls if configured- if feature == 'outbound-call' and limit_outgoing_calls > 0 then+ -- now lets check any limits for dials if configured. This applies to both+ -- outbound calls and transcriptions: each one starts a Jigasi session, and+ -- get_concurrent_outgoing_count counts both through the initiator headers.+ if limit_outgoing_calls > 0 thenif not session.dial_out_throttle then-- module:log("debug", "Enabling dial-out throttle session=%s.", session);session.dial_out_throttle = new_throttle(limit_outgoing_calls, OUTGOING_CALLS_THROTTLE_INTERVAL);@@ -161,7 +165,7 @@ module:hook("pre-iq/full", function(event)or get_concurrent_outgoing_count(user_id, group_id) >= limit_outgoing_callsthenmodule:log("warn",- "Filtering stanza dial, stanza:%s, outgoing calls limit reached", tostring(stanza));+ "Filtering stanza dial, stanza:%s, %s limit reached", tostring(stanza), feature);measure_drop(1);session.send(st.error_reply(stanza, "cancel", "resource-constraint"));return true;diff --git a/tests/prosody/docker/cfg/virtualhosts.cfg.lua b/tests/prosody/docker/cfg/virtualhosts.cfg.luaindex fc97709841..727cbb199d 100644--- a/tests/prosody/docker/cfg/virtualhosts.cfg.lua+++ b/tests/prosody/docker/cfg/virtualhosts.cfg.lua@@ -78,6 +78,11 @@ VirtualHost "localhost"lobby_muc = "lobby.conference.localhost"breakout_rooms_muc = "breakout.conference.localhost"+ -- mod_filter_iq_rayo: per-session rate (per minute) and per-user+ -- concurrency limit for Rayo dials. Kept low so the limit can be hit+ -- in tests with a few dials.+ max_number_outgoing_calls = 2+-- Clients on whitelist.localhost bypass the lobby.muc_lobby_whitelist = { "whitelist.localhost" }diff --git a/tests/prosody/mod_filter_iq_rayo_spec.js b/tests/prosody/mod_filter_iq_rayo_spec.jsindex 7f9e0104d8..a5db34fe86 100644--- a/tests/prosody/mod_filter_iq_rayo_spec.js+++ b/tests/prosody/mod_filter_iq_rayo_spec.js@@ -1,3 +1,4 @@+import { xml } from '@xmpp/client';import assert from 'assert';import http from 'http';@@ -265,6 +266,157 @@ describe('mod_filter_iq_rayo (feature-based authorization)', () => {});});+ // ─── max_number_outgoing_calls (set to 2 in the test config) ────────────+ //+ // The option bounds every Rayo dial a session or user sends: at most N+ // dials per minute per session, and at most N concurrent Jigasi sessions+ // (SIP or transcriber) per user, counted through the initiator headers that+ // Jigasi echoes back in its MUC presence.++ describe('max_number_outgoing_calls', () => {+ const LIMIT = 2;+ const transcribeOpts = { dialTo: 'jitsi_meet_transcribe' };++ /**+ * Creates a client whose token allows any room, and joins it to `count`+ * fresh rooms (focus joins each room first).+ *+ * @param {number} count+ * @param {object} [context] JWT context claim.+ * @returns {Promise<{client: object, rooms: string[]}>}+ */+ async function setupRooms(count, context) {+ const token = mintAsapToken({ room: '*',+ context });+ const c = await createXmppClient({ params: { token } });++ clients.push(c);++ const rooms = [];++ for (let i = 0; i < count; i++) {+ const room = nextRoom();+ const focus = await joinWithFocus(room);++ clients.push(focus);+ await c.joinRoom(room);+ rooms.push(room);+ }++ return { client: c,+ rooms };+ }++ /**+ * Joins a room as a transcriber (recorder.localhost account) whose+ * presence carries the Jigasi initiator extension with the+ * X-outbound-call-initiator-user header, as a real Jigasi transcriber+ * started by `userId` does.+ *+ * @param {string} roomJid+ * @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 })+ );++ await c.joinRoom(roomJid, 'transcriber', { extensions: [ initiator ] });++ return c;+ }++ /**+ * Sends a dial that is expected to be blocked and returns the error+ * condition name from the reply.+ */+ async function dialErrorCondition(client, roomJid, opts) {+ const reply = await client.sendRayoIqAndWait(roomJid, opts);+ const error = reply.getChild('error');++ return error ? error.children[0].name : null;+ }++ it('blocks the third outbound-call dial from one session within a minute', async () => {+ const { client: c, rooms: [ room ] } = await setupRooms(1, { features: { 'outbound-call': true } });++ for (let i = 0; i < LIMIT; i++) {+ const iqs = await sendAndCollect(c, room);++ assert.strictEqual(iqs.length, 1, `dial ${i + 1} should pass`);+ }++ assert.strictEqual(await dialErrorCondition(c, room), 'resource-constraint');+ });++ it('blocks the third transcription dial from one session within a minute', async () => {+ // One dial per room, so the per-room transcription throttle does not interfere.+ const { client: c, rooms } = await setupRooms(LIMIT + 1, { features: { transcription: true } });++ for (let i = 0; i < LIMIT; i++) {+ const iqs = await sendAndCollect(c, rooms[i], transcribeOpts);++ assert.strictEqual(iqs.length, 1, `transcription dial ${i + 1} should pass`);+ }++ assert.strictEqual(await dialErrorCondition(c, rooms[LIMIT], transcribeOpts), 'resource-constraint');+ });++ it('blocks a transcription dial when the user already has the maximum number of Jigasi sessions', async () => {+ const userId = 'limit-user-1';+ const { client: c, rooms } = await setupRooms(LIMIT + 1, {+ user: { id: userId },+ features: { transcription: true }+ });++ // Simulate LIMIT transcribers already running for this user in other rooms.+ for (let i = 0; i < LIMIT; i++) {+ await joinAsTranscriberStartedBy(rooms[i], userId);+ }++ assert.strictEqual(await dialErrorCondition(c, rooms[LIMIT], transcribeOpts), 'resource-constraint');+ });++ it('blocks an outbound-call dial when the user already has the maximum number of Jigasi sessions', async () => {+ const userId = 'limit-user-2';+ const { client: c, rooms } = await setupRooms(LIMIT + 1, {+ user: { id: userId },+ features: { 'outbound-call': true }+ });++ for (let i = 0; i < LIMIT; i++) {+ await joinAsTranscriberStartedBy(rooms[i], userId);+ }++ assert.strictEqual(await dialErrorCondition(c, rooms[LIMIT]), 'resource-constraint');+ });++ it('does not count Jigasi sessions started by another user', async () => {+ const { client: c, rooms } = await setupRooms(LIMIT + 1, {+ user: { id: 'limit-user-3' },+ features: { transcription: true }+ });++ for (let i = 0; i < LIMIT; i++) {+ await joinAsTranscriberStartedBy(rooms[i], 'someone-else');+ }++ const iqs = await sendAndCollect(c, rooms[LIMIT], transcribeOpts);++ assert.strictEqual(iqs.length, 1, 'dial should pass, the other sessions belong to another user');+ });+ });+// ─── Header stripping ───────────────────────────────────────────────────describe('header stripping', () => {