From 9e375f9325d007e31b766edd3cc989e271b07540 Mon Sep 17 00:00:00 2001
From: Oliver Bartsch <bo@cedev.de>
Date: Wed, 20 Sep 2023 22:29:01 +0200
Subject: [PATCH] [BUGFIX] Prevent exception on fetching online media id
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

In case a user does not have access to the physical
file, containing the online media id, this does no
longer lead to an exception, which would e.g. prevent
the user from accessing any backend module, rendering
a preview for such online media asset.

Resolves: #80210
Releases: main, 12.4
Change-Id: I4c1a3cfdea211dd1775e57796584416ab7df05d5
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/81117
Reviewed-by: Oliver Klee <typo3-coding@oliverklee.de>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Oliver Bartsch <bo@cedev.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Oliver Bartsch <bo@cedev.de>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: core-ci <typo3@b13.com>
---
 .../OnlineMedia/Helpers/AbstractOnlineMediaHelper.php | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/typo3/sysext/core/Classes/Resource/OnlineMedia/Helpers/AbstractOnlineMediaHelper.php b/typo3/sysext/core/Classes/Resource/OnlineMedia/Helpers/AbstractOnlineMediaHelper.php
index 4c417bca7cee..7ba0534a8eb5 100644
--- a/typo3/sysext/core/Classes/Resource/OnlineMedia/Helpers/AbstractOnlineMediaHelper.php
+++ b/typo3/sysext/core/Classes/Resource/OnlineMedia/Helpers/AbstractOnlineMediaHelper.php
@@ -17,6 +17,8 @@ namespace TYPO3\CMS\Core\Resource\OnlineMedia\Helpers;
 
 use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Resource\DuplicationBehavior;
+use TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException;
+use TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException;
 use TYPO3\CMS\Core\Resource\File;
 use TYPO3\CMS\Core\Resource\Folder;
 use TYPO3\CMS\Core\Resource\Index\FileIndexRepository;
@@ -64,8 +66,13 @@ abstract class AbstractOnlineMediaHelper implements OnlineMediaHelperInterface
             if ($file->getSize() > 2048) {
                 return '';
             }
-            // By definition these files only contain the ID of the remote media source
-            $this->onlineMediaIdCache[$file->getUid()] = trim($file->getContents());
+            try {
+                // By definition these files only contain the ID of the remote media source
+                $this->onlineMediaIdCache[$file->getUid()] = trim($file->getContents());
+            } catch (InsufficientFileAccessPermissionsException | IllegalFileExtensionException $e) {
+                // User has no access to the file - online media id can not be fetched
+                return '';
+            }
         }
         return $this->onlineMediaIdCache[$file->getUid()];
     }
-- 
GitLab