Honor preference order in webfinger links

This commit is contained in:
Hypolite Petovan 2018-11-10 08:23:11 -05:00
parent 10a8be7943
commit 94a71d9ffc

View file

@ -979,7 +979,9 @@ class Probe
{ {
$hcard_url = ""; $hcard_url = "";
$data = []; $data = [];
foreach ($webfinger["links"] as $link) { // The array is reversed to take into account the order of preference for same-rel links
// See: https://tools.ietf.org/html/rfc7033#section-4.4.4
foreach (array_reverse($webfinger["links"]) as $link) {
if (($link["rel"] == NAMESPACE_DFRN) && !empty($link["href"])) { if (($link["rel"] == NAMESPACE_DFRN) && !empty($link["href"])) {
$data["network"] = Protocol::DFRN; $data["network"] = Protocol::DFRN;
} elseif (($link["rel"] == NAMESPACE_FEED) && !empty($link["href"])) { } elseif (($link["rel"] == NAMESPACE_FEED) && !empty($link["href"])) {
@ -1182,7 +1184,9 @@ class Probe
{ {
$hcard_url = ""; $hcard_url = "";
$data = []; $data = [];
foreach ($webfinger["links"] as $link) { // The array is reversed to take into account the order of preference for same-rel links
// See: https://tools.ietf.org/html/rfc7033#section-4.4.4
foreach (array_reverse($webfinger["links"]) as $link) {
if (($link["rel"] == "http://microformats.org/profile/hcard") && !empty($link["href"])) { if (($link["rel"] == "http://microformats.org/profile/hcard") && !empty($link["href"])) {
$hcard_url = $link["href"]; $hcard_url = $link["href"];
} elseif (($link["rel"] == "http://joindiaspora.com/seed_location") && !empty($link["href"])) { } elseif (($link["rel"] == "http://joindiaspora.com/seed_location") && !empty($link["href"])) {
@ -1283,7 +1287,9 @@ class Probe
$pubkey = ""; $pubkey = "";
if (is_array($webfinger["links"])) { if (is_array($webfinger["links"])) {
foreach ($webfinger["links"] as $link) { // The array is reversed to take into account the order of preference for same-rel links
// See: https://tools.ietf.org/html/rfc7033#section-4.4.4
foreach (array_reverse($webfinger["links"]) as $link) {
if (($link["rel"] == "http://webfinger.net/rel/profile-page") if (($link["rel"] == "http://webfinger.net/rel/profile-page")
&& (defaults($link, "type", "") == "text/html") && (defaults($link, "type", "") == "text/html")
&& ($link["href"] != "") && ($link["href"] != "")
@ -1447,7 +1453,9 @@ class Probe
private static function pumpio($webfinger, $addr) private static function pumpio($webfinger, $addr)
{ {
$data = []; $data = [];
foreach ($webfinger["links"] as $link) { // The array is reversed to take into account the order of preference for same-rel links
// See: https://tools.ietf.org/html/rfc7033#section-4.4.4
foreach (array_reverse($webfinger["links"]) as $link) {
if (($link["rel"] == "http://webfinger.net/rel/profile-page") if (($link["rel"] == "http://webfinger.net/rel/profile-page")
&& (defaults($link, "type", "") == "text/html") && (defaults($link, "type", "") == "text/html")
&& ($link["href"] != "") && ($link["href"] != "")