view mod_muc_block_pm/mod_muc_block_pm.lua @ 5616:59d5fc50f602

mod_http_oauth2: Implement refresh token rotation Makes refresh tokens one-time-use, handing out a new refresh token with each access token. Thus if a refresh token is stolen and used by an attacker, the next time the legitimate client tries to use the previous refresh token, it will not work and the attack will be noticed. If the attacker does not use the refresh token, it becomes invalid after the legitimate client uses it. This behavior is recommended by draft-ietf-oauth-security-topics
author Kim Alvefur <zash@zash.se>
date Sun, 23 Jul 2023 02:56:08 +0200
parents 67f7df9892bb
children
line wrap: on
line source

local st = require "util.stanza";

module:hook("muc-disco#info", function(event)
	table.insert(event.form, { name = "muc#roomconfig_allowpm"; value = "moderators" });
end);

module:hook("muc-private-message", function(event)
	local stanza, room = event.stanza, event.room;
	local from_occupant = room:get_occupant_by_nick(stanza.attr.from);

	if from_occupant and from_occupant.role == "moderator" then
		return -- moderators may message anyone
	end

	local to_occupant = room:get_occupant_by_nick(stanza.attr.to)
	if to_occupant and to_occupant.role == "moderator" then
		return -- messaging moderators is ok
	end

	if to_occupant.bare_jid == from_occupant.bare_jid then
		return -- to yourself is okay, used by some clients to sync read state in public channels
	end

	room:route_to_occupant(from_occupant, st.error_reply(stanza, "cancel", "policy-violation", "Private messages are disabled", room.jid))
	return false;
end, 1);