From 32c4d3224c1bc80e2a684bf1301bf4b1a2985d28 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Wed, 2 Dec 2020 16:55:53 +0100 Subject: [PATCH] Check for community ban when parsing post/comment (fixes #1287) --- lemmy_apub/src/inbox/community_inbox.rs | 2 +- lemmy_apub/src/objects/comment.rs | 3 +++ lemmy_apub/src/objects/mod.rs | 29 ++++++++++++++++++++++++- lemmy_apub/src/objects/post.rs | 2 ++ 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/lemmy_apub/src/inbox/community_inbox.rs b/lemmy_apub/src/inbox/community_inbox.rs index 6acdfa0d8..ad6eaffbf 100644 --- a/lemmy_apub/src/inbox/community_inbox.rs +++ b/lemmy_apub/src/inbox/community_inbox.rs @@ -259,7 +259,7 @@ async fn handle_undo_follow( Ok(()) } -async fn check_community_or_site_ban( +pub(crate) async fn check_community_or_site_ban( user: &User_, community: &Community, pool: &DbPool, diff --git a/lemmy_apub/src/objects/comment.rs b/lemmy_apub/src/objects/comment.rs index 6d2933949..9ff63cbd2 100644 --- a/lemmy_apub/src/objects/comment.rs +++ b/lemmy_apub/src/objects/comment.rs @@ -7,6 +7,7 @@ use crate::{ }, objects::{ check_object_domain, + check_object_for_community_or_site_ban, create_tombstone, get_object_from_apub, get_source_markdown_value, @@ -101,6 +102,8 @@ impl FromApub for Comment { expected_domain: Option, request_counter: &mut i32, ) -> Result { + check_object_for_community_or_site_ban(note, context, request_counter).await?; + let comment: Comment = get_object_from_apub(note, context, expected_domain, request_counter).await?; diff --git a/lemmy_apub/src/objects/mod.rs b/lemmy_apub/src/objects/mod.rs index 6a0175051..f7db59c70 100644 --- a/lemmy_apub/src/objects/mod.rs +++ b/lemmy_apub/src/objects/mod.rs @@ -1,4 +1,8 @@ -use crate::check_is_apub_id_valid; +use crate::{ + check_is_apub_id_valid, + fetcher::{get_or_fetch_and_upsert_community, get_or_fetch_and_upsert_user}, + inbox::community_inbox::check_community_or_site_ban, +}; use activitystreams::{ base::{AsBase, BaseExt, ExtendsExt}, markers::Base, @@ -205,3 +209,26 @@ where Ok(to) } } + +pub(in crate::objects) async fn check_object_for_community_or_site_ban( + object: &T, + context: &LemmyContext, + request_counter: &mut i32, +) -> Result<(), LemmyError> +where + T: ObjectExt, +{ + let user_id = object + .attributed_to() + .context(location_info!())? + .as_single_xsd_any_uri() + .context(location_info!())?; + let user = get_or_fetch_and_upsert_user(user_id, context, request_counter).await?; + let community_id = object + .to() + .context(location_info!())? + .as_single_xsd_any_uri() + .context(location_info!())?; + let community = get_or_fetch_and_upsert_community(community_id, context, request_counter).await?; + check_community_or_site_ban(&user, &community, context.pool()).await +} diff --git a/lemmy_apub/src/objects/post.rs b/lemmy_apub/src/objects/post.rs index 9c68c1c90..3ca8650da 100644 --- a/lemmy_apub/src/objects/post.rs +++ b/lemmy_apub/src/objects/post.rs @@ -3,6 +3,7 @@ use crate::{ fetcher::{get_or_fetch_and_upsert_community, get_or_fetch_and_upsert_user}, objects::{ check_object_domain, + check_object_for_community_or_site_ban, create_tombstone, get_object_from_apub, get_source_markdown_value, @@ -112,6 +113,7 @@ impl FromApub for Post { expected_domain: Option, request_counter: &mut i32, ) -> Result { + check_object_for_community_or_site_ban(page, context, request_counter).await?; get_object_from_apub(page, context, expected_domain, request_counter).await } }