diff --git a/lib/hk-util.js b/lib/hk-util.js index bc2c39f35..4dab6cafc 100644 --- a/lib/hk-util.js +++ b/lib/hk-util.js @@ -1028,6 +1028,17 @@ HK.onChannelMessage = function (Env, Server, channel, msgStruct, cb) { if (!_metadata) { return; } metadata = _metadata; + if (metadata?.restricted) { + const userId = msgStruct[1]; + // If userId is defined (not a private message) and the user + // is not a member of this restricted channel, prevent them + // from broadcasting to the pad until they have joined it + if (userId && !Server.channelContainsUser(channel.id, userId)) { + cb('EFORBIDDEN'); + return void w.abort(); + } + } + // don't write messages to expired channels if (checkExpired(Env, Server, channel)) { cb('EEXPIRED');