Skip to content

Commit

Permalink
only federate site bans originating from user's home instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutomic committed Feb 7, 2022
1 parent 02eee1c commit 238dc11
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
43 changes: 23 additions & 20 deletions crates/api/src/local_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,26 +478,29 @@ impl Perform for BanPerson {
.await??
.into(),
);
if ban {
BlockUser::send(
&site,
&person.into(),
&local_user_view.person.into(),
remove_data,
data.reason.clone(),
expires,
context,
)
.await?;
} else {
UndoBlockUser::send(
&site,
&person.into(),
&local_user_view.person.into(),
data.reason.clone(),
context,
)
.await?;
// if the action affects a local user, federate to other instances
if person.local {
if ban {
BlockUser::send(
&site,
&person.into(),
&local_user_view.person.into(),
remove_data,
data.reason.clone(),
expires,
context,
)
.await?;
} else {
UndoBlockUser::send(
&site,
&person.into(),
&local_user_view.person.into(),
data.reason.clone(),
context,
)
.await?;
}
}

let res = BanPersonResponse {
Expand Down
8 changes: 7 additions & 1 deletion crates/apub/src/activities/block/block_user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use lemmy_db_schema::{
},
traits::{Bannable, Crud, Followable},
};
use lemmy_utils::{utils::convert_datetime, LemmyError};
use lemmy_utils::{settings::structs::Settings, utils::convert_datetime, LemmyError};
use lemmy_websocket::LemmyContext;

impl BlockUser {
Expand Down Expand Up @@ -121,6 +121,12 @@ impl ActivityHandler for BlockUser {
.await?
{
SiteOrCommunity::Site(site) => {
let domain = self.object.inner().domain().expect("url needs domain");
if Settings::get().hostname == domain {
return Err(
anyhow!("Site bans from remote instance can't affect user's home instance").into(),
);
}
// site ban can only target a user who is on the same instance as the actor (admin)
verify_domains_match(&site.actor_id(), self.actor.inner())?;
verify_domains_match(&site.actor_id(), self.object.inner())?;
Expand Down

0 comments on commit 238dc11

Please sign in to comment.