1
0
Fork 1
mirror of https://github.com/pixelfed/pixelfed.git synced 2024-12-27 02:06:52 +00:00

Update FederationController, fix webfinger endpoint

This commit is contained in:
Daniel Supernault 2022-03-23 00:58:21 -06:00
parent afe903c36e
commit a0e15d89e2
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

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