Skip to content

Commit 9b1f820

Browse files
committed
Images: Forced intervention loading via specific method
Updated image loading for intervention library to be via a specific 'initFromBinary' method to avoid being overly accepting of input types and mechansisms. For CVE-2023-6199
1 parent 2fb873f commit 9b1f820

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

app/Config/app.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@
141141
// Third party service providers
142142
Barryvdh\DomPDF\ServiceProvider::class,
143143
Barryvdh\Snappy\ServiceProvider::class,
144-
Intervention\Image\ImageServiceProvider::class,
145144
SocialiteProviders\Manager\ServiceProvider::class,
146145

147146
// BookStack custom service providers
@@ -161,9 +160,6 @@
161160
// Laravel Packages
162161
'Socialite' => Laravel\Socialite\Facades\Socialite::class,
163162

164-
// Third Party
165-
'ImageTool' => Intervention\Image\Facades\Image::class,
166-
167163
// Custom BookStack
168164
'Activity' => BookStack\Facades\Activity::class,
169165
'Theme' => BookStack\Facades\Theme::class,

app/Uploads/ImageResizer.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@
66
use Exception;
77
use GuzzleHttp\Psr7\Utils;
88
use Illuminate\Support\Facades\Cache;
9+
use Intervention\Image\Gd\Driver;
910
use Intervention\Image\Image as InterventionImage;
10-
use Intervention\Image\ImageManager;
1111

1212
class ImageResizer
1313
{
1414
protected const THUMBNAIL_CACHE_TIME = 604_800; // 1 week
1515

1616
public function __construct(
17-
protected ImageManager $intervention,
1817
protected ImageStorage $storage,
1918
) {
2019
}
@@ -117,7 +116,7 @@ public function resizeImageData(
117116
?string $format = null,
118117
): string {
119118
try {
120-
$thumb = $this->intervention->make($imageData);
119+
$thumb = $this->interventionFromImageData($imageData);
121120
} catch (Exception $e) {
122121
throw new ImageUploadException(trans('errors.cannot_create_thumbs'));
123122
}
@@ -144,6 +143,17 @@ public function resizeImageData(
144143
return $thumbData;
145144
}
146145

146+
/**
147+
* Create an intervention image instance from the given image data.
148+
* Performs some manual library usage to ensure image is specifically loaded
149+
* from given binary data instead of data being misinterpreted.
150+
*/
151+
protected function interventionFromImageData(string $imageData): InterventionImage
152+
{
153+
$driver = new Driver();
154+
return $driver->decoder->initFromBinary($imageData);
155+
}
156+
147157
/**
148158
* Orientate the given intervention image based upon the given original image data.
149159
* Intervention does have an `orientate` method but the exif data it needs is lost before it

0 commit comments

Comments
 (0)