[backend/federation] Enforce federation control in ActivityFetcherService

With this there should be no remaining ways for new activities from blocked instances to make it into the database.
This commit is contained in:
Laura Hausmann 2024-04-28 18:51:37 +02:00
parent ead8e126f1
commit a7898e8aa9
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -21,7 +21,8 @@ public class ActivityFetcherService(
HttpRequestService httpRqSvc, HttpRequestService httpRqSvc,
SystemUserService systemUserSvc, SystemUserService systemUserSvc,
DatabaseContext db, DatabaseContext db,
ILogger<ActivityFetcherService> logger ILogger<ActivityFetcherService> logger,
FederationControlService fedCtrlSvc
) )
{ {
private static readonly IReadOnlyCollection<string> AcceptableActivityTypes = private static readonly IReadOnlyCollection<string> AcceptableActivityTypes =
@ -78,6 +79,12 @@ public class ActivityFetcherService(
if (requestHost == config.Value.WebDomain || requestHost == config.Value.AccountDomain) if (requestHost == config.Value.WebDomain || requestHost == config.Value.AccountDomain)
throw GracefulException.UnprocessableEntity("Refusing to fetch activity from local domain"); throw GracefulException.UnprocessableEntity("Refusing to fetch activity from local domain");
if (await fedCtrlSvc.ShouldBlockAsync(requestHost))
{
logger.LogDebug("Refusing to fetch activity from blocked instance");
return (null, new Uri(url));
}
var request = httpRqSvc.GetSigned(url, AcceptableActivityTypes, actor, keypair); var request = httpRqSvc.GetSigned(url, AcceptableActivityTypes, actor, keypair);
var response = await client.SendAsync(request); var response = await client.SendAsync(request);