(fix): harden image preview against image-bomb DoS

Bump appwrite/base to 1.4.4, which ships a hardened ImageMagick policy
(50KP width/height caps, 4GiB disk, 120s time, PS/PDF/SVG/HTTP coders
disabled). Reject oversized images before decode with a dedicated
storage_image_resolution_exceeded error instead of the opaque
storage_file_type_unsupported wrapper.
This commit is contained in:
Chirag Aggarwal committed 2026-07-03 17:43:13 +05:30
1 parent 81fa1f7bd2
commit 4edd2b9eef
6 files changed
+51 -1

No files matched your search

+1 -1
View File
@@ -12,7 +12,7 @@ RUN composer install --ignore-platform-reqs --optimize-autoloader \
--no-plugins --no-scripts --prefer-dist \
`if [ "$TESTING" != "true" ]; then echo "--no-dev"; fi`
FROM appwrite/base:1.4.3 AS base
FROM appwrite/base:1.4.4 AS base
LABEL maintainer="team@appwrite.io"
+5
View File
@@ -512,6 +512,11 @@ return [
'description' => 'The given file extension is not supported.',
'code' => 400,
],
Exception::STORAGE_IMAGE_RESOLUTION_EXCEEDED => [
'name' => Exception::STORAGE_IMAGE_RESOLUTION_EXCEEDED,
'description' => 'The image resolution exceeds the maximum allowed for processing.',
'code' => 400,
],
Exception::STORAGE_INVALID_FILE_SIZE => [
'name' => Exception::STORAGE_INVALID_FILE_SIZE,
'description' => 'The file size is either not valid or exceeds the maximum allowed size. Please check the file or the value of the _APP_STORAGE_LIMIT environment variable.',
+1
View File
@@ -151,6 +151,7 @@ class Exception extends \Exception
public const string STORAGE_DEVICE_NOT_FOUND = 'storage_device_not_found';
public const string STORAGE_FILE_EMPTY = 'storage_file_empty';
public const string STORAGE_FILE_TYPE_UNSUPPORTED = 'storage_file_type_unsupported';
public const string STORAGE_IMAGE_RESOLUTION_EXCEEDED = 'storage_image_resolution_exceeded';
public const string STORAGE_INVALID_FILE_SIZE = 'storage_invalid_file_size';
public const string STORAGE_INVALID_FILE = 'storage_invalid_file';
public const string STORAGE_BUCKET_ALREADY_EXISTS = 'storage_bucket_already_exists';
@@ -240,6 +240,19 @@ class Get extends Action
$decompressionTime = \microtime(true) - $startTime - $downloadTime - $decryptionTime;
$maxWidth = \Imagick::getResourceLimit(\Imagick::RESOURCETYPE_WIDTH);
$maxHeight = \Imagick::getResourceLimit(\Imagick::RESOURCETYPE_HEIGHT);
$dimensions = \getimagesizefromstring($source);
if (
$dimensions !== false &&
(($maxWidth > 0 && $dimensions[0] > $maxWidth) || ($maxHeight > 0 && $dimensions[1] > $maxHeight))
) {
throw new Exception(
Exception::STORAGE_IMAGE_RESOLUTION_EXCEEDED,
\sprintf('Image resolution %dx%d exceeds the maximum allowed %dx%d pixels', $dimensions[0], $dimensions[1], $maxWidth, $maxHeight)
);
}
try {
$image = new Image($source);
} catch (\Exception $e) {
@@ -892,6 +892,37 @@ trait StorageBase
$this->assertEquals(404, $file8['headers']['status-code']);
}
public function testFilePreviewOversized(): void
{
$data = $this->setupBucketFile();
$bucketId = $data['bucketId'];
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', array_merge([
'content-type' => 'multipart/form-data',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'fileId' => ID::unique(),
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/disk-a/image-bomb.png'), 'image/png', 'image-bomb.png'),
'permissions' => [
Permission::read(Role::any()),
Permission::update(Role::any()),
Permission::delete(Role::any()),
],
]);
$this->assertEquals(201, $file['headers']['status-code']);
$this->assertNotEmpty($file['body']['$id']);
$preview = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $file['body']['$id'] . '/preview', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(400, $preview['headers']['status-code']);
$this->assertEquals(Exception::STORAGE_IMAGE_RESOLUTION_EXCEEDED, $preview['body']['type']);
$this->assertStringContainsString('60000x1', $preview['body']['message']);
}
public function testFilePreviewCache(): void
{
$data = $this->setupBucketFile();
Binary file not shown.

After

Width:  |  Height:  |  Size: 138 B