Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
"Imaginary: disable document processing by default"
Signed-off-by: ernolf <[email protected]>
  • Loading branch information
ernolf committed Jul 11, 2024
commit 2aa30d3c5df8bb5f2530a8e26b257f4c7f990853
11 changes: 11 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,17 @@
*/
'preview_imaginary_key' => 'secret',

/**
* Due to security concerns, Imaginary does not process document files by default.
* The following mimetypes are always processed:
* bmp, x-bitmap, png, jpeg, gif, heic, heif, svg+xml, tiff and webp
*
* Set to ``true`` to enable processing of documents of type pdf and illustrator.
*
* Defaults to ``false``
*/
'imaginary_process_documents' => false,
Comment on lines +1317 to +1319
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Defaults to ``false``
*/
'imaginary_process_documents' => false,
* Defaults to ``true``
*/
'imaginary_process_documents' => true,


/**
* Only register providers that have been explicitly enabled
*
Expand Down
19 changes: 18 additions & 1 deletion lib/private/Preview/Imaginary.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,15 @@ public function getMimeType(): string {
}

public static function supportedMimeTypes(): string {
return '/(image\/(bmp|x-bitmap|png|jpeg|gif|heic|heif|svg\+xml|tiff|webp)|application\/(pdf|illustrator))/';
$config = \OC::$server->getConfig();
// Check if processing of documents is enabled
$processDocuments = $config->getSystemValueBool('imaginary_process_documents', false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$processDocuments = $config->getSystemValueBool('imaginary_process_documents', false);
$processDocuments = $config->getSystemValueBool('imaginary_process_documents', true);


if ($processDocuments) {
return '/(image\/(bmp|x-bitmap|png|jpeg|gif|heic|heif|svg\+xml|tiff|webp)|application\/(pdf|illustrator))/';
} else {
return '/(image\/(bmp|x-bitmap|png|jpeg|gif|heic|heif|svg\+xml|tiff|webp))/';
}
}

public function getCroppedThumbnail(File $file, int $maxX, int $maxY, bool $crop): ?IImage {
Expand Down Expand Up @@ -81,8 +89,17 @@ public function getCroppedThumbnail(File $file, int $maxX, int $maxY, bool $crop
$mimeType = 'png';
break;
case 'image/svg+xml':
$convert = true;
// Converted files do not need to be autorotated
$autorotate = false;
$mimeType = 'png';
break;
case 'application/pdf':
case 'application/illustrator':
// Check if processing of documents is enabled
if (!$this->config->getSystemValueBool('imaginary_process_documents', false)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (!$this->config->getSystemValueBool('imaginary_process_documents', false)) {
if (!$this->config->getSystemValueBool('imaginary_process_documents', true)) {

return null;
}
$convert = true;
// Converted files do not need to be autorotated
$autorotate = false;
Expand Down