Disable spam detection when importing activities from outbox

This commit is contained in:
silverpill 2023-04-12 20:33:34 +00:00 committed by Rafael Caricio
parent 1092319f6e
commit 01cefa6ea1
Signed by: rafaelcaricio
GPG key ID: 3C86DBCE8E93C947
2 changed files with 19 additions and 12 deletions

View file

@ -657,7 +657,7 @@ pub async fn handle_note(
Ok(post) Ok(post)
} }
async fn is_unsolicited_message( pub async fn is_unsolicited_message(
db_client: &impl DatabaseClient, db_client: &impl DatabaseClient,
instance_url: &str, instance_url: &str,
object: &Object, object: &Object,
@ -678,9 +678,9 @@ async fn is_unsolicited_message(
} }
#[derive(Deserialize)] #[derive(Deserialize)]
struct CreateNote { pub struct CreateNote {
actor: String, pub actor: String,
object: Object, pub object: Object,
} }
pub async fn handle_create( pub async fn handle_create(
@ -692,12 +692,6 @@ pub async fn handle_create(
let activity: CreateNote = serde_json::from_value(activity) let activity: CreateNote = serde_json::from_value(activity)
.map_err(|_| ValidationError("invalid object"))?; .map_err(|_| ValidationError("invalid object"))?;
let object = activity.object; let object = activity.object;
let instance = config.instance();
if is_unsolicited_message(db_client, &instance.url(), &object).await? {
log::warn!("unsolicited message rejected: {}", object.id);
return Ok(None);
};
// Verify attribution // Verify attribution
let author_id = get_object_attributed_to(&object)?; let author_id = get_object_attributed_to(&object)?;
@ -716,7 +710,7 @@ pub async fn handle_create(
}; };
import_post( import_post(
db_client, db_client,
&instance, &config.instance(),
&MediaStorage::from(config), &MediaStorage::from(config),
object_id, object_id,
object_received, object_received,

View file

@ -25,7 +25,11 @@ use super::handlers::{
accept::handle_accept, accept::handle_accept,
add::handle_add, add::handle_add,
announce::handle_announce, announce::handle_announce,
create::handle_create, create::{
handle_create,
is_unsolicited_message,
CreateNote,
},
delete::handle_delete, delete::handle_delete,
follow::handle_follow, follow::handle_follow,
like::handle_like, like::handle_like,
@ -320,6 +324,15 @@ pub async fn receive_activity(
}; };
}; };
if activity_type == CREATE {
let CreateNote { object, .. } = serde_json::from_value(activity.clone())
.map_err(|_| ValidationError("invalid object"))?;
if is_unsolicited_message(db_client, &config.instance_url(), &object).await? {
log::warn!("unsolicited message rejected: {}", object.id);
return Ok(());
};
};
if let ANNOUNCE | CREATE | DELETE | MOVE | UNDO | UPDATE = activity_type { if let ANNOUNCE | CREATE | DELETE | MOVE | UNDO | UPDATE = activity_type {
// Add activity to job queue and release lock // Add activity to job queue and release lock
IncomingActivityJobData::new(activity, is_authenticated) IncomingActivityJobData::new(activity, is_authenticated)