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) public function webfinger(Request $request)
{ {
abort_if(!config('federation.webfinger.enabled'), 400); if (!config('federation.webfinger.enabled') ||
!$request->has('resource') ||
abort_if(!$request->has('resource') || !$request->filled('resource'), 400); !$request->filled('resource')
) {
return response('', 400);
}
$resource = $request->input('resource'); $resource = $request->input('resource');
$hash = hash('sha256', $resource); $hash = hash('sha256', $resource);
@ -59,14 +62,18 @@ 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, 400); if(strpos($resource, $domain) == false) {
return response('', 400);
}
$parsed = Nickname::normalizeProfileUrl($resource); $parsed = Nickname::normalizeProfileUrl($resource);
if(empty($parsed) || $parsed['domain'] !== $domain) { if(empty($parsed) || $parsed['domain'] !== $domain) {
abort(400); return response('', 400);
} }
$username = $parsed['username']; $username = $parsed['username'];
$profile = Profile::whereNull('domain')->whereUsername($username)->firstOrFail(); $profile = Profile::whereNull('domain')->whereUsername($username)->first();
abort_if($profile->status != null, 400); if(!$profile || $profile->status !== null) {
return response('', 400);
}
$webfinger = (new Webfinger($profile))->generate(); $webfinger = (new Webfinger($profile))->generate();
Cache::put($key, $webfinger, 1209600); Cache::put($key, $webfinger, 1209600);