From 082ed5b70c51f69548837e907716d3413828ff69 Mon Sep 17 00:00:00 2001 From: timedout Date: Tue, 27 Jan 2026 23:26:14 +0000 Subject: [PATCH] feat: Use info level logs for residency check failures --- src/api/server/backfill.rs | 4 ++-- src/api/server/event.rs | 15 ++++++++++++++- src/api/server/event_auth.rs | 15 ++++++++++++++- src/api/server/get_missing_events.rs | 15 ++++++++++++++- src/api/server/hierarchy.rs | 15 ++++++++++++++- src/api/server/make_join.rs | 6 ++---- src/api/server/make_knock.rs | 4 ++-- src/api/server/make_leave.rs | 4 ++-- src/api/server/send_join.rs | 4 ++-- src/api/server/send_knock.rs | 4 ++-- src/api/server/send_leave.rs | 4 ++-- src/api/server/state.rs | 4 ++-- src/api/server/state_ids.rs | 15 ++++++++++++++- .../rooms/event_handler/handle_incoming_pdu.rs | 4 ++-- 14 files changed, 88 insertions(+), 25 deletions(-) diff --git a/src/api/server/backfill.rs b/src/api/server/backfill.rs index dc3520ed..91d1fc04 100644 --- a/src/api/server/backfill.rs +++ b/src/api/server/backfill.rs @@ -2,7 +2,7 @@ use std::cmp; use axum::extract::State; use conduwuit::{ - Err, Event, PduCount, Result, debug_warn, + Err, Event, PduCount, Result, info, result::LogErr, utils::{IterStream, ReadyExt, stream::TryTools}, }; @@ -40,7 +40,7 @@ pub(crate) async fn get_backfill_route( .server_in_room(services.globals.server_name(), &body.room_id) .await { - debug_warn!( + info!( origin = body.origin().as_str(), "Refusing to serve backfill for room we aren't participating in" ); diff --git a/src/api/server/event.rs b/src/api/server/event.rs index 5846c6d7..e56ee248 100644 --- a/src/api/server/event.rs +++ b/src/api/server/event.rs @@ -1,5 +1,5 @@ use axum::extract::State; -use conduwuit::{Result, err}; +use conduwuit::{Err, Result, err, info}; use ruma::{MilliSecondsSinceUnixEpoch, RoomId, api::federation::event::get_event}; use super::AccessCheck; @@ -38,6 +38,19 @@ pub(crate) async fn get_event_route( .check() .await?; + if !services + .rooms + .state_cache + .server_in_room(services.globals.server_name(), room_id) + .await + { + info!( + origin = body.origin().as_str(), + "Refusing to serve state for room we aren't participating in" + ); + return Err!(Request(NotFound("This server is not participating in that room."))); + } + Ok(get_event::v1::Response { origin: services.globals.server_name().to_owned(), origin_server_ts: MilliSecondsSinceUnixEpoch::now(), diff --git a/src/api/server/event_auth.rs b/src/api/server/event_auth.rs index c9e210f5..a9019e8e 100644 --- a/src/api/server/event_auth.rs +++ b/src/api/server/event_auth.rs @@ -1,7 +1,7 @@ use std::{borrow::Borrow, iter::once}; use axum::extract::State; -use conduwuit::{Error, Result, utils::stream::ReadyExt}; +use conduwuit::{Err, Error, Result, info, utils::stream::ReadyExt}; use futures::StreamExt; use ruma::{ RoomId, @@ -29,6 +29,19 @@ pub(crate) async fn get_event_authorization_route( .check() .await?; + if !services + .rooms + .state_cache + .server_in_room(services.globals.server_name(), &body.room_id) + .await + { + info!( + origin = body.origin().as_str(), + "Refusing to serve state for room we aren't participating in" + ); + return Err!(Request(NotFound("This server is not participating in that room."))); + } + let event = services .rooms .timeline diff --git a/src/api/server/get_missing_events.rs b/src/api/server/get_missing_events.rs index d727c694..577c079b 100644 --- a/src/api/server/get_missing_events.rs +++ b/src/api/server/get_missing_events.rs @@ -1,5 +1,5 @@ use axum::extract::State; -use conduwuit::{Result, debug, debug_error, utils::to_canonical_object}; +use conduwuit::{Err, Result, debug, debug_error, info, utils::to_canonical_object}; use ruma::api::federation::event::get_missing_events; use super::AccessCheck; @@ -26,6 +26,19 @@ pub(crate) async fn get_missing_events_route( .check() .await?; + if !services + .rooms + .state_cache + .server_in_room(services.globals.server_name(), &body.room_id) + .await + { + info!( + origin = body.origin().as_str(), + "Refusing to serve state for room we aren't participating in" + ); + return Err!(Request(NotFound("This server is not participating in that room."))); + } + let limit = body .limit .try_into() diff --git a/src/api/server/hierarchy.rs b/src/api/server/hierarchy.rs index 42c348f9..f67e1b76 100644 --- a/src/api/server/hierarchy.rs +++ b/src/api/server/hierarchy.rs @@ -1,6 +1,6 @@ use axum::extract::State; use conduwuit::{ - Err, Result, + Err, Result, info, utils::stream::{BroadbandExt, IterStream}, }; use conduwuit_service::rooms::spaces::{ @@ -23,6 +23,19 @@ pub(crate) async fn get_hierarchy_route( return Err!(Request(NotFound("Room does not exist."))); } + if !services + .rooms + .state_cache + .server_in_room(services.globals.server_name(), &body.room_id) + .await + { + info!( + origin = body.origin().as_str(), + "Refusing to serve state for room we aren't participating in" + ); + return Err!(Request(NotFound("This server is not participating in that room."))); + } + let room_id = &body.room_id; let suggested_only = body.suggested_only; let ref identifier = Identifier::ServerName(body.origin()); diff --git a/src/api/server/make_join.rs b/src/api/server/make_join.rs index a4b28bb8..a203d636 100644 --- a/src/api/server/make_join.rs +++ b/src/api/server/make_join.rs @@ -1,9 +1,7 @@ use std::borrow::ToOwned; use axum::extract::State; -use conduwuit::{ - Err, Error, Result, debug, debug_info, debug_warn, info, matrix::pdu::PduBuilder, warn, -}; +use conduwuit::{Err, Error, Result, debug, debug_info, info, matrix::pdu::PduBuilder, warn}; use conduwuit_service::Services; use futures::StreamExt; use ruma::{ @@ -38,7 +36,7 @@ pub(crate) async fn create_join_event_template_route( .server_in_room(services.globals.server_name(), &body.room_id) .await { - debug_warn!( + info!( origin = body.origin().as_str(), "Refusing to serve make_join for room we aren't participating in" ); diff --git a/src/api/server/make_knock.rs b/src/api/server/make_knock.rs index 23a680a6..83fd0081 100644 --- a/src/api/server/make_knock.rs +++ b/src/api/server/make_knock.rs @@ -1,6 +1,6 @@ use RoomVersionId::*; use axum::extract::State; -use conduwuit::{Err, Error, Result, debug_warn, matrix::pdu::PduBuilder, warn}; +use conduwuit::{Err, Error, Result, debug_warn, info, matrix::pdu::PduBuilder, warn}; use ruma::{ RoomVersionId, api::{client::error::ErrorKind, federation::knock::create_knock_event_template}, @@ -26,7 +26,7 @@ pub(crate) async fn create_knock_event_template_route( .server_in_room(services.globals.server_name(), &body.room_id) .await { - debug_warn!( + info!( origin = body.origin().as_str(), "Refusing to serve make_knock for room we aren't participating in" ); diff --git a/src/api/server/make_leave.rs b/src/api/server/make_leave.rs index c4e10b41..0c333788 100644 --- a/src/api/server/make_leave.rs +++ b/src/api/server/make_leave.rs @@ -1,5 +1,5 @@ use axum::extract::State; -use conduwuit::{Err, Result, debug_warn, matrix::pdu::PduBuilder}; +use conduwuit::{Err, Result, info, matrix::pdu::PduBuilder}; use ruma::{ api::federation::membership::prepare_leave_event, events::room::member::{MembershipState, RoomMemberEventContent}, @@ -26,7 +26,7 @@ pub(crate) async fn create_leave_event_template_route( .server_in_room(services.globals.server_name(), &body.room_id) .await { - debug_warn!( + info!( origin = body.origin().as_str(), "Refusing to serve make_leave for room we aren't participating in" ); diff --git a/src/api/server/send_join.rs b/src/api/server/send_join.rs index ab99ec03..f04ed4a5 100644 --- a/src/api/server/send_join.rs +++ b/src/api/server/send_join.rs @@ -4,7 +4,7 @@ use std::{borrow::Borrow, time::Instant, vec}; use axum::extract::State; use conduwuit::{ - Err, Event, Result, at, debug, debug_warn, err, info, + Err, Event, Result, at, debug, err, info, matrix::event::gen_event_id_canonical_json, trace, utils::stream::{BroadbandExt, IterStream, TryBroadbandExt}, @@ -42,7 +42,7 @@ async fn create_join_event( .server_in_room(services.globals.server_name(), room_id) .await { - debug_warn!( + info!( origin = origin.as_str(), "Refusing to serve send_join for room we aren't participating in" ); diff --git a/src/api/server/send_knock.rs b/src/api/server/send_knock.rs index cbe3ed57..a93c581f 100644 --- a/src/api/server/send_knock.rs +++ b/src/api/server/send_knock.rs @@ -1,6 +1,6 @@ use axum::extract::State; use conduwuit::{ - Err, Result, debug_warn, err, + Err, Result, err, info, matrix::{event::gen_event_id_canonical_json, pdu::PduEvent}, warn, }; @@ -60,7 +60,7 @@ pub(crate) async fn create_knock_event_v1_route( .server_in_room(services.globals.server_name(), &body.room_id) .await { - debug_warn!( + info!( origin = body.origin().as_str(), "Refusing to serve send_knock for room we aren't participating in" ); diff --git a/src/api/server/send_leave.rs b/src/api/server/send_leave.rs index 2842fd2f..cd17a500 100644 --- a/src/api/server/send_leave.rs +++ b/src/api/server/send_leave.rs @@ -1,7 +1,7 @@ #![allow(deprecated)] use axum::extract::State; -use conduwuit::{Err, Result, debug_warn, err, matrix::event::gen_event_id_canonical_json}; +use conduwuit::{Err, Result, err, info, matrix::event::gen_event_id_canonical_json}; use conduwuit_service::Services; use futures::FutureExt; use ruma::{ @@ -56,7 +56,7 @@ async fn create_leave_event( .server_in_room(services.globals.server_name(), room_id) .await { - debug_warn!( + info!( origin = origin.as_str(), "Refusing to serve backfill for room we aren't participating in" ); diff --git a/src/api/server/state.rs b/src/api/server/state.rs index 39b908a0..5e1ad8ca 100644 --- a/src/api/server/state.rs +++ b/src/api/server/state.rs @@ -1,7 +1,7 @@ use std::{borrow::Borrow, iter::once}; use axum::extract::State; -use conduwuit::{Err, Result, at, debug_warn, err, utils::IterStream}; +use conduwuit::{Err, Result, at, err, info, utils::IterStream}; use futures::{FutureExt, StreamExt, TryStreamExt}; use ruma::{OwnedEventId, api::federation::event::get_room_state}; @@ -30,7 +30,7 @@ pub(crate) async fn get_room_state_route( .server_in_room(services.globals.server_name(), &body.room_id) .await { - debug_warn!( + info!( origin = body.origin().as_str(), "Refusing to serve state for room we aren't participating in" ); diff --git a/src/api/server/state_ids.rs b/src/api/server/state_ids.rs index 648d4575..c9dea311 100644 --- a/src/api/server/state_ids.rs +++ b/src/api/server/state_ids.rs @@ -1,7 +1,7 @@ use std::{borrow::Borrow, iter::once}; use axum::extract::State; -use conduwuit::{Result, at, err}; +use conduwuit::{Err, Result, at, err, info}; use futures::{StreamExt, TryStreamExt}; use ruma::{OwnedEventId, api::federation::event::get_room_state_ids}; @@ -25,6 +25,19 @@ pub(crate) async fn get_room_state_ids_route( .check() .await?; + if !services + .rooms + .state_cache + .server_in_room(services.globals.server_name(), &body.room_id) + .await + { + info!( + origin = body.origin().as_str(), + "Refusing to serve state for room we aren't participating in" + ); + return Err!(Request(NotFound("This server is not participating in that room."))); + } + let shortstatehash = services .rooms .state_accessor diff --git a/src/service/rooms/event_handler/handle_incoming_pdu.rs b/src/service/rooms/event_handler/handle_incoming_pdu.rs index 2d12161b..92b862a4 100644 --- a/src/service/rooms/event_handler/handle_incoming_pdu.rs +++ b/src/service/rooms/event_handler/handle_incoming_pdu.rs @@ -4,7 +4,7 @@ use std::{ }; use conduwuit::{ - Err, Event, Result, debug::INFO_SPAN_LEVEL, debug_warn, defer, err, implement, + Err, Event, Result, debug::INFO_SPAN_LEVEL, defer, err, implement, info, utils::stream::IterStream, warn, }; use futures::{ @@ -120,7 +120,7 @@ pub async fn handle_incoming_pdu<'a>( .server_in_room(self.services.globals.server_name(), room_id) .await { - debug_warn!( + info!( %origin, "Dropping inbound PDU for room we aren't participating in" );