Problem/Motivation

OnlyofficeDownloadController::download() answers every failure with a JSON error: 401 for a missing or invalid token, 400 for an invalid link key or UUID, 404 when the file entity does not exist and 403 when access is denied. The last step, however, is

return new BinaryFileResponse($file->getFileUri(), 200);

without checking that the file is actually on disk. When the file entity exists but its file is gone (deleted or lost on disk, a database restored without the files directory, an unmounted storage), the BinaryFileResponse constructor throws Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException. The exception is not caught, so the Document Server gets an HTML 500 error page instead of the JSON error it gets for every other failure on this route, and the site logs an uncaught exception for what is a missing-data condition.

Steps to reproduce

  1. Configure the module with a Document Server and create a media item with an office document.
  2. Delete the document's file from disk, keeping the file entity (e.g. remove it from sites/default/files).
  3. Open the media item in ONLYOFFICE, so the Document Server requests the file from the onlyoffice.download route.
  4. The route answers with a 500 error; the log shows FileNotFoundException: The file "…" does not exist.

Expected: a 404 response with the route's JSON error body, as when the file entity is missing.

Proposed resolution

In OnlyofficeDownloadController::download(), check file_exists($file->getFileUri()) after the access check. If the file is missing, log an error and return new JsonResponse(['error' => 1, 'message' => …], 404), the same shape as the existing 404 for a missing file entity.

Remaining tasks

  • Review the merge request.

User interface changes

None.

API changes

None. The route answers 404 with a JSON body instead of a 500 error page when the file is missing.

Data model changes

None.

Text generated with AI

Issue fork onlyoffice-3630200

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

daniel.pernold created an issue. See original summary.

daniel.pernold’s picture

Status: Active » Needs review

Merge request !5 is ready for review.