Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Handle when required resource parameter is missing or empty #1951

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/WellKnown/WebfingerHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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'] ?? '';
}
}
Loading