| @@ -45,9 +45,12 @@ | ||
| 45 | 45 | if ( ! is_array( $data ) || empty( $data['links'] ) ) { |
| 46 | 46 | return new WP_Error( |
| 47 | 47 | 'webfinger_missing_links', |
| 48 | 48 | __( 'No valid Link elements found.', 'activitypub' ), |
| 49 | - $data | |
| 49 | + array( | |
| 50 | + 'status' => 400, | |
| 51 | + 'data' => $data, | |
| 52 | + ) | |
| 50 | 53 | ); |
| 51 | 54 | } |
| 52 | 55 | |
| 53 | 56 | foreach ( $data['links'] as $link ) { |
| @@ -52,9 +55,12 @@ | ||
| 52 | 55 | |
| 53 | 56 | foreach ( $data['links'] as $link ) { |
| 54 | 57 | if ( |
| 55 | 58 | 'self' === $link['rel'] && |
| 56 | - '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 | + ) | |
| 57 | 63 | ) { |
| 58 | 64 | return $link['href']; |
| 59 | 65 | } |
| 60 | 66 | } |
| @@ -61,9 +67,12 @@ | ||
| 61 | 67 | |
| 62 | 68 | return new WP_Error( |
| 63 | 69 | 'webfinger_url_no_activitypub', |
| 64 | 70 | __( 'The Site supports WebFinger but not ActivityPub', 'activitypub' ), |
| 65 | - $data | |
| 71 | + array( | |
| 72 | + 'status' => 400, | |
| 73 | + 'data' => $data, | |
| 74 | + ) | |
| 66 | 75 | ); |
| 67 | 76 | } |
| 68 | 77 | |
| 69 | 78 | /** |
| @@ -99,9 +108,12 @@ | ||
| 99 | 108 | |
| 100 | 109 | return new WP_Error( |
| 101 | 110 | 'webfinger_url_no_acct', |
| 102 | 111 | __( 'No acct URI found.', 'activitypub' ), |
| 103 | - $data | |
| 112 | + array( | |
| 113 | + 'status' => 400, | |
| 114 | + 'data' => $data, | |
| 115 | + ) | |
| 104 | 116 | ); |
| 105 | 117 | } |
| 106 | 118 | |
| 107 | 119 | /** |
| @@ -113,8 +125,19 @@ | ||
| 113 | 125 | * @return WP_Error|array Error reaction or array with |
| 114 | 126 | * identifier and host as values |
| 115 | 127 | */ |
| 116 | 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 | + | |
| 117 | 140 | // remove leading @ |
| 118 | 141 | $url = ltrim( $url, '@' ); |
| 119 | 142 | |
| 120 | 143 | if ( ! preg_match( '/^([a-zA-Z+]+):/', $url, $match ) ) { |
| @@ -140,9 +163,16 @@ | ||
| 140 | 163 | break; |
| 141 | 164 | } |
| 142 | 165 | |
| 143 | 166 | if ( empty( $host ) ) { |
| 144 | - 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 | + ); | |
| 145 | 175 | } |
| 146 | 176 | |
| 147 | 177 | return array( $identifier, $host ); |
| 148 | 178 | } |
| @@ -170,9 +200,9 @@ | ||
| 170 | 200 | if ( $data ) { |
| 171 | 201 | return $data; |
| 172 | 202 | } |
| 173 | 203 | |
| 174 | - $webfinger_url = 'https://' . $host . '/.well-known/webfinger?resource=' . rawurlencode( $identifier ); | |
| 204 | + $webfinger_url = sprintf( 'https://%s/.well-known/webfinger?resource=%s', $host, rawurlencode( $identifier ) ); | |
| 175 | 205 | |
| 176 | 206 | $response = wp_safe_remote_get( |
| 177 | 207 | $webfinger_url, |
| 178 | 208 | array( |
| @@ -183,9 +213,12 @@ | ||
| 183 | 213 | if ( is_wp_error( $response ) ) { |
| 184 | 214 | return new WP_Error( |
| 185 | 215 | 'webfinger_url_not_accessible', |
| 186 | 216 | __( 'The WebFinger Resource is not accessible.', 'activitypub' ), |
| 187 | - $webfinger_url | |
| 217 | + array( | |
| 218 | + 'status' => 400, | |
| 219 | + 'data' => $webfinger_url, | |
| 220 | + ) | |
| 188 | 221 | ); |
| 189 | 222 | } |
| 190 | 223 | |
| 191 | 224 | $body = wp_remote_retrieve_body( $response ); |
| @@ -211,9 +244,12 @@ | ||
| 211 | 244 | if ( empty( $data['links'] ) ) { |
| 212 | 245 | return new WP_Error( |
| 213 | 246 | 'webfinger_missing_links', |
| 214 | 247 | __( 'No valid Link elements found.', 'activitypub' ), |
| 215 | - $data | |
| 248 | + array( | |
| 249 | + 'status' => 400, | |
| 250 | + 'data' => $data, | |
| 251 | + ) | |
| 216 | 252 | ); |
| 217 | 253 | } |
| 218 | 254 | |
| 219 | 255 | foreach ( $data['links'] as $link ) { |
| @@ -224,9 +260,12 @@ | ||
| 224 | 260 | |
| 225 | 261 | return new WP_Error( |
| 226 | 262 | 'webfinger_missing_remote_follow_endpoint', |
| 227 | 263 | __( 'No valid Remote-Follow endpoint found.', 'activitypub' ), |
| 228 | - $data | |
| 264 | + array( | |
| 265 | + 'status' => 400, | |
| 266 | + 'data' => $data, | |
| 267 | + ) | |
| 229 | 268 | ); |
| 230 | 269 | } |
| 231 | 270 | |
| 232 | 271 | /** |