mod_s2s_whitelist/mod_s2s_whitelist.lua
author Matthew Wild <mwild1@gmail.com>
Thu, 07 Dec 2023 15:46:50 +0000
changeset 5791 e79f9dec35c0
parent 1288 c1a8ce147885
permissions -rw-r--r--
mod_c2s_conn_throttle: Reduce log level from error->info Our general policy is that "error" should never be triggerable by remote entities, and that it is always about something that requires admin intervention. This satisfies neither condition. The "warn" level can be used for unexpected events/behaviour triggered by remote entities, and this could qualify. However I don't think failed auth attempts are unexpected enough. I selected "info" because it is what is also used for other notable session lifecycle events.

local st = require "util.stanza";

local whitelist = module:get_option_inherited_set("s2s_whitelist", {});

module:hook("route/remote", function (event)
	if not whitelist:contains(event.to_host) then
		module:send(st.error_reply(event.stanza, "cancel", "not-allowed", "Communication with this domain is restricted"));
		return true;
	end
end, 100);

module:hook("s2s-stream-features", function (event)
	if not whitelist:contains(event.origin.from_host) then
		event.origin:close({
			condition = "policy-violation";
			text = "Communication with this domain is restricted";
		});
	end
end, 1000);