Changeset

10361:6e051bfca12d

MUC: Enforce strict resourceprep on nicknames (bye bye robot face)
author Kim Alvefur <zash@zash.se>
date Mon, 23 Sep 2019 19:13:14 +0200
parents 10360:64ddcbc9a328
children 10362:c05444119e9e
files plugins/muc/muc.lib.lua
diffstat 1 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/muc/muc.lib.lua	Mon Sep 09 22:32:01 2019 +0200
+++ b/plugins/muc/muc.lib.lua	Mon Sep 23 19:13:14 2019 +0200
@@ -444,6 +444,22 @@
 	end
 end, 1);
 
+module:hook("muc-occupant-pre-join", function(event)
+	local nick = jid_resource(event.occupant.nick);
+	if not resourceprep(nick, true) then -- strict
+		event.origin.send(st.error_reply(event.stanza, "modify", "jid-malformed", "Nickname must pass strict validation"));
+		return true;
+	end
+end, 2);
+
+module:hook("muc-occupant-pre-change", function(event)
+	local nick = jid_resource(event.dest_occupant.nick);
+	if not resourceprep(nick, true) then -- strict
+		event.origin.send(st.error_reply(event.stanza, "modify", "jid-malformed", "Nickname must pass strict validation"));
+		return true;
+	end
+end, 2);
+
 function room_mt:handle_first_presence(origin, stanza)
 	local real_jid = stanza.attr.from;
 	local dest_jid = stanza.attr.to;