diff --git a/lib/WellKnown/WebfingerHandler.php b/lib/WellKnown/WebfingerHandler.php index fee8c4b28..ff3559eaf 100644 --- a/lib/WellKnown/WebfingerHandler.php +++ b/lib/WellKnown/WebfingerHandler.php @@ -97,6 +97,12 @@ public function handle( */ public function handleWebfinger(IRequestContext $context, ?IResponse $previousResponse): ?IResponse { $subject = $this->getSubjectFromRequest($context->getHttpRequest()); + + // the `resource` parameter is required + if ($subject === '') { + return new JrdResponse('', Http::STATUS_BAD_REQUEST); + } + if (str_starts_with($subject, 'acct:')) { $subject = substr($subject, 5); } @@ -216,8 +222,11 @@ private function getSubjectFromRequest(IRequest $request): string { // work around to extract resource: // on some setup (i.e. tests) the data are not available from IRequest - parse_str(parse_url($request->getRequestUri(), PHP_URL_QUERY), $query); - + $requestUri = $request->getRequestUri(); + if ($requestUri !== '') { + parse_str(parse_url($requestUri, PHP_URL_QUERY) ?? '', $query); + } + return $query['resource'] ?? ''; } }