Skip to content

Commit

Permalink
Merge pull request Automattic#153 from pfefferle/fix-webfinger
Browse files Browse the repository at this point in the history
  • Loading branch information
pfefferle authored Jun 4, 2022
2 parents 2977cef + b3aefc6 commit c63de35
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ services:
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DEBUG: 1
11 changes: 6 additions & 5 deletions includes/rest/class-webfinger.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ public static function register_routes() {
public static function webfinger( $request ) {
$resource = $request->get_param( 'resource' );

$matches = array();
$matched = \preg_match( '/^acct:([^@]+)@(.+)$/', $resource, $matches );
$matched = \str_contains( $resource, '@' );

if ( ! $matched ) {
return new \WP_Error( 'activitypub_unsupported_resource', \__( 'Resource is invalid', 'activitypub' ), array( 'status' => 400 ) );
}

$resource_identifier = $matches[1];
$resource_host = $matches[2];
$resource = \str_replace( 'acct:', '', $resource );

$resource_identifier = \substr( $resource, 0, \strrpos( $resource, '@' ) );
$resource_host = \substr( \strrchr( $resource, '@' ), 1 );

if ( \wp_parse_url( \home_url( '/' ), \PHP_URL_HOST ) !== $resource_host ) {
return new \WP_Error( 'activitypub_wrong_host', \__( 'Resource host does not match blog host', 'activitypub' ), array( 'status' => 404 ) );
Expand Down Expand Up @@ -97,7 +98,7 @@ public static function request_parameters() {
$params['resource'] = array(
'required' => true,
'type' => 'string',
'pattern' => '^acct:([^@]+)@(.+)$',
'pattern' => '^acct:(.+)@(.+)$',
);

return $params;
Expand Down

0 comments on commit c63de35

Please sign in to comment.