Issue Feature Accepted Quiet Good first issue

#104364Add restrictions for sys_file_storage (better restrict file access when dealing with private storages)

Jan Kornblum 07/11/24, 12:01 updated 10/18/26, 15:57

Description

When working with “private” storages (outside web root), access to any file from frontend context (typolink, image view helper, etc.) is automatically handled by core using the “eID=dumpFile” functionality. So access to any file is (theoretically) always possible when the token is known (or guessed). This is misleading and confusing, people might not be aware of this!

In my opinion, an integrator or developer should be able to rely on, that when making a storage physically “private”, there is absolutely no file access possible per default. Please add a storage restriction as Oliver suggests below.

Reviews 1

Fix this issue

Start the commit message of your patch with this. Add what the patch does, and the versions it goes to in "Releases:". The changes above were merged or abandoned: read them before you start. How to create a patch

Commit message
[FEATURE] Add restrictions for sys_file_storage (better restrict file access when dealing with private storages) Resolves: #104364 Releases: main

History 1113

  1. Jan Kornblum changed subject Better restrict frontend file access when dealing with private storages Better restrict file access when dealing with private storages <span data-processor="relativetime" data-value="2024-07-25T15:01:10+00:00" > 07/25/24, 15:01 </span>

  2. Oliver Hader commented <span data-processor="relativetime" data-value="2025-01-22T12:43:32+00:00" > 01/22/25, 12:43 </span>

    Having a rate-limiter that catches the invalid requests (most probably brute force, since the HMAC token did not match) seems to be very useful.

    However, for additional restrictions, there probably should be a new configuration for file storages – the current “is publicly available” is misleading and was interpreted differently in the past.

    Thus, there might be a new sys_file_storage.content_restriction which could be

    • complete/full → no file content can be retrieved by file-dump-controller, nor are any thumbnails generated
      • just the meta-data in sys_file can be accessed via the backend user interface
      • individual implementations still can use the FAL low-level API directly to retrieve file contents
      • having this complete/full mode should be discussed further
    • granted-backend-users → only backend users with corresponding permissions can retrieve file content in the UI
      • always requires an active backend user session
      • always requires, that the current user has granted permission to the file-mount at the time of accessing file contents
    • no-restriction → file contents can always be retrieved
      • that’s basically the current situation in eID=dumpFile (FileDumpController)
  3. Andreas Kießling commented <span data-processor="relativetime" data-value="2025-05-24T11:34:52+00:00" > 05/24/25, 11:34 </span>

    Would be great to see some progress here.

    I wanted to make use of the ModifyFileDumpEvent to restrict access to frontend uploads via EXT:form and a “private storage” so only backend users can access the files.
    But as far is i can tell it is invoked too early in the middleware chain and no frontend or backend user logins are ready at that moment. For performance this might make sense, but then adding access checks seems cumbersome

  4. Jan Kornblum commented <span data-processor="relativetime" data-value="2025-05-24T12:51:05+00:00" > 05/24/25, 12:51 </span>

    Olivers idea about introducing a new sys_file_storage.content_restriction withs these three options would be really great! I suppose in this context a new middleware to handle this (instead of the eID) is required, in addition with a new event, where both backend user object as well as frontend user objects are available (if existing), to be used by developers in their own implementations.

  5. Jan Kornblum changed subject Better restrict file access when dealing with private storages Add restrictions for sys_file_storage (better restrict file access when dealing with private storages) <span data-processor="relativetime" data-value="2026-03-02T13:49:16+00:00" > 03/02/26, 13:49 </span>

  6. Markus Timtner commented and changed done 0 % 90 % Complexity easy <span data-processor="relativetime" data-value="2026-07-09T13:34:08+00:00" > 07/09/26, 13:34 </span>

    Hi there!

    I just found this issue here, because i have a working fix for that.
    The requirement was, that a file should ONLY be accessible for logged in Backend users, in a private file storage outside of the webroot.

    Since I found out that the eID link is still accessible when not logged in, I created this extension-based EventListener:

    <?php
    
    declare(strict_types=1);
    
    namespace My\Sitepackage\EventListener;
    
    use Psr\Http\Message\ResponseFactoryInterface;
    use TYPO3\CMS\Core\Attribute\AsEventListener;
    use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
    use TYPO3\CMS\Core\Resource\Event\ModifyFileDumpEvent;
    use TYPO3\CMS\Core\Utility\GeneralUtility;
    
    #[AsEventListener(identifier: 'sitepackage/restrict-file-dump-to-be-users')]
    final readonly class RestrictFileDumpToBackendUsers
    {
        private const PROTECTED_STORAGE_UID = 2;
    
        public function __construct(
            private ResponseFactoryInterface $responseFactory,
        ) {}
    
        public function __invoke(ModifyFileDumpEvent $event): void
        {
            if ($event->getFile()->getStorage()->getUid() !== self::PROTECTED_STORAGE_UID) {
                return;
            }
    
            $beUser = $GLOBALS['BE_USER'] ?? null;
            if (!$beUser instanceof BackendUserAuthentication) {
                $beUser = GeneralUtility::makeInstance(BackendUserAuthentication::class);
                $beUser->start($event->getRequest());
            }
    
            if (empty($beUser->user['uid'])) {
                $loginUrl = '/typo3/login?redirect_url=' . rawurlencode((string)$event->getRequest()->getUri());
                $event->setResponse(
                    $this->responseFactory->createResponse(302)->withHeader('Location', $loginUrl)
                );
            }
        }
    }

    Works as intended – right now with redirect to login if unauthorized.

    Only things left to do is:
    - make the file storage configurable so it includes EVERY private file storage
    - and find the right place in the core for that.

    Any help is appreciated, lets fix this!