Closed (fixed)
Project:
Protected Node
Version:
7.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Unassigned
Reporter:
Created:
19 Nov 2013 at 07:06 UTC
Updated:
15 Mar 2014 at 19:40 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
grimreaperHello,
Here is a patch that should solve the problem, but I think it's should be improved.
The problem was from the $uri which is wrong when it's an image generated from an image style so $files was void and so the hook returned -1 to prevent access.
Please test because if the return -1 is not returned when the user shouldnot have access. the user will have access to your files.
Comment #2
izus commentedwhat do you mean by uri is wrong when the image is a derivative of private one ? doesn't it have the private streamwrapper in the uri ?
also i think the patch is making all the image derivatives bypass the protection which may not be really what all users need. i think the image derivatives should be accessible only when the original image is accessible too
also 'styles' is not a directory name we can relay, in case of privatefiles/tshirts/styles/pdf we can bypass the protection by error
Comment #3
izus commentedComment #4
grimreaperOk,
About the $uri, in the case of the file, it matches the uri stored in the table file_managed so file_load_multiple returns the file. In the case of a derivative, $uri doesn't match the uri stored in the table so it returns nothing so you don't go in the loops and the hook return -1.
About the patch, I would prefer to have the fid to load the file, but it seems the hook_file_download only have uri in parameter. And I don't know if I could get the fid starting from a derivative.
Comment #5
grimreaperHello,
I think I found the clean solution in the image.module file line 280 where its implements the hook_file_download.
Thanks for the review.
Comment #6
ishworthapaliya commentedHi!
Thanks for the patch. I will try it out and update about the results here.
Comment #7
izus commentedHi ishworthapaliya,
Did the patch in #5 work well for you ?
Thanks
Comment #8
ishworthapaliya commentedHi izus,
Unfortunately i haven't had time to try it out because of the other projects that i am working with. I will test it out as soon as i can and inform here.
Comment #9
grimreaperI have remade a patch because the last one was not applyable anymore.
Comment #10
ishworthapaliya commentedHi Grimreaper and Izus,
I finally had time to test the patch #9 and it is working as it should be working i.e. private image styles are accessible after the password is entered.
Thanks a lot!
Comment #11
grimreaperThanks ishworthapaliya for testing.
Comment #12
izus commentedline 702 : we can even check if it starts with private://styles i guess ?
lines 702 to 712, i think we need a helper function that gets an image derivative uri and returns the original file uri, it would be easier to read :)
Comment #13
izus commentedComment #14
grimreaperHum, I wrote the patch two months ago, so line 702 I need to check.
I remember I took exactly what the module image in core used to deal with the private image. As said in #5, so if you want I put it in an helper function, ok as you want.
Comment #15
grimreaperline 702 : no, $path starts with style, ex : styles/medium/private/field/image/toto.jpg
Now, you have the choice, a patch with an helper function or not :).
Comment #16
izus commentedwe're close :) and as we'e close we find non issued bugs yet !
There is something we miss here, we should only do this for private files (and their derivatives if the file is of image type) if they belong only to protected nodes. i think a way to do this is checking is $uri starts with private:// (this should wrapp all the code of this hook i think) and for image derivatives that should start with private://styles
you should do it in two paragraphs with a blank line (https://drupal.org/coding-standards/docs#general) and the @see tag (https://drupal.org/coding-standards/docs#see) for documentation here refering the function name protected_node_file_download
Comment #17
izus commentedComment #18
grimreaper1) This hook is only triggered by private files. https://api.drupal.org/api/drupal/modules!system!system.api.php/function...
I test putting a dpm at the very beginning of the function. with a node with two image field, one private, one public, only the private field triggers the hook.
And if I unprotect the node, I don't pass in the hook for both public or private image.
2) Is it better now ?
Comment #19
izus commentedthis is now merged.
Thank you