From b50f11a0406458cd58f8cee7e03f12f435a35edc Mon Sep 17 00:00:00 2001 From: Diogo Peralta Cordeiro Date: Wed, 18 Aug 2021 14:34:15 +0100 Subject: [PATCH] [ENTITY][Link] self urls can't be considered a remote url --- src/Entity/Link.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Entity/Link.php b/src/Entity/Link.php index 38f1a27081..18b332f5be 100644 --- a/src/Entity/Link.php +++ b/src/Entity/Link.php @@ -24,6 +24,7 @@ use App\Core\Entity; use App\Core\Event; use App\Core\GSFile; use App\Core\HTTPClient; +use App\Core\Log; use App\Util\Common; use App\Util\Exception\DuplicateFoundException; use App\Util\Exception\NotFoundException; @@ -137,6 +138,12 @@ class Link extends Entity public static function getOrCreate(string $url): self { if (Common::isValidHttpUrl($url)) { + // If the URL is a local one, do not create a Link to it + if (parse_url($url, PHP_URL_HOST) === $_ENV['SOCIAL_DOMAIN']) { + Log::warning("It was attempted to create a Link to a local location {$url}."); + // Forbidden + throw new InvalidArgumentException(message: "A Link can't point to a local location ({$url}), it must be a remote one", code: 400); + } $head = HTTPClient::head($url); // This must come before getInfo given that Symfony HTTPClient is lazy (thus forcing curl exec) try {