Skip to content

Commit 6017a39

Browse files
committed
Add HTTP signatures to WebFinger requests
Some ActivityPub implementations like GoToSocial require HTTP signatures for all requests, including WebFinger lookups. Previously, WebFinger requests were made without signatures, causing 401 Unauthorized errors when trying to resolve mentions for users on these platforms. This updates Webfinger::get_data() to use Http::get() which includes HTTP signature authentication, while using a filter to override the Accept header to the WebFinger-appropriate application/jrd+json. Fixes #2593.
1 parent a93eeb4 commit 6017a39

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

includes/class-webfinger.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +215,16 @@ public static function get_data( $uri ) {
215215
\rawurlencode( $identifier )
216216
);
217217

218-
$response = \wp_safe_remote_get(
219-
$webfinger_url,
220-
array(
221-
'headers' => array( 'Accept' => 'application/jrd+json' ),
222-
)
223-
);
218+
$set_accept_header = function ( $args ) {
219+
$args['headers']['Accept'] = 'application/jrd+json';
220+
return $args;
221+
};
222+
223+
\add_filter( 'http_request_args', $set_accept_header );
224+
$response = Http::get( $webfinger_url );
225+
\remove_filter( 'http_request_args', $set_accept_header );
224226

225-
if ( \is_wp_error( $response ) || \wp_remote_retrieve_response_code( $response ) >= 400 ) {
227+
if ( \is_wp_error( $response ) ) {
226228
return new \WP_Error(
227229
'webfinger_url_not_accessible',
228230
__( 'The WebFinger Resource is not accessible.', 'activitypub' ),

0 commit comments

Comments
 (0)