diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php
index 8c0c656d4e8e1266857b15db7c8860a6d817a6ff..cbdd618b9e449e9c5d9ec711bd2d73424203813b 100644
--- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php
+++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php
@@ -2571,31 +2571,34 @@ class GeneralUtility
      */
     public static function getFileAbsFileName($filename)
     {
-        if ((string)$filename === '') {
+        $fileName = (string)$filename;
+        if ($fileName === '') {
             return '';
         }
-        // Extension
-        if (PathUtility::isExtensionPath($filename)) {
+        $checkForBackPath = fn (string $fileName): string => $fileName !== '' && static::validPathStr($fileName) ? $fileName : '';
+
+        // Extension "EXT:" path resolving.
+        if (PathUtility::isExtensionPath($fileName)) {
             try {
-                $filename = ExtensionManagementUtility::resolvePackagePath($filename);
-            } catch (PackageException $e) {
-                $filename = '';
-            }
-        } elseif (!PathUtility::isAbsolutePath($filename)) {
-            // is relative. Prepended with the public web folder
-            $filename = Environment::getPublicPath() . '/' . $filename;
-        } elseif (!(
-            str_starts_with($filename, Environment::getProjectPath())
-                  || str_starts_with($filename, Environment::getPublicPath())
-        )) {
-            // absolute, but set to blank if not allowed
-            $filename = '';
-        }
-        if ((string)$filename !== '' && static::validPathStr($filename)) {
-            // checks backpath.
-            return $filename;
+                $fileName = ExtensionManagementUtility::resolvePackagePath($fileName);
+            } catch (PackageException) {
+                $fileName = '';
+            }
+            return $checkForBackPath($fileName);
         }
-        return '';
+
+        // Absolute path, but set to blank if not inside allowed directories.
+        if (PathUtility::isAbsolutePath($fileName)) {
+            if (str_starts_with($fileName, Environment::getProjectPath()) ||
+                str_starts_with($fileName, Environment::getPublicPath())) {
+                return $checkForBackPath($fileName);
+            }
+            return '';
+        }
+
+        // Relative path. Prepend with the public web folder.
+        $fileName = Environment::getPublicPath() . '/' . $fileName;
+        return $checkForBackPath($fileName);
     }
 
     /**