The function checks view access for the view, if that is not granted, then access is explicitly denied.

file_file_download() already checks and supports download access operation. If you implement a custom file access check, it only works if you return access allowed for both view *and* download.

download vs view is weird anyway, but having to support both is even weirder :)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Berdir created an issue. See original summary.

Berdir’s picture

Berdir’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: remove-2799897-2.patch, failed testing.

The last submitted patch, 2: remove-2799897-2.patch, failed testing.

manarth’s picture

Related in 7.x-2.x: #2351691: Access denied when downloading private files - decide if file_entity_file_download() should deny access by default or not

The current behavior in 7.x-2.x is to return NULL ("no opinion"), rather than -1 ("deny access"), so the behaviour of the 8.x-2.x branch is different to the 7.x-2.x branch.

The change in 7.x-2.x occurred in commit 5b5e5a5.

It might be worth initially switching the 8.x behavior to simply match the 7.x branch, then taking a longer view on whether a more complete sweeping change should be applied to both branches. The comments in #2351691: Access denied when downloading private files - decide if file_entity_file_download() should deny access by default or not suggest that there are quite a few differing opinions on the best way forward.

dwkitchen’s picture

Title: remove file_entity_file_download? » Simplify file_entity_file_download?
Status: Needs work » Needs review
FileSize
729 bytes

What I think we need to remove here is the access check; this is managed by FileEntityAccessControlHandler. We can still add the file_entitiy information to the headers though.

On an aside FileEntityAccessControlHandler checks access based on 'download' permission and this uses 'view' causing a conflict.

Berdir’s picture

Status: Needs review » Needs work

I don't think we should remove it completely, that's definitely not secure.

file_file_download() uses 'view', so possibly we should use the same. I honestly don't know what the difference between those two operations is. It could be view file/ID vs. downloading the file but the problem is that core already does it in the wrong way and we can't easily change that.

dwkitchen’s picture

Hi @Berdir

I created another patch with a link to this one but forgot to back link.

https://www.drupal.org/node/2892628

I'll have a look a file_file_download()

joseph.olstad’s picture

Status: Needs work » Needs review

requeue

Wim Leers’s picture

file_file_download() uses 'view'

That's not true since #2078473: Use entity access API for checking access to private files, which was committed July 24, 2014:

if (!$file->access('download')) {

In fact, zero mentions of the string 'view' in file.module.

EDIT: I'm talking about D8 of course. In D7, it is indeed using 'view', because before #2078473, D8 was too.

David_Rothstein’s picture

If you implement a custom file access check, it only works if you return access allowed for both view *and* download.

Seems like a bug to me...

Note that the related issue (#2892628: Improve file download access control) is currently marked as a bug.

hanoii’s picture

Category: Task » Bug report
FileSize
887 bytes

Based on #11, #12 and after reviewing this and #2892628: Improve file download access control I do think that we are better off removing the hook and let file_file_download handle that part, this module's access control handler will take precedence.

The headers are not necessary, they are also added by that hook.

Re-rolling #2 mostly so that it takes more relevance in the discussion.

Also uploaded an alternative to the mentioned issue: #2892628-6: Improve file download access control.

Status: Needs review » Needs work

The last submitted patch, 13: 2799897-n13.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.