Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Receive & store remote site bans #4571

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

sunaurus
Copy link
Collaborator

Currently, remote site bans are only received if they originate from the user's home instance. This has some downsides:

  1. Instances can't check if their users are site banned from remote communities, meaning that local users can post completely unmoderated content in their local views of remote communities. Instance banning a remote user should prevent them from participating in remote versions of communities #3399
  2. Remote instance admins can completely negate bans against their users on any instance, by simply banning & unbanning them locally (as this overwrites existing bans on all instances!)

This PR adds a new site_person_ban table, which stores data about all incoming federated bans. Additionally, this PR adds logic to prevent participating in communities if the user is banned on the host instance.

TODO:

  • Need to add logic to the API to reflect if a user is banned on their home instance, as we no longer use the person.banned column for remote bans (that column is now exclusively reserved for local bans and should never be overwritten by federation)
  • I want to do some proper testing for this in the next few days, as it's quite an important feature

// home instance. We can continue to use community bans to federate data removal for
// backwards compatibility, initially but at some point, when most instances have been
// upgraded to have the logic of storing remote site bans, we can start doing data
// removal here & remove the logic of federating community bans on remote site bans.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldnt bother with this, the mentioned changes in #4464 havent even been released yet and are quite hacky. So theres a chance that it will introduce problems of its own. Better to revert #4464 here and go for the proper solution directly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this, I'd love to remove my weird logic for banning them from local communities.

@Nutomic
Copy link
Member

Nutomic commented Mar 26, 2024

Need to add logic to the API to reflect if a user is banned on their home instance, as we no longer use the person.banned column for remote bans (that column is now exclusively reserved for local bans and should never be overwritten by federation)

I dont think it makes sense to have two different places to store site bans, that can easily cause confusion and bugs. You should remove the person.banned column and migrate to site_person_ban table instead.

@Nothing4You
Copy link
Contributor

Nothing4You commented Mar 26, 2024

This might be out of scope for this PR if this is being strictly for site bans, but this is also a problem with other moderation actions.

As an instance admin, I can issue a community ban for a remote user on a remote instance. I'm not sure if there are many cases where I would need this beyond dealing with some federation related issues like the recent kbin.social activity spam, so maybe it would make sense to remove a local admin's ability to issue a community ban if they're not also a community moderator?
That also cuts into the topic of community management though, as communities generally belong to an instance. To streamline this, we'd probably also have to prevent local admins from adding themselves to remote communities.

Once this is addressed on community level, posts and comments can still be removed locally without the admin being a community moderator. I'm not sure if there is an elegant solution besides adding a column like local_removed next to removed to properly address this, although it would also bring up the question of how to handle with @admin@A removing a post in !comm@A, which they're also moderator of. Then @mod@B, who is also moderator of !comm@A decides to restore the post, e.g. because of an appeal. Should the post be restored for everyone? Only outside of instance A?

Let me know if I should move this to its own issue.

if let Some(site) = Site::read_from_instance_id(pool, instance_id).await? {
let is_banned_from_site_of_community = SitePersonBanView::get(pool, person.id, site.id).await?;
if is_banned_from_site_of_community {
Err(LemmyErrorType::BannedFromCommunity)?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on adding a separate error here, like BannedFromSiteHostingCommunity or something?

published TIMESTAMP WITH TIME ZONE DEFAULT NOW() NOT NULL,
expires TIMESTAMP WITH TIME ZONE,
PRIMARY KEY (person_id, site_id)
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

pub struct SitePersonBanView {
pub site: Site,
pub person: Person,
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The view might not be necessary, since we're not returning this view specifically, but only fields joined from site_person_ban

Same for CommunityPersonBanView, but that's up to you whether to remove it or not.

@@ -84,3 +84,28 @@ pub struct SiteUpdateForm {
pub public_key: Option<String>,
pub content_warning: Option<Option<String>>,
}

#[derive(PartialEq, Eq, Debug)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add #[skip_serializing_none]

@dessalines
Copy link
Member

Main change needed of course is that we need to remove the person.banned column, and do joins to your new table on pretty much every view. Maybe two separate fields, a local_site_banned and host_site_banned would be best.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants