mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-30 20:37:36 +00:00
1 parent
347048c35f
commit
b375170fba
5 files changed
+107
-37
No files matched your search
@@ -0,0 +1 @@
|
||||
SEC25 fix. See <https://forgejo.ellis.link/continuwuation/advisories> at a later date for more info. Contributed by @jade.
|
||||
+52
-24
@@ -147,6 +147,33 @@ async fn create_invite(
|
||||
.server_in_room(services.globals.server_name(), &body.room_id)
|
||||
.await;
|
||||
if resident {
|
||||
// Make sure the invite is for the room we are in, then authorise it
|
||||
// against our current view of the room state.
|
||||
let create_event = services
|
||||
.rooms
|
||||
.state_accessor
|
||||
.room_state_get(&body.room_id, &StateEventType::RoomCreate, "")
|
||||
.await?;
|
||||
if create_event.event_id != create_event_id
|
||||
|| services.rooms.state.get_room_version(&body.room_id).await? != body.room_version
|
||||
{
|
||||
return Err!(Request(InvalidParam(
|
||||
"Invite does not match the room's create event or version."
|
||||
)));
|
||||
}
|
||||
|
||||
let invite_pdu = PduEvent::from_id_val(&body.event_id, signed_event.clone())?;
|
||||
if !services
|
||||
.rooms
|
||||
.event_handler
|
||||
.current_state_check_6(&invite_pdu, &room_version_rules, &create_event)
|
||||
.await?
|
||||
{
|
||||
return Err!(Request(Forbidden(
|
||||
"Invite is not authorised by the current room state."
|
||||
)));
|
||||
}
|
||||
|
||||
services
|
||||
.rooms
|
||||
.event_handler
|
||||
@@ -174,10 +201,31 @@ async fn create_invite(
|
||||
.expect("must be able to create PDU object");
|
||||
invite_state.push(RawStrippedState::Pdu(serde_json::value::to_raw_value(&signed_event)?));
|
||||
|
||||
// If we are active in the room, the remote server will notify us about the
|
||||
// join/invite through /send. If we are not in the room, we need to manually
|
||||
// record the invited state for client /sync through update_membership(),
|
||||
// and send the invite PDU to the relevant appservices.
|
||||
// We always mark the room as invited, because we don't act on invites through /send
|
||||
services
|
||||
.rooms
|
||||
.state_cache
|
||||
.mark_as_invited(
|
||||
&recipient_user,
|
||||
&body.room_id,
|
||||
&sender_user,
|
||||
invite_state,
|
||||
body.via.clone(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
services
|
||||
.rooms
|
||||
.state_cache
|
||||
.update_joined_count(&body.room_id)
|
||||
.await;
|
||||
|
||||
services.sync.wake(&recipient_user).await;
|
||||
|
||||
// If we are active in the room, the remote server will send us the invite
|
||||
// through /send, which notifies pushers and appservices now that the invite
|
||||
// has been recorded. If we are not in the room, we need to manually send
|
||||
// the invite PDU to the relevant appservices.
|
||||
if !resident {
|
||||
// We will start by recording the room's create event as an outlier.
|
||||
// This will allow us to recognise it later in case the sender revokes
|
||||
@@ -190,26 +238,6 @@ async fn create_invite(
|
||||
.outlier
|
||||
.add_pdu_outlier(&create_event_id, create_event_json);
|
||||
|
||||
services
|
||||
.rooms
|
||||
.state_cache
|
||||
.mark_as_invited(
|
||||
&recipient_user,
|
||||
&body.room_id,
|
||||
&sender_user,
|
||||
invite_state,
|
||||
body.via.clone(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
services
|
||||
.rooms
|
||||
.state_cache
|
||||
.update_joined_count(&body.room_id)
|
||||
.await;
|
||||
|
||||
services.sync.wake(&recipient_user).await;
|
||||
|
||||
let matching_appservices: Vec<_> = services
|
||||
.appservice
|
||||
.read()
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user