0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-26 15:33:54 +01:00

ircd:Ⓜ️:vm: Add phase to reject events not needed by any local user.

This commit is contained in:
Jason Volk 2020-12-16 14:22:21 -08:00
parent dfcf032b96
commit c3f0f37b30
3 changed files with 33 additions and 0 deletions

View file

@ -29,6 +29,7 @@ enum ircd::m::vm::phase
DUPCHK, ///< Duplicate existence check.
ISSUE, ///< Issue phase (for my(event)'s only).
ACCESS, ///< Access control phase.
EMPTION, ///< Emption control phase.
VERIFY, ///< Signature verification.
FETCH_AUTH, ///< Authentication events fetch phase.
AUTH_STATIC, ///< Static authentication phase.

View file

@ -137,6 +137,7 @@ ircd::m::vm::reflect(const enum phase &code)
case phase::DUPCHK: return "DUPCHK";
case phase::ISSUE: return "ISSUE";
case phase::ACCESS: return "ACCESS";
case phase::EMPTION: return "EMPTION";
case phase::VERIFY: return "VERIFY";
case phase::FETCH_AUTH: return "FETCH_AUTH";
case phase::AUTH_STATIC: return "AUTH_STATIC";

View file

@ -827,6 +827,37 @@ ircd::m::vm::execute_pdu(eval &eval,
call_hook(access_hook, eval, event, eval);
}
// Check if this event is relevant to this server.
if(likely(opts.phase[phase::EMPTION]) && !eval.room_internal)
{
const scope_restore eval_phase
{
eval.phase, phase::EMPTION
};
const bool my_target_member_event
{
type == "m.room.member"
&& my(m::user(json::get<"state_key"_>(event)))
};
const bool allow
{
my(event)
|| my_target_member_event
|| m::local_joined(room_id)
};
if(unlikely(!allow))
throw m::ACCESS_DENIED
{
"I have no users which require (%s,%s) in %s on this server.",
type,
json::get<"state_key"_>(event),
json::get<"room_id"_>(event),
};
}
if(likely(opts.phase[phase::VERIFY]))
{
const scope_restore eval_phase