Update FederationController

This commit is contained in:
Daniel Supernault 2022-01-09 15:09:37 -07:00
parent 93196e57a0
commit 4ab99d66d1
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -50,7 +50,7 @@ class FederationController extends Controller
{ {
abort_if(!config('federation.webfinger.enabled'), 400); abort_if(!config('federation.webfinger.enabled'), 400);
abort_if(!$request->filled('resource'), 400); abort_if(!$request->has('resource') || !$request->filled('resource'), 400);
$resource = $request->input('resource'); $resource = $request->input('resource');
$hash = hash('sha256', $resource); $hash = hash('sha256', $resource);
@ -59,14 +59,14 @@ class FederationController extends Controller
return response()->json($cached, 200, [], JSON_UNESCAPED_SLASHES); return response()->json($cached, 200, [], JSON_UNESCAPED_SLASHES);
} }
$domain = config('pixelfed.domain.app'); $domain = config('pixelfed.domain.app');
abort_if(strpos($resource, $domain) == false, 404); abort_if(strpos($resource, $domain) == false, 400);
$parsed = Nickname::normalizeProfileUrl($resource); $parsed = Nickname::normalizeProfileUrl($resource);
if(empty($parsed) || $parsed['domain'] !== $domain) { if(empty($parsed) || $parsed['domain'] !== $domain) {
abort(404); abort(400);
} }
$username = $parsed['username']; $username = $parsed['username'];
$profile = Profile::whereNull('domain')->whereUsername($username)->firstOrFail(); $profile = Profile::whereNull('domain')->whereUsername($username)->firstOrFail();
abort_if($profile->status != null, 404); abort_if($profile->status != null, 400);
$webfinger = (new Webfinger($profile))->generate(); $webfinger = (new Webfinger($profile))->generate();
Cache::put($key, $webfinger, 1209600); Cache::put($key, $webfinger, 1209600);