]> Untitled Git - lemmy.git/commitdiff
Make verify apub url function async (#2514)
authorNutomic <me@nutomic.com>
Fri, 28 Oct 2022 13:38:22 +0000 (13:38 +0000)
committerGitHub <noreply@github.com>
Fri, 28 Oct 2022 13:38:22 +0000 (09:38 -0400)
* Make verify apub url function async

* cleanup

* use dep from crates.io

* dont use unwrap

26 files changed:
Cargo.lock
Cargo.toml
crates/api/Cargo.toml
crates/api_crud/Cargo.toml
crates/apub/Cargo.toml
crates/apub/src/activities/block/block_user.rs
crates/apub/src/activities/block/undo_block_user.rs
crates/apub/src/activities/community/add_mod.rs
crates/apub/src/activities/community/announce.rs
crates/apub/src/activities/community/remove_mod.rs
crates/apub/src/activities/community/report.rs
crates/apub/src/activities/community/update.rs
crates/apub/src/activities/create_or_update/comment.rs
crates/apub/src/activities/create_or_update/post.rs
crates/apub/src/activities/create_or_update/private_message.rs
crates/apub/src/activities/deletion/delete.rs
crates/apub/src/activities/deletion/delete_user.rs
crates/apub/src/activities/deletion/undo_delete.rs
crates/apub/src/activities/following/accept.rs
crates/apub/src/activities/following/follow.rs
crates/apub/src/activities/following/undo_follow.rs
crates/apub/src/activities/voting/undo_vote.rs
crates/apub/src/activities/voting/vote.rs
crates/apub/src/lib.rs
crates/db_schema/Cargo.toml
crates/utils/translations

index e726ae25e2a0651a6f8415d899267a38785d3337..20e6c85be15b7bb132b7863d80553fc913f4c31e 100644 (file)
@@ -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"
index 58fb33257941a7884013fb12471743f17a3353c1..82962d16f55e3513fac09ad0091303c579fbe0cd 100644 (file)
@@ -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"] }
index 935a4788bf010e3788783cb96ff5f5c5b9343450..09136b43d66f8a7284a10c9c27d2ad27a510532b 100644 (file)
@@ -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 }
index 161e57c093c4da2354919e40dab1308573cbdbdb..6608f22cb0d2ab31349d078ed3b941c1af35c140 100644 (file)
@@ -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"] }
index 22e6a52b544c3393f2cfa15041e927c2f00f7b6f..81967ee915ba62f94635fd2d81a938e4e255d8e2 100644 (file)
@@ -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 }
index 3e574232d24e1fc0f770720dfc748d2cd5ba4cc4..bef3b6a287c8fc90ab65207664003642029050b4 100644 (file)
@@ -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<LemmyContext>,
     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
index b93d0aa3a77b9bc2d7e0ffadcbe9f5f425ba72e0..6de1d3a17c46abc1ba4b03cd5d24b7e76f27167e 100644 (file)
@@ -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<LemmyContext>,
     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?;
index 86ee916661c267398b2fb1a2a9f48699dfae8bad..4dbd463b70463596d6f7b5e2f55aaf33540d3f3f 100644 (file)
@@ -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<LemmyContext>,
     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?;
index 2886c2bf0ff2d81e0c266914b98d2ee8216a8ebe..e5419680ef9fda18266e121d34b4cc5a90c008a9 100644 (file)
@@ -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<LemmyContext>,
+    _context: &Data<LemmyContext>,
     _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(())
   }
index 3dca02397a719447fb74724951237b39218e1e27..ede6a0089cb9b22eca63714e2ab41d3d266b7536 100644 (file)
@@ -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<LemmyContext>,
     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?;
index de3fb3566d1ca0357ad8b8bdef9fad9da158e703..c3b50abfeeb915d18cf07cf3abf125c34527d364 100644 (file)
@@ -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<LemmyContext>,
     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?;
index b444f4f5eb6e49e1418a26fa07aa9a08a959d907..def4d7a4e0899056edde682e832c683dbd7fbd5d 100644 (file)
@@ -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<LemmyContext>,
     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?;
index 3e0de366ff899ef87ddf1b626532c71d70d86513..dad6ada9bf96e5ddcfeead994ef646ef35c56347 100644 (file)
@@ -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<LemmyContext>,
     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?;
index 1f997f72f458442b24ef5964f311040a5f65e4a5..d9d7b854549ffd79d5f3ae5415f2f7c8879e7c71 100644 (file)
@@ -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<LemmyContext>,
     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?;
index 20310bc4114a089a3b0c37be3a1de3aedf7113de..9ad54769121d9cd6009254efb43abb6552746d77 100644 (file)
@@ -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<LemmyContext>,
     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())?;
index 95024c475c3c1b3ac609c03e9b6320d33bbcbb4f..ca93b89f0606f998c6c434db154dd9126e6a0025 100644 (file)
@@ -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<LemmyContext>,
     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(())
   }
index 5fb453eef38d87c515f7888224030e72319254cb..9570d85d2199e36d495ece4f0fd53f390553fba7 100644 (file)
@@ -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<LemmyContext>,
     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())?;
index f73c780c2de38670340d54a61f00fac5fe860786..1576e944ccb2c7b436ad42783ecc83dc17d97b80 100644 (file)
@@ -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<LemmyContext>,
     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,
index c4bbbb1bb6596aa4d65a3319740cf3daea9d7d3f..f964da08673a57e311d3aacf54fdd0f7a730fa2d 100644 (file)
@@ -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<LemmyContext>,
     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(())
index 512c074cdc068472a975fc880c994114c80958d1..b0ae72c7168088ba024936a2e5b067865f4fd2a3 100644 (file)
@@ -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<LemmyContext>,
     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
index b37e21fb28cb63883edf95871fd29865393ebaa5..94b0b68ecef5569930fe91b57c12a40c5ed2280c 100644 (file)
@@ -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<LemmyContext>,
     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?;
index 80e319bf0a4c560bc48409beb0f7b5384fb9c47b..f6fc36a2de7e8ca8ee00c846698983ce846c847d 100644 (file)
@@ -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<LemmyContext>,
     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())?;
index 7d07fe8cd978cffc485fe51a50d95e7323e21ec5..e33c956761b9c416ce292a9cfe42166da467a487 100644 (file)
@@ -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<LemmyContext>,
     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)
index 471a7564f5dfc6f5a8b628d26f298085b414ce76..8c7c042c618f957681bb3420ef833fb36f24f248 100644 (file)
@@ -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,
index 155d844060ee01fbc523a6190d26bcd6b0a7b860..5808f81c9ffa1392e8230d04af696fd43bed1dec 100644 (file)
@@ -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 }
index 454debaede4cc932ac15fea9bf620cf1daf1ae4c..f5d6f0eabafd559417bf8f203fd655f7858bffcf 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 454debaede4cc932ac15fea9bf620cf1daf1ae4c
+Subproject commit f5d6f0eabafd559417bf8f203fd655f7858bffcf