Issue Bug Closed

#106890Replacing a file in filelist with different file extension

Georg Ringer 06/16/25, 08:39 updated 12/02/25, 14:21

Description

Replacing an existing file with one of a different file extension is not possible anymore but totally valid, e.g. jpg with a png

current error:
> Mime-type “image/jpeg” not allowed for file extension “png”.

Reviews 3

History 1324

  1. Oliver Hader commented <span data-processor="relativetime" data-value="2025-06-16T12:47:29+00:00" > 06/16/25, 12:47 </span>

    What is the “valid” use-case for replacing contents having the type image/jpeg to a file with .png extension?
    Probably I’m overlooking something here. Please provide a step by step example to understand the scenario. Thanks!

  2. Georg Ringer commented <span data-processor="relativetime" data-value="2025-06-16T13:10:03+00:00" > 06/16/25, 13:10 </span>

    1st: Typical usecase is:

    1. Client provides somewhere an image of a product as jpg
    2. The image is used on multiple images
    3. The quality of the jpg is bad, now a png is provided and all usages need to be changed

    2nd: Sometimes I even got clients how changed a pdf to a zip and vice versa as those files are used for creating downloads.
    3rd: What also now not working is renaming a file, like a test.txt to test.csv. Just some not so helpful message “Resource consistency check failed” is shown

  3. Markus Klein commented <span data-processor="relativetime" data-value="2025-06-16T13:42:14+00:00" > 06/16/25, 13:42 </span>

    I’m fully with Georg here. Users have the need to replace an image at all places. (Sometimes even for legal reasons.)

    Of course there might be scenarios where replacing a file with some other mime-type file can cause issues.
    But I have a hard time weighing “absolute security by tool” with “practical needs” here.
    (I tend to lean towards the second.)

  4. Garvin Hicking commented <span data-processor="relativetime" data-value="2025-06-16T14:05:45+00:00" > 06/16/25, 14:05 </span>

    Could we just validate the “new file” against the allowed mimetypes, and not do comparison of oldmime == newmime? So if I want to replace an image with a pdf, as long as the pdf is not a forbidden filetype&mime mapping, it could go through?

    (If not by default, at least with a feature.backend.allowHotMimeReplacement switch?)

  5. Oliver Hader commented <span data-processor="relativetime" data-value="2025-06-17T08:16:51+00:00" > 06/17/25, 08:16 </span>

    The problem in the user interface is, that “replace file” actually performs two operations:

    • replacing the existing file object with the uploaded contents (e.g. file.pdf gets new contents of image/png → which obviously fails)
    • renaming the existing file object to match the uploaded file (e.g. file.pdf with contents of image/png to be renamed to file.png)

    For solving this, a new storage method has to be introduced that reflects both of the mentioned operations.
    This is not a discussion about security, but a discussion about poor API design in the file abstraction layer.

  6. Gerrit Code Review pushed patch set 1 for main to change 89740 status Accepted Under Review <span data-processor="relativetime" data-value="2025-06-17T10:13:35+00:00" > 06/17/25, 10:13 </span>

  7. Oliver Hader commented <span data-processor="relativetime" data-value="2025-06-17T10:18:54+00:00" > 06/17/25, 10:18 </span>

    I’ve added a WIP patch which combines the replace-and-rename FAL operation.

    Besides that, the handling for “keep the current filename” has been adjusted (keeping whatever.pdf for an image/png contents already would have failed in a browser, the new behavior adjusts the file extension, resulting in whatever.png for this example).

  8. Denis Mir commented <span data-processor="relativetime" data-value="2025-07-02T12:03:03+00:00" > 07/02/25, 12:03 </span>

    One additional use case is that an old “doc” file gets replace by a “docx” file. This happens pretty regularly for some of our customers.

  9. Mathias Brodala commented <span data-processor="relativetime" data-value="2025-07-02T13:03:51+00:00" > 07/02/25, 13:03 </span>

    Denis Mir wrote in #note-10:
    > One additional use case is that an old “doc” file gets replace by a “docx” file. This happens pretty regularly for some of our customers.

    That’s the same usecase, a completely different file extension and completely different MIME type. Even if they looks similar to humans. ;-)

  10. Oliver Hader commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2025-07-08T08:45:09+00:00" > 07/08/25, 08:45 </span>

    Applied in changeset commit:cf227b18e205a3720599f07ac98a8747c7008398.