diff --git a/app/Util/ActivityPub/Helpers.php b/app/Util/ActivityPub/Helpers.php index 349aa49cb..24c83cc87 100644 --- a/app/Util/ActivityPub/Helpers.php +++ b/app/Util/ActivityPub/Helpers.php @@ -6,6 +6,7 @@ use DB, Cache, Purify, Storage, Request, Validator; use App\{ Activity, Follower, + Instance, Like, Media, Notification, @@ -174,6 +175,14 @@ class Helpers { } } + $bannedInstances = Cache::remember('instances:banned:domains', now()->addHours(12), function() { + return Instance::whereBanned(true)->pluck('domain')->toArray(); + }); + + if(in_array($host, $bannedInstances)) { + return false; + } + if(in_array($host, $localhosts)) { return false; } @@ -472,21 +481,24 @@ class Helpers { $profile = Profile::whereRemoteUrl($res['id'])->first(); if(!$profile) { + Instance::firstOrCreate([ + 'domain' => $domain + ]); $profileLockKey = 'helpers:profile-lock:' . hash('sha256', $res['id']); $profile = Cache::lock($profileLockKey)->get(function () use($domain, $webfinger, $res, $runJobs) { return DB::transaction(function() use($domain, $webfinger, $res, $runJobs) { $profile = new Profile(); $profile->domain = strtolower($domain); - $profile->username = strtolower(Purify::clean($webfinger)); + $profile->username = Purify::clean($webfinger); $profile->name = isset($res['name']) ? Purify::clean($res['name']) : 'user'; $profile->bio = isset($res['summary']) ? Purify::clean($res['summary']) : null; $profile->sharedInbox = isset($res['endpoints']) && isset($res['endpoints']['sharedInbox']) ? $res['endpoints']['sharedInbox'] : null; - $profile->inbox_url = strtolower($res['inbox']); - $profile->outbox_url = strtolower($res['outbox']); - $profile->remote_url = strtolower($res['id']); + $profile->inbox_url = $res['inbox']; + $profile->outbox_url = $res['outbox']; + $profile->remote_url = $res['id']; $profile->public_key = $res['publicKey']['publicKeyPem']; $profile->key_id = $res['publicKey']['id']; - $profile->webfinger = strtolower(Purify::clean($webfinger)); + $profile->webfinger = Purify::clean($webfinger); $profile->last_fetched_at = now(); $profile->save(); if(config('pixelfed.cloud_storage') == true) {