Comparison

plugins/muc/mod_muc.lua @ 10366:5611c939743a

MUC: Strictly validate room JID on creation This should prevent any MUCs with invalid JID (according to current normalization routine)
author Kim Alvefur <zash@zash.se>
date Fri, 01 Nov 2019 22:08:38 +0100
parent 10353:7b602e13c3b6
child 10449:2e36a54906e4
comparison
equal deleted inserted replaced
10365:744ca71a49f7 10366:5611c939743a
91 room_mt.set_presence_broadcast = presence_broadcast.set; 91 room_mt.set_presence_broadcast = presence_broadcast.set;
92 room_mt.get_valid_broadcast_roles = presence_broadcast.get_valid_broadcast_roles; 92 room_mt.get_valid_broadcast_roles = presence_broadcast.get_valid_broadcast_roles;
93 93
94 94
95 local jid_split = require "util.jid".split; 95 local jid_split = require "util.jid".split;
96 local jid_prep = require "util.jid".prep;
96 local jid_bare = require "util.jid".bare; 97 local jid_bare = require "util.jid".bare;
97 local st = require "util.stanza"; 98 local st = require "util.stanza";
98 local cache = require "util.cache"; 99 local cache = require "util.cache";
99 local um_is_admin = require "core.usermanager".is_admin; 100 local um_is_admin = require "core.usermanager".is_admin;
100 101
271 room:set_language(lang or module:get_option_string("muc_room_default_language")); 272 room:set_language(lang or module:get_option_string("muc_room_default_language"));
272 room:set_presence_broadcast(module:get_option("muc_room_default_presence_broadcast", room:get_presence_broadcast())); 273 room:set_presence_broadcast(module:get_option("muc_room_default_presence_broadcast", room:get_presence_broadcast()));
273 end 274 end
274 275
275 function create_room(room_jid, config) 276 function create_room(room_jid, config)
277 if jid_bare(room_jid) ~= room_jid or not jid_prep(room_jid, true) then
278 return nil, "invalid-jid";
279 end
276 local exists = get_room_from_jid(room_jid); 280 local exists = get_room_from_jid(room_jid);
277 if exists then 281 if exists then
278 return nil, "room-exists"; 282 return nil, "room-exists";
279 end 283 end
280 local room = muclib.new_room(room_jid, config); 284 local room = muclib.new_room(room_jid, config);
458 end 462 end
459 end 463 end
460 464
461 if room == nil then 465 if room == nil then
462 -- Watch presence to create rooms 466 -- Watch presence to create rooms
467 if not jid_prep(room_jid, true) then
468 origin.send(st.error_reply(stanza, "modify", "jid-malformed"));
469 return true;
470 end
463 if stanza.attr.type == nil and stanza.name == "presence" and stanza:get_child("x", "http://jabber.org/protocol/muc") then 471 if stanza.attr.type == nil and stanza.name == "presence" and stanza:get_child("x", "http://jabber.org/protocol/muc") then
464 room = muclib.new_room(room_jid); 472 room = muclib.new_room(room_jid);
465 return room:handle_first_presence(origin, stanza); 473 return room:handle_first_presence(origin, stanza);
466 elseif stanza.attr.type ~= "error" then 474 elseif stanza.attr.type ~= "error" then
467 origin.send(st.error_reply(stanza, "cancel", "item-not-found")); 475 origin.send(st.error_reply(stanza, "cancel", "item-not-found"));