X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FXrd.php;h=8e314400186269c2ac1c9e73f4bd3d9ff71e4ade;hb=3bca4fe2a64671d09e08346456cdfa6c12f996e9;hp=4e4603fbdb20dcc3848a7d8bc6d98603d9b41eb6;hpb=b5d01337d9ef3f616829956b059ba55a4642798f;p=friendica.git diff --git a/src/Module/Xrd.php b/src/Module/Xrd.php index 4e4603fbdb..8e31440018 100644 --- a/src/Module/Xrd.php +++ b/src/Module/Xrd.php @@ -1,6 +1,6 @@ getArgv()[0] == 'xrd') { if (empty($_GET['uri'])) { @@ -65,15 +67,23 @@ class Xrd extends BaseModule if (substr($uri, 0, 4) === 'http') { $name = ltrim(basename($uri), '~'); + $host = parse_url($uri, PHP_URL_HOST); } else { $local = str_replace('acct:', '', $uri); if (substr($local, 0, 2) == '//') { $local = substr($local, 2); } - $name = substr($local, 0, strpos($local, '@')); + list($name, $host) = explode('@', $local); + } + + if (!empty($host) && $host !== DI::baseUrl()->getHost()) { + DI::logger()->notice('Invalid host name for xrd query',['host' => $host, 'uri' => $uri]); + throw new NotFoundException('Invalid host name for xrd query: ' . $host); } + header('Vary: Accept', false); + if ($name == User::getActorName()) { $owner = User::getSystemAccount(); if (empty($owner)) { @@ -105,7 +115,7 @@ class Xrd extends BaseModule private function printSystemJSON(array $owner) { - $baseURL = $this->baseUrl->get(); + $baseURL = (string)$this->baseUrl; $json = [ 'subject' => 'acct:' . $owner['addr'], 'aliases' => [$owner['url']], @@ -146,12 +156,12 @@ class Xrd extends BaseModule ] ]; header('Access-Control-Allow-Origin: *'); - System::jsonExit($json, 'application/jrd+json; charset=utf-8'); + $this->jsonExit($json, 'application/jrd+json; charset=utf-8'); } private function printJSON(string $alias, array $owner, array $avatar) { - $baseURL = $this->baseUrl->get(); + $baseURL = (string)$this->baseUrl; $json = [ 'subject' => 'acct:' . $owner['addr'], @@ -184,10 +194,6 @@ class Xrd extends BaseModule 'type' => 'text/html', 'href' => $baseURL . '/hcard/' . $owner['nickname'], ], - [ - 'rel' => ActivityNamespace::POCO, - 'href' => $owner['poco'], - ], [ 'rel' => 'http://webfinger.net/rel/avatar', 'type' => $avatar['type'], @@ -227,16 +233,14 @@ class Xrd extends BaseModule ]; header('Access-Control-Allow-Origin: *'); - System::jsonExit($json, 'application/jrd+json; charset=utf-8'); + $this->jsonExit($json, 'application/jrd+json; charset=utf-8'); } private function printXML(string $alias, array $owner, array $avatar) { - $baseURL = $this->baseUrl->get(); - - $xml = null; + $baseURL = (string)$this->baseUrl; - XML::fromArray([ + $xmlString = XML::fromArray([ 'XRD' => [ '@attributes' => [ 'xmlns' => 'http://docs.oasis-open.org/ns/xri/xrd-1.0', @@ -272,56 +276,50 @@ class Xrd extends BaseModule ] ], '5:link' => [ - '@attributes' => [ - 'rel' => 'http://portablecontacts.net/spec/1.0', - 'href' => $owner['poco'] - ] - ], - '6:link' => [ '@attributes' => [ 'rel' => 'http://webfinger.net/rel/avatar', 'type' => $avatar['type'], 'href' => User::getAvatarUrl($owner) ] ], - '7:link' => [ + '6:link' => [ '@attributes' => [ 'rel' => 'http://joindiaspora.com/seed_location', 'type' => 'text/html', 'href' => $baseURL ] ], - '8:link' => [ + '7:link' => [ '@attributes' => [ 'rel' => 'salmon', 'href' => $baseURL . '/salmon/' . $owner['nickname'] ] ], - '9:link' => [ + '8:link' => [ '@attributes' => [ 'rel' => 'http://salmon-protocol.org/ns/salmon-replies', 'href' => $baseURL . '/salmon/' . $owner['nickname'] ] ], - '10:link' => [ + '9:link' => [ '@attributes' => [ 'rel' => 'http://salmon-protocol.org/ns/salmon-mention', 'href' => $baseURL . '/salmon/' . $owner['nickname'] . '/mention' ] ], - '11:link' => [ + '10:link' => [ '@attributes' => [ 'rel' => 'http://ostatus.org/schema/1.0/subscribe', 'template' => $baseURL . '/contact/follow?url={uri}' ] ], - '12:link' => [ + '11:link' => [ '@attributes' => [ 'rel' => 'magic-public-key', 'href' => 'data:application/magic-public-key,' . Salmon::salmonKey($owner['spubkey']) ] ], - '13:link' => [ + '12:link' => [ '@attributes' => [ 'rel' => 'http://purl.org/openwebauth/v1', 'type' => 'application/x-zot+json', @@ -329,10 +327,9 @@ class Xrd extends BaseModule ] ], ], - ], $xml); + ]); header('Access-Control-Allow-Origin: *'); - - System::httpExit($xml->saveXML(), Response::TYPE_XML, 'application/xrd+xml'); + $this->httpExit($xmlString, Response::TYPE_XML, 'application/xrd+xml'); } }