Mercurial > prosody-modules
comparison mod_isolate_host/mod_isolate_host.lua @ 5650:0eb2d5ea2428
merge
| author | Stephen Paul Weber <singpolyma@singpolyma.net> |
|---|---|
| date | Sat, 06 May 2023 19:40:23 -0500 |
| parents | 4bba2d27ffaf |
| children | 25e20fa3824c |
comparison
equal
deleted
inserted
replaced
| 5649:2c69577b28c2 | 5650:0eb2d5ea2428 |
|---|---|
| 20 if to_host and to_host ~= origin.host and not except_domains:contains(to_host) then | 20 if to_host and to_host ~= origin.host and not except_domains:contains(to_host) then |
| 21 if to_host:match("^[^.]+%.(.+)$") == origin.host then -- Permit subdomains | 21 if to_host:match("^[^.]+%.(.+)$") == origin.host then -- Permit subdomains |
| 22 except_domains:add(to_host); | 22 except_domains:add(to_host); |
| 23 return; | 23 return; |
| 24 end | 24 end |
| 25 if origin.type == "local" then | |
| 26 -- this is code-generated, which means that set_session_isolation_flag has never triggered. | |
| 27 -- we need to check explicitly. | |
| 28 if not is_jid_isolated(jid_bare(event.stanza.attr.from)) then | |
| 29 module:log("debug", "server-generated stanza from %s is allowed, as the jid is not isolated", event.stanza.attr.from); | |
| 30 return; | |
| 31 end | |
| 32 end | |
| 25 module:log("warn", "Forbidding stanza from %s to %s", stanza.attr.from or origin.full_jid, stanza.attr.to); | 33 module:log("warn", "Forbidding stanza from %s to %s", stanza.attr.from or origin.full_jid, stanza.attr.to); |
| 26 origin.send(st.error_reply(stanza, "auth", "forbidden", "Communication with "..to_host.." is not available")); | 34 origin.send(st.error_reply(stanza, "auth", "forbidden", "Communication with "..to_host.." is not available")); |
| 27 return true; | 35 return true; |
| 28 end | 36 end |
| 29 end | 37 end |
| 34 end | 42 end |
| 35 end | 43 end |
| 36 | 44 |
| 37 module:default_permission("prosody:admin", "xmpp:federate"); | 45 module:default_permission("prosody:admin", "xmpp:federate"); |
| 38 | 46 |
| 39 function check_user_isolated(event) | 47 function is_jid_isolated(bare_jid) |
| 48 if except_users:contains(bare_jid) or module:may("xmpp:federate", bare_jid) then | |
| 49 return false; | |
| 50 else | |
| 51 return true; | |
| 52 end | |
| 53 end | |
| 54 | |
| 55 function set_session_isolation_flag(event) | |
| 40 local session = event.session; | 56 local session = event.session; |
| 41 local bare_jid = jid_bare(session.full_jid); | 57 local bare_jid = jid_bare(session.full_jid); |
| 42 if module:may("xmpp:federate", event) or except_users:contains(bare_jid) then | 58 if not is_jid_isolated(bare_jid) then |
| 43 session.no_host_isolation = true; | 59 session.no_host_isolation = true; |
| 44 end | 60 end |
| 45 module:log("debug", "%s is %sisolated", session.full_jid or "[?]", session.no_host_isolation and "" or "not "); | 61 module:log("debug", "%s is %sisolated", session.full_jid or "[?]", session.no_host_isolation and "" or "not "); |
| 46 end | 62 end |
| 47 | 63 |
| 48 module:hook("resource-bind", check_user_isolated); | 64 module:hook("resource-bind", set_session_isolation_flag); |
