diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index 0be2e0d849..3b93348643 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -1,11 +1,8 @@ isKnown()) { + throw new Exception(Exception::AVATAR_REMOTE_URL_FAILED); + } + + $fetch = @\file_get_contents($url); if (!$fetch) { throw new Exception(Exception::AVATAR_IMAGE_NOT_FOUND); @@ -326,6 +333,12 @@ App::get('/v1/avatars/favicon') throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Imagick extension is missing'); } + $domain = new Domain(\parse_url($url, PHP_URL_HOST)); + + if (!$domain->isKnown()) { + throw new Exception(Exception::AVATAR_REMOTE_URL_FAILED); + } + $curl = \curl_init(); \curl_setopt_array($curl, [ @@ -399,6 +412,12 @@ App::get('/v1/avatars/favicon') $outputExt = 'ico'; } + $domain = new Domain(\parse_url($outputHref, PHP_URL_HOST)); + + if (!$domain->isKnown()) { + throw new Exception(Exception::AVATAR_REMOTE_URL_FAILED); + } + if ('ico' == $outputExt) { // Skip crop, Imagick isn\'t supporting icon files $data = @\file_get_contents($outputHref, false); @@ -545,8 +564,6 @@ App::get('/v1/avatars/initials') $image->setImageFormat("png"); $image->compositeImage($punch, Imagick::COMPOSITE_COPYOPACITY, 0, 0); - //$image->setImageCompressionQuality(9 - round(($quality / 100) * 9)); - $response ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)) . ' GMT') // 45 days cache ->setContentType('image/png') diff --git a/tests/e2e/Services/Avatars/AvatarsBase.php b/tests/e2e/Services/Avatars/AvatarsBase.php index e2ddc1a863..1652e01514 100644 --- a/tests/e2e/Services/Avatars/AvatarsBase.php +++ b/tests/e2e/Services/Avatars/AvatarsBase.php @@ -287,26 +287,6 @@ trait AvatarsBase $this->assertEquals('image/png', $response['headers']['content-type']); $this->assertNotEmpty($response['body']); - // $response = $this->client->call(Client::METHOD_GET, '/avatars/favicon', [ - // 'x-appwrite-project' => $this->getProject()['$id'], - // ], [ - // 'url' => 'https://www.bbc.com/', - // ]); - - // $this->assertEquals(200, $response['headers']['status-code']); - // $this->assertEquals('image/png', $response['headers']['content-type']); - // $this->assertNotEmpty($response['body']); - - // $response = $this->client->call(Client::METHOD_GET, '/avatars/favicon', [ - // 'x-appwrite-project' => $this->getProject()['$id'], - // ], [ - // 'url' => 'https://edition.cnn.com/', - // ]); - - // $this->assertEquals(200, $response['headers']['status-code']); - // $this->assertEquals('image/x-icon', $response['headers']['content-type']); - // $this->assertNotEmpty($response['body']); - /** * Test for FAILURE */ @@ -326,6 +306,14 @@ trait AvatarsBase $this->assertEquals(404, $response['headers']['status-code']); + $response = $this->client->call(Client::METHOD_GET, '/avatars/favicon', [ + 'x-appwrite-project' => $this->getProject()['$id'], + ], [ + 'url' => 'http://localhost', + ]); + + $this->assertEquals(404, $response['headers']['status-code']); + return []; }