Hi,
accessing an image directly via a call to
http://example.site/drupal/image/view/57
is possible even when access to node 57 is not allowed by drupal's access control. This means that a user without permissions to access the image node via http://example.site/drupal/node/57 can still access the image via the above link. This includes anonymous users, users from different groups (if using og), etc. Not sure if this was an intended feature, but it seems like a bug to me.
image_menu sets the relevant callback in this case
$items[] = array('path' => 'image/view', 'title' => t('image'),
'access' => user_access('access content'),
'type' => MENU_CALLBACK,
'callback' => 'image_fetch');
So as long as a user has privileges to 'access content' (most do) they can access the image via the image/view path, currently there's no check against any other privileges.
I updated image_fetch with a check against the node the image belongs to, returning from the function after a call to drupal_access_denied() if the check fails.
/**
* Fetches an image file, allows "shorthand" image urls such of the form:
* image/view/$nid/$label
* (e.g. image/view/25/thumbnail or image/view/14)
*/
function image_fetch($nid = 0, $size = 'preview') {
if ($nid) {
$node = node_load(array('nid' => $nid));
if (!node_access('view',$node)) { // check against image's parent node
drupal_access_denied();
return;
}
if ($node->images[$size]) {
$file = $node->images[$size];
$headers = image_file_download($file);
file_transfer($file, $headers);
}
}
}
Are there any problems with that?
Patrick
p.s. There was another issue posted for 4.6 at http://drupal.org/node/49881 that is similar but I think has to do with accessing the file directly rather than using the view/image path
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | image_view_original.patch | 1.02 KB | drewish |
| #3 | image.module_86283.patch | 1.19 KB | drewish |
| #2 | image_node_access.patch.txt | 483 bytes | h0tw1r3 |
Comments
Comment #1
drewish commentedI'm interested in getting this fixed but you need to submit your changes as a patch: http://drupal.org/patch
Comment #2
h0tw1r3 commentedPatch attached based on code above.
Comment #3
drewish commentedtesting this out i realized there were a few other bugs in the function. it should be checking permissions for original images and returning proper error messages.
Comment #4
drewish commentedhad davidstrauss take a look at it on IRC and he though it was okay so i committed it.
Comment #5
pcdonohue commentedGreat,
I only just noticed the activity on this patch (despite having been the OP), so thanks for creating and integrating the patch. I don't use the image module anymore, but will probably some day again.
cheers,
Patrick
Comment #6
drewish commentedmissed on avenue of viewing...
Comment #7
drewish commentedhetta opened up an issue specifically for this so i'm going to move it over there.