diff --git a/src/service/rooms/event_handler/call_policyserv.rs b/src/service/rooms/event_handler/call_policyserv.rs index 0592186a..331d4c8f 100644 --- a/src/service/rooms/event_handler/call_policyserv.rs +++ b/src/service/rooms/event_handler/call_policyserv.rs @@ -11,6 +11,10 @@ use ruma::{ #[implement(super::Service)] #[tracing::instrument(skip_all, level = "debug")] pub async fn policyserv_check(&self, pdu: &PduEvent, room_id: &RoomId) -> Result { + if pdu.event_type().to_owned() == StateEventType::RoomPolicy.into() { + debug!("Skipping spam check for policy server meta-event in room {room_id}"); + return Ok(()); + } let Ok(policyserver) = self .services .state_accessor @@ -28,6 +32,14 @@ pub async fn policyserv_check(&self, pdu: &PduEvent, room_id: &RoomId) -> Result return Ok(()); }, }; + if via.is_empty() { + debug!("Policy server is empty for room {room_id}, skipping spam check"); + return Ok(()); + } + if !self.services.state_cache.server_in_room(via, room_id).await { + debug!("Policy server {via} is not in the room {room_id}, skipping spam check"); + return Ok(()); + } let outgoing = self .services .sending diff --git a/src/service/rooms/event_handler/mod.rs b/src/service/rooms/event_handler/mod.rs index ba5ad7e2..a0a1b20b 100644 --- a/src/service/rooms/event_handler/mod.rs +++ b/src/service/rooms/event_handler/mod.rs @@ -38,6 +38,7 @@ struct Services { server_keys: Dep, short: Dep, state: Dep, + state_cache: Dep, state_accessor: Dep, state_compressor: Dep, timeline: Dep, @@ -63,6 +64,7 @@ impl crate::Service for Service { pdu_metadata: args.depend::("rooms::pdu_metadata"), short: args.depend::("rooms::short"), state: args.depend::("rooms::state"), + state_cache: args.depend::("rooms::state_cache"), state_accessor: args .depend::("rooms::state_accessor"), state_compressor: args