fix: SEC25

Reviewed-By: timedout <git@nexy7574.co.uk>
This commit is contained in:
Jade Ellis authored and timedout committed 2026-11-30 17:59:25 +00:00
1 parent 347048c35f
commit b375170fba
5 files changed
+107 -37

No files matched your search

@@ -249,7 +249,7 @@ impl super::Service {
///
/// Returns a boolean indicating whether the event is authorised, or an
/// error if the auth check fails.
pub(super) async fn current_state_check_6(
pub async fn current_state_check_6(
&self,
incoming_pdu: &PduEvent,
room_version_rules: &RoomVersionRules,
+16 -10
View File
@@ -109,17 +109,23 @@ impl super::Service {
self.mark_as_joined(user_id, room_id);
},
| MembershipState::Invite => {
let invite_state = if is_local {
self.services
.state
.summary_stripped(pdu, room_id, user_id, false)
.await
} else {
vec![]
};
// Remote invites for local users are not processed via the
// /send endpoint or state
// resolution, so they cannot bypass invite anti-spam or
// signature checks.
if !is_local || self.services.globals.user_is_local(pdu.sender()) {
let invite_state = if is_local {
self.services
.state
.summary_stripped(pdu, room_id, user_id, false)
.await
} else {
vec![]
};
self.mark_as_invited(user_id, room_id, pdu.sender(), invite_state, None)
.await?;
self.mark_as_invited(user_id, room_id, pdu.sender(), invite_state, None)
.await?;
}
},
| MembershipState::Knock => {
let knocked_state = if is_local {
+37 -2
View File
@@ -415,7 +415,9 @@ impl super::Service {
let mut notifies = Vec::with_capacity(push_targets.len().saturating_add(1));
let mut highlights = Vec::with_capacity(push_targets.len().saturating_add(1));
if *pdu.kind() == TimelineEventType::RoomMember {
if *pdu.kind() == TimelineEventType::RoomMember
&& !self.is_untrusted_remote_invite(pdu, room_id).await
{
if let Some(state_key) = pdu.state_key() {
match UserId::parse(state_key) {
| Ok(target_user_id) => {
@@ -701,6 +703,37 @@ impl super::Service {
}
}
/// Returns true if `pdu` is an invite for a local user from a remote
/// sender that was not accepted through the federation /invite endpoint,
/// and so has not passed the invite anti-spam checks.
async fn is_untrusted_remote_invite(&self, pdu: &PduEvent, room_id: &RoomId) -> bool {
if *pdu.kind() != TimelineEventType::RoomMember
|| self.services.globals.user_is_local(pdu.sender())
|| !pdu
.get_content::<RoomMemberEventContent>()
.is_ok_and(|c| c.membership == MembershipState::Invite)
{
return false;
}
let Some(target) = pdu.state_key().and_then(|sk| UserId::parse(sk).ok()) else {
return false;
};
if !self.services.globals.user_is_local(&target) {
return false;
}
// /invite records the sender when it accepts an invite.
self.services
.state_cache
.invite_sender(&target, room_id)
.await
.ok()
.as_deref()
!= Some(pdu.sender())
}
/// Determines if an appservice is interested in a particular event.
async fn is_appservice_interested(
&self,
@@ -717,7 +750,9 @@ impl super::Service {
return true;
}
let target = if *pdu.kind() == TimelineEventType::RoomMember {
let target = if *pdu.kind() == TimelineEventType::RoomMember
&& !self.is_untrusted_remote_invite(pdu, room_id).await
{
pdu.state_key().and_then(|sk| UserId::parse(sk).ok())
} else {
None