Problem/Motivation
Forgive me if this issue has been covered by some of the other issues linked to from #2821423: Dealing with unexpected file deletion due to incorrect file usage but I couldn't find this specific case listed anywhere.
The issue stems from the fact that file usage is only tracked on an entity's id, not the specific revision that a file is being used in. This can lead to instances where a file uploaded to the private file system and linked to via a text/text_long/text_with_summary field is still accessible in an unpublished revision.
Steps to reproduce:
1) Upload a file to a field that stores files in the private file system
2) Reference that file in a text field (like the body field on a node) (we'll call this Node A)
3) Delete the file from the field you previously uploaded it to
4) Create a new revision of Node A, deleting the link to the file in the text field and unpublishing the old revision (WBM or CM may be required here)
5) Make sure the new revision of Node A is published
6) Attempt to access the file by path directly
Expected:
File is inaccessible as it isn't referenced by a published revision.
Actual:
File is accessible due to editor's implementation of hook_file_download. This gathers usage via \Drupal::service('file.usage')->listUsage($file); and checks whether the user is able to view the entity. Since the entity is published, and it only loads the current revision, the user is able to access the file.
The use case for needing to deny access to these files comes back to what the private file system is usually used for: limiting access to files. If a file has been removed and a new version has been uploaded, but the previous version was once linked to in a text field then it should not be accessible.
Proposed resolution
TBD
Comments
Comment #2
cilefen commentedThis seems almost like #2887988: Translation of file count is incorrect or #1239558: Deleting an entity with revisions and file/image field does not release file usage of non-default revisions, causing files to linger.
I advise adding a comment on #2821423: Dealing with unexpected file deletion due to incorrect file usage mentioning this issue
to get some eyes on it.
Comment #3
acbramley commentedThanks @cilefen will do!
Comment #11
smustgrave commented@acbramley wonder if those other issues addressed this?
Comment #12
acbramley commentedUnfortunately not, I can still reproduce this on HEAD.
Comment #13
seth h commentedThis issue has an inverse effect as well, namely that when a new file is uploaded to an unpublished revision on a previously published entity, that file is permanently access denied.
Example: A draft update to some node has updated the file, and the reviewing user wants to check the file contents before marking the revision as published.
This is caused by the fact that the published revision is loaded when loading file references in `file_get_file_references()`.
There is even a comment documenting this.
Comment #15
benjifisherThis issue was temporarily un-published by the security team. After some discussion, we decided that having the files remain in the filesystem is something that can be discussed in public, so I am re-publishing this issue. See https://www.drupal.org/psa-2023-07-12.
Comment #16
prudloff commented