PluginProbe
ActivityPub / 3.2.2
ActivityPub v3.2.2
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
← All changes | includes/class-webfinger.php +63 -13 2.0.03.2.2 View file →
@@ -19,13 +19,8 @@
19 19 *
20 20 * @return string The user-resource
21 21 */
22 22 public static function get_user_resource( $user_id ) {
23 - // use WebFinger plugin if installed
24 - if ( \function_exists( '\get_webfinger_resource' ) ) {
25 - return \get_webfinger_resource( $user_id, false );
26 - }
27 -
28 23 $user = Users::get_by_id( $user_id );
29 24 if ( ! $user || is_wp_error( $user ) ) {
30 25 return '';
31 26 }
@@ -46,18 +41,39 @@
46 41 if ( \is_wp_error( $data ) ) {
47 42 return $data;
48 43 }
49 44
45 + if ( ! is_array( $data ) || empty( $data['links'] ) ) {
46 + return new WP_Error(
47 + 'webfinger_missing_links',
48 + __( 'No valid Link elements found.', 'activitypub' ),
49 + array(
50 + 'status' => 400,
51 + 'data' => $data,
52 + )
53 + );
54 + }
55 +
50 56 foreach ( $data['links'] as $link ) {
51 57 if (
52 58 'self' === $link['rel'] &&
53 - 'application/activity+json' === $link['type']
59 + (
60 + 'application/activity+json' === $link['type'] ||
61 + 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"' === $link['type']
62 + )
54 63 ) {
55 64 return $link['href'];
56 65 }
57 66 }
58 67
59 - return new WP_Error( 'webfinger_url_no_activitypub', null, $data );
68 + return new WP_Error(
69 + 'webfinger_url_no_activitypub',
70 + __( 'The Site supports WebFinger but not ActivityPub', 'activitypub' ),
71 + array(
72 + 'status' => 400,
73 + 'data' => $data,
74 + )
75 + );
60 76 }
61 77
62 78 /**
63 79 * Transform a URI to an acct <identifier>@<host>
@@ -92,9 +108,12 @@
92 108
93 109 return new WP_Error(
94 110 'webfinger_url_no_acct',
95 111 __( 'No acct URI found.', 'activitypub' ),
96 - $data
112 + array(
113 + 'status' => 400,
114 + 'data' => $data,
115 + )
97 116 );
98 117 }
99 118
100 119 /**
@@ -106,8 +125,19 @@
106 125 * @return WP_Error|array Error reaction or array with
107 126 * identifier and host as values
108 127 */
109 128 public static function get_identifier_and_host( $url ) {
129 + if ( ! $url ) {
130 + return new WP_Error(
131 + 'webfinger_invalid_identifier',
132 + __( 'Invalid Identifier', 'activitypub' ),
133 + array(
134 + 'status' => 400,
135 + 'data' => $url,
136 + )
137 + );
138 + }
139 +
110 140 // remove leading @
111 141 $url = ltrim( $url, '@' );
112 142
113 143 if ( ! preg_match( '/^([a-zA-Z+]+):/', $url, $match ) ) {
@@ -133,9 +163,16 @@
133 163 break;
134 164 }
135 165
136 166 if ( empty( $host ) ) {
137 - return new WP_Error( 'webfinger_invalid_identifier', __( 'Invalid Identifier', 'activitypub' ) );
167 + return new WP_Error(
168 + 'webfinger_invalid_identifier',
169 + __( 'Invalid Identifier', 'activitypub' ),
170 + array(
171 + 'status' => 400,
172 + 'data' => $url,
173 + )
174 + );
138 175 }
139 176
140 177 return array( $identifier, $host );
141 178 }
@@ -163,9 +200,13 @@
163 200 if ( $data ) {
164 201 return $data;
165 202 }
166 203
167 - $webfinger_url = 'https://' . $host . '/.well-known/webfinger?resource=' . rawurlencode( $identifier );
204 + $webfinger_url = sprintf(
205 + 'https://%s/.well-known/webfinger?resource=%s',
206 + $host,
207 + rawurlencode( $identifier )
208 + );
168 209
169 210 $response = wp_safe_remote_get(
170 211 $webfinger_url,
171 212 array(
@@ -176,9 +217,12 @@
176 217 if ( is_wp_error( $response ) ) {
177 218 return new WP_Error(
178 219 'webfinger_url_not_accessible',
179 220 __( 'The WebFinger Resource is not accessible.', 'activitypub' ),
180 - $webfinger_url
221 + array(
222 + 'status' => 400,
223 + 'data' => $webfinger_url,
224 + )
181 225 );
182 226 }
183 227
184 228 $body = wp_remote_retrieve_body( $response );
@@ -204,9 +248,12 @@
204 248 if ( empty( $data['links'] ) ) {
205 249 return new WP_Error(
206 250 'webfinger_missing_links',
207 251 __( 'No valid Link elements found.', 'activitypub' ),
208 - $data
252 + array(
253 + 'status' => 400,
254 + 'data' => $data,
255 + )
209 256 );
210 257 }
211 258
212 259 foreach ( $data['links'] as $link ) {
@@ -217,9 +264,12 @@
217 264
218 265 return new WP_Error(
219 266 'webfinger_missing_remote_follow_endpoint',
220 267 __( 'No valid Remote-Follow endpoint found.', 'activitypub' ),
221 - $data
268 + array(
269 + 'status' => 400,
270 + 'data' => $data,
271 + )
222 272 );
223 273 }
224 274
225 275 /**