Don't attempt to dereference local objects via http

This commit is contained in:
Jeremy Dormitzer 2019-04-06 13:25:35 -04:00
parent 35241944cf
commit e10b111a4b
2 changed files with 13 additions and 3 deletions

View File

@ -7,6 +7,7 @@ namespace ActivityPub\Objects;
use ActivityPub\Entities\ActivityPubObject;
use ActivityPub\Entities\Field;
use ActivityPub\Utils\DateTimeProvider;
use ActivityPub\Utils\Util;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\QueryBuilder;
use GuzzleHttp\Client;
@ -311,13 +312,14 @@ class ObjectsService
*/
public function dereference( $id )
{
// TOOD pass a $request into here, so that I can sign the request below and so that
// I can check for local objects that should not result in network calls
$object = $this->getObject( $id );
if ( $object ) {
return $object;
}
// TODO sign this request?
if ( Util::isLocalUri( $id ) ) {
return null;
}
// TODO sign this request? Would have to pass in the request object to get the actor to sign with
$request = new Request( 'GET', $id, array(
'Accept' => 'application/ld+json; profile="https://www.w3.org/ns/activitystreams"'
) );

View File

@ -2,6 +2,8 @@
namespace ActivityPub\Utils;
use Symfony\Component\HttpFoundation\Request;
class Util
{
/**
@ -32,5 +34,11 @@ class Util
}
return true;
}
public static function isLocalUri( $uri )
{
$request = Request::createFromGlobals();
return parse_url( $uri, PHP_URL_HOST ) === $request->getHost();
}
}