| @@ -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,13 @@ | ||
| 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( | |
| 205 | + 'https://%s/.well-known/webfinger?resource=%s', | |
| 206 | + $host, | |
| 207 | + rawurlencode( $identifier ) | |
| 208 | + ); | |
| 175 | 209 | |
| 176 | 210 | $response = wp_safe_remote_get( |
| 177 | 211 | $webfinger_url, |
| 178 | 212 | array( |
| @@ -183,9 +217,12 @@ | ||
| 183 | 217 | if ( is_wp_error( $response ) ) { |
| 184 | 218 | return new WP_Error( |
| 185 | 219 | 'webfinger_url_not_accessible', |
| 186 | 220 | __( 'The WebFinger Resource is not accessible.', 'activitypub' ), |
| 187 | - $webfinger_url | |
| 221 | + array( | |
| 222 | + 'status' => 400, | |
| 223 | + 'data' => $webfinger_url, | |
| 224 | + ) | |
| 188 | 225 | ); |
| 189 | 226 | } |
| 190 | 227 | |
| 191 | 228 | $body = wp_remote_retrieve_body( $response ); |
| @@ -211,9 +248,12 @@ | ||
| 211 | 248 | if ( empty( $data['links'] ) ) { |
| 212 | 249 | return new WP_Error( |
| 213 | 250 | 'webfinger_missing_links', |
| 214 | 251 | __( 'No valid Link elements found.', 'activitypub' ), |
| 215 | - $data | |
| 252 | + array( | |
| 253 | + 'status' => 400, | |
| 254 | + 'data' => $data, | |
| 255 | + ) | |
| 216 | 256 | ); |
| 217 | 257 | } |
| 218 | 258 | |
| 219 | 259 | foreach ( $data['links'] as $link ) { |
| @@ -224,9 +264,12 @@ | ||
| 224 | 264 | |
| 225 | 265 | return new WP_Error( |
| 226 | 266 | 'webfinger_missing_remote_follow_endpoint', |
| 227 | 267 | __( 'No valid Remote-Follow endpoint found.', 'activitypub' ), |
| 228 | - $data | |
| 268 | + array( | |
| 269 | + 'status' => 400, | |
| 270 | + 'data' => $data, | |
| 271 | + ) | |
| 229 | 272 | ); |
| 230 | 273 | } |
| 231 | 274 | |
| 232 | 275 | /** |