From: Nutomic Date: Fri, 28 Oct 2022 13:38:22 +0000 (+0000) Subject: Make verify apub url function async (#2514) X-Git-Url: http://these/git/%7B%60%24%7BwebArchiveUrl%7D/%22%7B%7D/%22https:/nerdica.net/static/%7BpictshareAvatarThumbnail%28?a=commitdiff_plain;h=b0c318566342740c5c97dd4b4d341fc2902607e0;p=lemmy.git Make verify apub url function async (#2514) * Make verify apub url function async * cleanup * use dep from crates.io * dont use unwrap --- diff --git a/Cargo.lock b/Cargo.lock index e726ae25..20e6c85b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "activitypub_federation" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "690ed975ab70b883b4f0776f60fd7f23a7484a49f4257e7672e64d0990e95771" +checksum = "dd9ae511df7135c271dca3ef3751f5528891c965e47d8d7a70fed9d2f1e5b6b1" dependencies = [ "activitypub_federation_derive", "actix-web", @@ -16,6 +16,7 @@ dependencies = [ "base64", "chrono", "derive_builder 0.11.2", + "dyn-clone", "http", "http-signature-normalization-actix", "http-signature-normalization-reqwest", @@ -1219,6 +1220,12 @@ dependencies = [ "syn 1.0.100", ] +[[package]] +name = "dyn-clone" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f94fa09c2aeea5b8839e414b7b841bf429fd25b9c522116ac97ee87856d88b2" + [[package]] name = "either" version = "1.8.0" diff --git a/Cargo.toml b/Cargo.toml index 58fb3325..82962d16 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,7 +49,7 @@ lemmy_db_schema = { version = "=0.16.5", path = "./crates/db_schema" } lemmy_api_common = { version = "=0.16.5", path = "crates/api_common" } lemmy_websocket = { version = "=0.16.5", path = "./crates/websocket" } lemmy_routes = { version = "=0.16.5", path = "./crates/routes" } -activitypub_federation = "0.2.0" +activitypub_federation = "0.2.3" diesel = "2.0.0" diesel_migrations = "2.0.0" serde = { version = "1.0.145", features = ["derive"] } diff --git a/crates/api/Cargo.toml b/crates/api/Cargo.toml index 935a4788..09136b43 100644 --- a/crates/api/Cargo.toml +++ b/crates/api/Cargo.toml @@ -22,7 +22,7 @@ lemmy_db_views_moderator = { version = "=0.16.5", path = "../db_views_moderator" lemmy_db_views_actor = { version = "=0.16.5", path = "../db_views_actor", features = ["full"] } lemmy_api_common = { version = "=0.16.5", path = "../api_common", features = ["full"] } lemmy_websocket = { version = "=0.16.5", path = "../websocket" } -activitypub_federation = { version = "0.2.2" } +activitypub_federation = "0.2.3" diesel = "2.0.0" bcrypt = "0.13.0" chrono = { version = "0.4.22", features = ["serde"], default-features = false } diff --git a/crates/api_crud/Cargo.toml b/crates/api_crud/Cargo.toml index 161e57c0..6608f22c 100644 --- a/crates/api_crud/Cargo.toml +++ b/crates/api_crud/Cargo.toml @@ -16,7 +16,7 @@ lemmy_db_views = { version = "=0.16.5", path = "../db_views", features = ["full" lemmy_db_views_actor = { version = "=0.16.5", path = "../db_views_actor", features = ["full"] } lemmy_api_common = { version = "=0.16.5", path = "../api_common", features = ["full"] } lemmy_websocket = { version = "=0.16.5", path = "../websocket" } -activitypub_federation = { version = "0.2.2" } +activitypub_federation = "0.2.3" bcrypt = "0.13.0" serde_json = { version = "1.0.85", features = ["preserve_order"] } serde = { version = "1.0.145", features = ["derive"] } diff --git a/crates/apub/Cargo.toml b/crates/apub/Cargo.toml index 22e6a52b..81967ee9 100644 --- a/crates/apub/Cargo.toml +++ b/crates/apub/Cargo.toml @@ -20,7 +20,7 @@ lemmy_db_views = { version = "=0.16.5", path = "../db_views", features = ["full" lemmy_db_views_actor = { version = "=0.16.5", path = "../db_views_actor", features = ["full"] } lemmy_api_common = { version = "=0.16.5", path = "../api_common", features = ["full"] } lemmy_websocket = { version = "=0.16.5", path = "../websocket" } -activitypub_federation = { version = "0.2.2" } +activitypub_federation = "0.2.3" diesel = "2.0.0" activitystreams-kinds = "0.2.1" chrono = { version = "0.4.22", features = ["serde"], default-features = false } diff --git a/crates/apub/src/activities/block/block_user.rs b/crates/apub/src/activities/block/block_user.rs index 3e574232..bef3b6a2 100644 --- a/crates/apub/src/activities/block/block_user.rs +++ b/crates/apub/src/activities/block/block_user.rs @@ -9,8 +9,6 @@ use crate::{ verify_person_in_community, }, activity_lists::AnnouncableActivities, - check_apub_id_valid, - fetch_local_site_data, local_instance, objects::{community::ApubCommunity, instance::remote_instance_inboxes, person::ApubPerson}, protocol::activities::block::block_user::BlockUser, @@ -125,10 +123,6 @@ impl ActivityHandler for BlockUser { context: &Data, request_counter: &mut i32, ) -> Result<(), LemmyError> { - let local_site_data = blocking(context.pool(), fetch_local_site_data).await??; - check_apub_id_valid(self.id(), &local_site_data, context.settings()) - .map_err(LemmyError::from_message)?; - verify_is_public(&self.to, &self.cc)?; match self .target diff --git a/crates/apub/src/activities/block/undo_block_user.rs b/crates/apub/src/activities/block/undo_block_user.rs index b93d0aa3..6de1d3a1 100644 --- a/crates/apub/src/activities/block/undo_block_user.rs +++ b/crates/apub/src/activities/block/undo_block_user.rs @@ -1,19 +1,3 @@ -use crate::{ - activities::{ - block::{generate_cc, SiteOrCommunity}, - community::{announce::GetCommunity, send_activity_in_community}, - generate_activity_id, - send_lemmy_activity, - verify_is_public, - }, - activity_lists::AnnouncableActivities, - check_apub_id_valid, - fetch_local_site_data, - local_instance, - objects::{community::ApubCommunity, instance::remote_instance_inboxes, person::ApubPerson}, - protocol::activities::block::{block_user::BlockUser, undo_block_user::UndoBlockUser}, - ActorType, -}; use activitypub_federation::{ core::object_id::ObjectId, data::Data, @@ -34,6 +18,21 @@ use lemmy_utils::error::LemmyError; use lemmy_websocket::LemmyContext; use url::Url; +use crate::{ + activities::{ + block::{generate_cc, SiteOrCommunity}, + community::{announce::GetCommunity, send_activity_in_community}, + generate_activity_id, + send_lemmy_activity, + verify_is_public, + }, + activity_lists::AnnouncableActivities, + local_instance, + objects::{community::ApubCommunity, instance::remote_instance_inboxes, person::ApubPerson}, + protocol::activities::block::{block_user::BlockUser, undo_block_user::UndoBlockUser}, + ActorType, +}; + impl UndoBlockUser { #[tracing::instrument(skip_all)] pub async fn send( @@ -92,10 +91,6 @@ impl ActivityHandler for UndoBlockUser { context: &Data, request_counter: &mut i32, ) -> Result<(), LemmyError> { - let local_site_data = blocking(context.pool(), fetch_local_site_data).await??; - check_apub_id_valid(self.id(), &local_site_data, context.settings()) - .map_err(LemmyError::from_message)?; - verify_is_public(&self.to, &self.cc)?; verify_domains_match(self.actor.inner(), self.object.actor.inner())?; self.object.verify(context, request_counter).await?; diff --git a/crates/apub/src/activities/community/add_mod.rs b/crates/apub/src/activities/community/add_mod.rs index 86ee9166..4dbd463b 100644 --- a/crates/apub/src/activities/community/add_mod.rs +++ b/crates/apub/src/activities/community/add_mod.rs @@ -12,8 +12,6 @@ use crate::{ verify_person_in_community, }, activity_lists::AnnouncableActivities, - check_apub_id_valid, - fetch_local_site_data, generate_moderators_url, local_instance, objects::{community::ApubCommunity, person::ApubPerson}, @@ -86,10 +84,6 @@ impl ActivityHandler for AddMod { context: &Data, request_counter: &mut i32, ) -> Result<(), LemmyError> { - let local_site_data = blocking(context.pool(), fetch_local_site_data).await??; - check_apub_id_valid(self.id(), &local_site_data, context.settings()) - .map_err(LemmyError::from_message)?; - verify_is_public(&self.to, &self.cc)?; let community = self.get_community(context, request_counter).await?; verify_person_in_community(&self.actor, &community, context, request_counter).await?; diff --git a/crates/apub/src/activities/community/announce.rs b/crates/apub/src/activities/community/announce.rs index 2886c2bf..e5419680 100644 --- a/crates/apub/src/activities/community/announce.rs +++ b/crates/apub/src/activities/community/announce.rs @@ -1,8 +1,6 @@ use crate::{ activities::{generate_activity_id, send_lemmy_activity, verify_is_public}, activity_lists::AnnouncableActivities, - check_apub_id_valid, - fetch_local_site_data, insert_activity, objects::community::ApubCommunity, protocol::{ @@ -13,7 +11,6 @@ use crate::{ }; use activitypub_federation::{core::object_id::ObjectId, data::Data, traits::ActivityHandler}; use activitystreams_kinds::{activity::AnnounceType, public}; -use lemmy_api_common::utils::blocking; use lemmy_utils::error::LemmyError; use lemmy_websocket::LemmyContext; use tracing::debug; @@ -87,13 +84,9 @@ impl ActivityHandler for AnnounceActivity { #[tracing::instrument(skip_all)] async fn verify( &self, - context: &Data, + _context: &Data, _request_counter: &mut i32, ) -> Result<(), LemmyError> { - let local_site_data = blocking(context.pool(), fetch_local_site_data).await??; - check_apub_id_valid(self.id(), &local_site_data, context.settings()) - .map_err(LemmyError::from_message)?; - verify_is_public(&self.to, &self.cc)?; Ok(()) } diff --git a/crates/apub/src/activities/community/remove_mod.rs b/crates/apub/src/activities/community/remove_mod.rs index 3dca0239..ede6a008 100644 --- a/crates/apub/src/activities/community/remove_mod.rs +++ b/crates/apub/src/activities/community/remove_mod.rs @@ -12,8 +12,6 @@ use crate::{ verify_person_in_community, }, activity_lists::AnnouncableActivities, - check_apub_id_valid, - fetch_local_site_data, generate_moderators_url, local_instance, objects::{community::ApubCommunity, person::ApubPerson}, @@ -86,10 +84,6 @@ impl ActivityHandler for RemoveMod { context: &Data, request_counter: &mut i32, ) -> Result<(), LemmyError> { - let local_site_data = blocking(context.pool(), fetch_local_site_data).await??; - check_apub_id_valid(self.id(), &local_site_data, context.settings()) - .map_err(LemmyError::from_message)?; - verify_is_public(&self.to, &self.cc)?; let community = self.get_community(context, request_counter).await?; verify_person_in_community(&self.actor, &community, context, request_counter).await?; diff --git a/crates/apub/src/activities/community/report.rs b/crates/apub/src/activities/community/report.rs index de3fb356..c3b50abf 100644 --- a/crates/apub/src/activities/community/report.rs +++ b/crates/apub/src/activities/community/report.rs @@ -1,7 +1,5 @@ use crate::{ activities::{generate_activity_id, send_lemmy_activity, verify_person_in_community}, - check_apub_id_valid, - fetch_local_site_data, local_instance, objects::{community::ApubCommunity, person::ApubPerson}, protocol::activities::community::report::Report, @@ -76,10 +74,6 @@ impl ActivityHandler for Report { context: &Data, request_counter: &mut i32, ) -> Result<(), LemmyError> { - let local_site_data = blocking(context.pool(), fetch_local_site_data).await??; - check_apub_id_valid(self.id(), &local_site_data, context.settings()) - .map_err(LemmyError::from_message)?; - let community = self.to[0] .dereference(context, local_instance(context), request_counter) .await?; diff --git a/crates/apub/src/activities/community/update.rs b/crates/apub/src/activities/community/update.rs index b444f4f5..def4d7a4 100644 --- a/crates/apub/src/activities/community/update.rs +++ b/crates/apub/src/activities/community/update.rs @@ -7,8 +7,6 @@ use crate::{ verify_person_in_community, }, activity_lists::AnnouncableActivities, - check_apub_id_valid, - fetch_local_site_data, local_instance, objects::{community::ApubCommunity, person::ApubPerson}, protocol::activities::community::update::UpdateCommunity, @@ -71,9 +69,6 @@ impl ActivityHandler for UpdateCommunity { context: &Data, request_counter: &mut i32, ) -> Result<(), LemmyError> { - let local_site_data = blocking(context.pool(), fetch_local_site_data).await??; - check_apub_id_valid(self.id(), &local_site_data, context.settings()) - .map_err(LemmyError::from_message)?; verify_is_public(&self.to, &self.cc)?; let community = self.get_community(context, request_counter).await?; verify_person_in_community(&self.actor, &community, context, request_counter).await?; diff --git a/crates/apub/src/activities/create_or_update/comment.rs b/crates/apub/src/activities/create_or_update/comment.rs index 3e0de366..dad6ada9 100644 --- a/crates/apub/src/activities/create_or_update/comment.rs +++ b/crates/apub/src/activities/create_or_update/comment.rs @@ -8,8 +8,6 @@ use crate::{ verify_person_in_community, }, activity_lists::AnnouncableActivities, - check_apub_id_valid, - fetch_local_site_data, local_instance, mentions::MentionOrValue, objects::{comment::ApubComment, community::ApubCommunity, person::ApubPerson}, @@ -117,10 +115,6 @@ impl ActivityHandler for CreateOrUpdateComment { context: &Data, request_counter: &mut i32, ) -> Result<(), LemmyError> { - let local_site_data = blocking(context.pool(), fetch_local_site_data).await??; - check_apub_id_valid(self.id(), &local_site_data, context.settings()) - .map_err(LemmyError::from_message)?; - verify_is_public(&self.to, &self.cc)?; let post = self.object.get_parents(context, request_counter).await?.0; let community = self.get_community(context, request_counter).await?; diff --git a/crates/apub/src/activities/create_or_update/post.rs b/crates/apub/src/activities/create_or_update/post.rs index 1f997f72..d9d7b854 100644 --- a/crates/apub/src/activities/create_or_update/post.rs +++ b/crates/apub/src/activities/create_or_update/post.rs @@ -8,8 +8,6 @@ use crate::{ verify_person_in_community, }, activity_lists::AnnouncableActivities, - check_apub_id_valid, - fetch_local_site_data, objects::{community::ApubCommunity, person::ApubPerson, post::ApubPost}, protocol::activities::{create_or_update::post::CreateOrUpdatePost, CreateOrUpdateType}, ActorType, @@ -95,9 +93,6 @@ impl ActivityHandler for CreateOrUpdatePost { context: &Data, request_counter: &mut i32, ) -> Result<(), LemmyError> { - let local_site_data = blocking(context.pool(), fetch_local_site_data).await??; - check_apub_id_valid(self.id(), &local_site_data, context.settings()) - .map_err(LemmyError::from_message)?; verify_is_public(&self.to, &self.cc)?; let community = self.get_community(context, request_counter).await?; verify_person_in_community(&self.actor, &community, context, request_counter).await?; diff --git a/crates/apub/src/activities/create_or_update/private_message.rs b/crates/apub/src/activities/create_or_update/private_message.rs index 20310bc4..9ad54769 100644 --- a/crates/apub/src/activities/create_or_update/private_message.rs +++ b/crates/apub/src/activities/create_or_update/private_message.rs @@ -1,7 +1,5 @@ use crate::{ activities::{generate_activity_id, send_lemmy_activity, verify_person}, - check_apub_id_valid, - fetch_local_site_data, objects::{person::ApubPerson, private_message::ApubPrivateMessage}, protocol::activities::{ create_or_update::private_message::CreateOrUpdatePrivateMessage, @@ -71,10 +69,6 @@ impl ActivityHandler for CreateOrUpdatePrivateMessage { context: &Data, request_counter: &mut i32, ) -> Result<(), LemmyError> { - let local_site_data = blocking(context.pool(), fetch_local_site_data).await??; - check_apub_id_valid(self.id(), &local_site_data, context.settings()) - .map_err(LemmyError::from_message)?; - verify_person(&self.actor, context, request_counter).await?; verify_domains_match(self.actor.inner(), self.object.id.inner())?; verify_domains_match(self.to[0].inner(), self.object.to[0].inner())?; diff --git a/crates/apub/src/activities/deletion/delete.rs b/crates/apub/src/activities/deletion/delete.rs index 95024c47..ca93b89f 100644 --- a/crates/apub/src/activities/deletion/delete.rs +++ b/crates/apub/src/activities/deletion/delete.rs @@ -4,8 +4,6 @@ use crate::{ deletion::{receive_delete_action, verify_delete_activity, DeletableObjects}, generate_activity_id, }, - check_apub_id_valid, - fetch_local_site_data, local_instance, objects::{community::ApubCommunity, person::ApubPerson}, protocol::{activities::deletion::delete::Delete, IdOrNestedObject}, @@ -57,9 +55,6 @@ impl ActivityHandler for Delete { context: &Data, request_counter: &mut i32, ) -> Result<(), LemmyError> { - let local_site_data = blocking(context.pool(), fetch_local_site_data).await??; - check_apub_id_valid(self.id(), &local_site_data, context.settings()) - .map_err(LemmyError::from_message)?; verify_delete_activity(self, self.summary.is_some(), context, request_counter).await?; Ok(()) } diff --git a/crates/apub/src/activities/deletion/delete_user.rs b/crates/apub/src/activities/deletion/delete_user.rs index 5fb453ee..9570d85d 100644 --- a/crates/apub/src/activities/deletion/delete_user.rs +++ b/crates/apub/src/activities/deletion/delete_user.rs @@ -1,7 +1,5 @@ use crate::{ activities::{generate_activity_id, send_lemmy_activity, verify_is_public, verify_person}, - check_apub_id_valid, - fetch_local_site_data, local_instance, objects::{instance::remote_instance_inboxes, person::ApubPerson}, protocol::activities::deletion::delete_user::DeleteUser, @@ -13,7 +11,7 @@ use activitypub_federation::{ utils::verify_urls_match, }; use activitystreams_kinds::{activity::DeleteType, public}; -use lemmy_api_common::utils::{blocking, delete_user_account}; +use lemmy_api_common::utils::delete_user_account; use lemmy_utils::error::LemmyError; use lemmy_websocket::LemmyContext; use url::Url; @@ -38,9 +36,6 @@ impl ActivityHandler for DeleteUser { context: &Data, request_counter: &mut i32, ) -> Result<(), LemmyError> { - let local_site_data = blocking(context.pool(), fetch_local_site_data).await??; - check_apub_id_valid(self.id(), &local_site_data, context.settings()) - .map_err(LemmyError::from_message)?; verify_is_public(&self.to, &[])?; verify_person(&self.actor, context, request_counter).await?; verify_urls_match(self.actor.inner(), self.object.inner())?; diff --git a/crates/apub/src/activities/deletion/undo_delete.rs b/crates/apub/src/activities/deletion/undo_delete.rs index f73c780c..1576e944 100644 --- a/crates/apub/src/activities/deletion/undo_delete.rs +++ b/crates/apub/src/activities/deletion/undo_delete.rs @@ -4,8 +4,6 @@ use crate::{ deletion::{receive_delete_action, verify_delete_activity, DeletableObjects}, generate_activity_id, }, - check_apub_id_valid, - fetch_local_site_data, local_instance, objects::{community::ApubCommunity, person::ApubPerson}, protocol::activities::deletion::{delete::Delete, undo_delete::UndoDelete}, @@ -56,9 +54,6 @@ impl ActivityHandler for UndoDelete { context: &Data, request_counter: &mut i32, ) -> Result<(), LemmyError> { - let local_site_data = blocking(context.pool(), fetch_local_site_data).await??; - check_apub_id_valid(self.id(), &local_site_data, context.settings()) - .map_err(LemmyError::from_message)?; self.object.verify(context, request_counter).await?; verify_delete_activity( &self.object, diff --git a/crates/apub/src/activities/following/accept.rs b/crates/apub/src/activities/following/accept.rs index c4bbbb1b..f964da08 100644 --- a/crates/apub/src/activities/following/accept.rs +++ b/crates/apub/src/activities/following/accept.rs @@ -1,7 +1,5 @@ use crate::{ activities::{generate_activity_id, send_lemmy_activity}, - check_apub_id_valid, - fetch_local_site_data, local_instance, protocol::activities::following::{accept::AcceptFollowCommunity, follow::FollowCommunity}, ActorType, @@ -69,10 +67,6 @@ impl ActivityHandler for AcceptFollowCommunity { context: &Data, request_counter: &mut i32, ) -> Result<(), LemmyError> { - let local_site_data = blocking(context.pool(), fetch_local_site_data).await??; - check_apub_id_valid(self.id(), &local_site_data, context.settings()) - .map_err(LemmyError::from_message)?; - verify_urls_match(self.actor.inner(), self.object.object.inner())?; self.object.verify(context, request_counter).await?; Ok(()) diff --git a/crates/apub/src/activities/following/follow.rs b/crates/apub/src/activities/following/follow.rs index 512c074c..b0ae72c7 100644 --- a/crates/apub/src/activities/following/follow.rs +++ b/crates/apub/src/activities/following/follow.rs @@ -5,8 +5,6 @@ use crate::{ verify_person, verify_person_in_community, }, - check_apub_id_valid, - fetch_local_site_data, local_instance, objects::{community::ApubCommunity, person::ApubPerson}, protocol::activities::following::{accept::AcceptFollowCommunity, follow::FollowCommunity}, @@ -86,9 +84,6 @@ impl ActivityHandler for FollowCommunity { context: &Data, request_counter: &mut i32, ) -> Result<(), LemmyError> { - let local_site_data = blocking(context.pool(), fetch_local_site_data).await??; - check_apub_id_valid(self.id(), &local_site_data, context.settings()) - .map_err(LemmyError::from_message)?; verify_person(&self.actor, context, request_counter).await?; let community = self .object diff --git a/crates/apub/src/activities/following/undo_follow.rs b/crates/apub/src/activities/following/undo_follow.rs index b37e21fb..94b0b68e 100644 --- a/crates/apub/src/activities/following/undo_follow.rs +++ b/crates/apub/src/activities/following/undo_follow.rs @@ -1,7 +1,5 @@ use crate::{ activities::{generate_activity_id, send_lemmy_activity, verify_person}, - check_apub_id_valid, - fetch_local_site_data, local_instance, objects::{community::ApubCommunity, person::ApubPerson}, protocol::activities::following::{follow::FollowCommunity, undo_follow::UndoFollowCommunity}, @@ -65,9 +63,6 @@ impl ActivityHandler for UndoFollowCommunity { context: &Data, request_counter: &mut i32, ) -> Result<(), LemmyError> { - let local_site_data = blocking(context.pool(), fetch_local_site_data).await??; - check_apub_id_valid(self.id(), &local_site_data, context.settings()) - .map_err(LemmyError::from_message)?; verify_urls_match(self.actor.inner(), self.object.actor.inner())?; verify_person(&self.actor, context, request_counter).await?; self.object.verify(context, request_counter).await?; diff --git a/crates/apub/src/activities/voting/undo_vote.rs b/crates/apub/src/activities/voting/undo_vote.rs index 80e319bf..f6fc36a2 100644 --- a/crates/apub/src/activities/voting/undo_vote.rs +++ b/crates/apub/src/activities/voting/undo_vote.rs @@ -6,8 +6,6 @@ use crate::{ voting::{undo_vote_comment, undo_vote_post}, }, activity_lists::AnnouncableActivities, - check_apub_id_valid, - fetch_local_site_data, local_instance, objects::{community::ApubCommunity, person::ApubPerson}, protocol::activities::voting::{ @@ -84,9 +82,6 @@ impl ActivityHandler for UndoVote { context: &Data, request_counter: &mut i32, ) -> Result<(), LemmyError> { - let local_site_data = blocking(context.pool(), fetch_local_site_data).await??; - check_apub_id_valid(self.id(), &local_site_data, context.settings()) - .map_err(LemmyError::from_message)?; let community = self.get_community(context, request_counter).await?; verify_person_in_community(&self.actor, &community, context, request_counter).await?; verify_urls_match(self.actor.inner(), self.object.actor.inner())?; diff --git a/crates/apub/src/activities/voting/vote.rs b/crates/apub/src/activities/voting/vote.rs index 7d07fe8c..e33c9567 100644 --- a/crates/apub/src/activities/voting/vote.rs +++ b/crates/apub/src/activities/voting/vote.rs @@ -6,8 +6,6 @@ use crate::{ voting::{vote_comment, vote_post}, }, activity_lists::AnnouncableActivities, - check_apub_id_valid, - fetch_local_site_data, local_instance, objects::{community::ApubCommunity, person::ApubPerson}, protocol::activities::voting::vote::{Vote, VoteType}, @@ -83,9 +81,6 @@ impl ActivityHandler for Vote { context: &Data, request_counter: &mut i32, ) -> Result<(), LemmyError> { - let local_site_data = blocking(context.pool(), fetch_local_site_data).await??; - check_apub_id_valid(self.id(), &local_site_data, context.settings()) - .map_err(LemmyError::from_message)?; let community = self.get_community(context, request_counter).await?; verify_person_in_community(&self.actor, &community, context, request_counter).await?; let enable_downvotes = blocking(context.pool(), LocalSite::read) diff --git a/crates/apub/src/lib.rs b/crates/apub/src/lib.rs index 471a7564..8c7c042c 100644 --- a/crates/apub/src/lib.rs +++ b/crates/apub/src/lib.rs @@ -4,8 +4,10 @@ use activitypub_federation::{ traits::{Actor, ApubObject}, InstanceSettings, LocalInstance, + UrlVerifier, }; use anyhow::Context; +use async_trait::async_trait; use diesel::PgConnection; use lemmy_api_common::utils::blocking; use lemmy_db_schema::{ @@ -59,9 +61,8 @@ fn local_instance(context: &LemmyContext) -> &'static LocalInstance { .http_fetch_retry_limit(http_fetch_retry_limit) .worker_count(worker_count) .debug(federation_debug) - // TODO No idea why, but you can't pass context.settings() to the verify_url_function closure - // without the value getting captured. .http_signature_compat(true) + .url_verifier(Box::new(VerifyUrlData(context.clone()))) .build() .expect("configure federation"); LocalInstance::new( @@ -72,6 +73,20 @@ fn local_instance(context: &LemmyContext) -> &'static LocalInstance { }) } +#[derive(Clone)] +struct VerifyUrlData(LemmyContext); + +#[async_trait] +impl UrlVerifier for VerifyUrlData { + async fn verify(&self, url: &Url) -> Result<(), &'static str> { + let local_site_data = blocking(self.0.pool(), fetch_local_site_data) + .await + .expect("read local site data") + .expect("read local site data"); + check_apub_id_valid(url, &local_site_data, self.0.settings()) + } +} + /// Checks if the ID is allowed for sending or receiving. /// /// In particular, it checks for: @@ -83,7 +98,6 @@ fn local_instance(context: &LemmyContext) -> &'static LocalInstance { /// `use_strict_allowlist` should be true only when parsing a remote community, or when parsing a /// post/comment in a local community. #[tracing::instrument(skip(settings, local_site_data))] -// TODO This function needs to be called by incoming activities fn check_apub_id_valid( apub_id: &Url, local_site_data: &LocalSiteData, diff --git a/crates/db_schema/Cargo.toml b/crates/db_schema/Cargo.toml index 155d8440..5808f81c 100644 --- a/crates/db_schema/Cargo.toml +++ b/crates/db_schema/Cargo.toml @@ -24,7 +24,7 @@ url = { version = "2.3.1", features = ["serde"] } strum = "0.24.1" strum_macros = "0.24.3" serde_json = { version = "1.0.85", features = ["preserve_order"], optional = true } -activitypub_federation = { version = "0.2.2", optional = true } +activitypub_federation = { version = "0.2.3", optional = true } lemmy_utils = { version = "=0.16.5", path = "../utils", optional = true } bcrypt = { version = "0.13.0", optional = true } diesel = { version = "2.0.0", features = ["postgres","chrono","r2d2","serde_json"], optional = true } diff --git a/crates/utils/translations b/crates/utils/translations index 454debae..f5d6f0ea 160000 --- a/crates/utils/translations +++ b/crates/utils/translations @@ -1 +1 @@ -Subproject commit 454debaede4cc932ac15fea9bf620cf1daf1ae4c +Subproject commit f5d6f0eabafd559417bf8f203fd655f7858bffcf