mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
fix: extend hostname validation to screenshots, image, and webhook worker
Applies the PublicHostname validator (added by fix-host-validation) to the remaining call sites: avatars/screenshots, avatars/image, and the webhook delivery worker. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
2f94ff0f98
commit
ec5b4ca565
3 files changed
+35
-6
No files matched your search
@@ -3,6 +3,7 @@
|
||||
namespace Appwrite\Platform\Modules\Avatars\Http\Image;
|
||||
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\Network\Validator\PublicHostname;
|
||||
use Appwrite\Platform\Modules\Avatars\Http\Action;
|
||||
use Appwrite\SDK\AuthType;
|
||||
use Appwrite\SDK\ContentType;
|
||||
@@ -69,10 +70,19 @@ class Get extends Action
|
||||
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Imagick extension is missing');
|
||||
}
|
||||
|
||||
$domain = new Domain(\parse_url($url, PHP_URL_HOST));
|
||||
$host = \parse_url($url, PHP_URL_HOST) ?? '';
|
||||
|
||||
if (!$domain->isKnown()) {
|
||||
throw new Exception(Exception::AVATAR_REMOTE_URL_FAILED);
|
||||
$isIpLiteral = \filter_var(\trim($host, '[]'), FILTER_VALIDATE_IP) !== false;
|
||||
if (!$isIpLiteral) {
|
||||
$domain = new Domain($host);
|
||||
if (!$domain->isKnown()) {
|
||||
throw new Exception(Exception::AVATAR_REMOTE_URL_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
$hostnameValidator = new PublicHostname();
|
||||
if (!$hostnameValidator->isValid($host)) {
|
||||
throw new Exception(Exception::AVATAR_REMOTE_URL_FAILED, $hostnameValidator->getDescription());
|
||||
}
|
||||
|
||||
$client = new Client();
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Appwrite\Platform\Modules\Avatars\Http\Screenshots;
|
||||
|
||||
use Appwrite\Extend\Exception;
|
||||
use Appwrite\Network\Validator\PublicHostname;
|
||||
use Appwrite\Platform\Modules\Avatars\Http\Action;
|
||||
use Appwrite\SDK\AuthType;
|
||||
use Appwrite\SDK\ContentType;
|
||||
@@ -95,10 +96,19 @@ class Get extends Action
|
||||
throw new Exception(Exception::GENERAL_SERVER_ERROR, 'Imagick extension is missing');
|
||||
}
|
||||
|
||||
$domain = new Domain(\parse_url($url, PHP_URL_HOST));
|
||||
$host = \parse_url($url, PHP_URL_HOST) ?? '';
|
||||
|
||||
if (!$domain->isKnown()) {
|
||||
throw new Exception(Exception::AVATAR_REMOTE_URL_FAILED);
|
||||
$isIpLiteral = \filter_var(\trim($host, '[]'), FILTER_VALIDATE_IP) !== false;
|
||||
if (!$isIpLiteral) {
|
||||
$domain = new Domain($host);
|
||||
if (!$domain->isKnown()) {
|
||||
throw new Exception(Exception::AVATAR_REMOTE_URL_FAILED);
|
||||
}
|
||||
}
|
||||
|
||||
$hostnameValidator = new PublicHostname();
|
||||
if (!$hostnameValidator->isValid($host)) {
|
||||
throw new Exception(Exception::AVATAR_REMOTE_URL_FAILED, $hostnameValidator->getDescription());
|
||||
}
|
||||
|
||||
$client = new Client();
|
||||
|
||||
@@ -6,6 +6,7 @@ use Appwrite\Event\Message\Mail as MailMessage;
|
||||
use Appwrite\Event\Message\Usage as UsageMessage;
|
||||
use Appwrite\Event\Publisher\Mail as MailPublisher;
|
||||
use Appwrite\Event\Publisher\Usage as UsagePublisher;
|
||||
use Appwrite\Network\Validator\PublicHostname;
|
||||
use Appwrite\Template\Template;
|
||||
use Appwrite\Usage\Context as UsageContext;
|
||||
use Exception;
|
||||
@@ -101,6 +102,14 @@ class Webhooks extends Action
|
||||
}
|
||||
|
||||
$url = \rawurldecode($webhook->getAttribute('url'));
|
||||
|
||||
$host = \parse_url($url, PHP_URL_HOST) ?? '';
|
||||
$hostnameValidator = new PublicHostname();
|
||||
if (!$hostnameValidator->isValid($host)) {
|
||||
$this->errors[] = 'Webhook target ' . $host . ' rejected: ' . $hostnameValidator->getDescription();
|
||||
return;
|
||||
}
|
||||
|
||||
$signatureKey = $webhook->getAttribute('signatureKey');
|
||||
$signature = base64_encode(hash_hmac('sha1', $url . $payload, $signatureKey, true));
|
||||
$httpUser = $webhook->getAttribute('httpUser');
|
||||
|
||||
Reference in new issue
Block a user