From d6f188de23c7eec1a9b479fb4b8c4acbf2d38f7d Mon Sep 17 00:00:00 2001 From: alemi Date: Tue, 31 Dec 2024 17:10:22 +0100 Subject: [PATCH] fix: proper delivery check this should be THE filter, previous one should just be an optimization... --- upub/worker/src/delivery.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/upub/worker/src/delivery.rs b/upub/worker/src/delivery.rs index 3fa4b4e..2c4f79a 100644 --- a/upub/worker/src/delivery.rs +++ b/upub/worker/src/delivery.rs @@ -1,11 +1,18 @@ -use reqwest::Method; - use apb::{LD, ActivityMut}; use upub::{Context, model, traits::Fetcher}; #[allow(clippy::manual_map)] // TODO can Update code be improved? pub async fn process(ctx: Context, job: &model::job::Model) -> crate::JobResult<()> { - tracing::info!("delivering {} to {:?}", job.activity, job.target); + let Some(ref target) = job.target else { + return Err(crate::JobError::Malformed(apb::FieldErr("target"))); // TODO not best error to use.. + }; + + if upub::ext::is_blacklisted(target, &ctx.cfg().reject.delivery) { + tracing::warn!("aborting delivery to {target} due to rejection policies: {:?}", job.payload); + return Ok(()); + } + + tracing::info!("delivering {} to {target}", job.activity); let Some(activity) = model::activity::Entity::find_by_ap_id(&job.activity) .one(ctx.db()) @@ -60,7 +67,7 @@ pub async fn process(ctx: Context, job: &model::job::Model) -> crate::JobResult< }; Context::request( - Method::POST, job.target.as_deref().unwrap_or(""), + reqwest::Method::POST, target, Some(&serde_json::to_string(&payload.ld_context()).unwrap()), &job.actor, &key, ctx.domain() ).await?;