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

Comments

drewish’s picture

Version: 4.7.x-1.x-dev » 5.x-1.x-dev
Status: Needs review » Needs work

I'm interested in getting this fixed but you need to submit your changes as a patch: http://drupal.org/patch

h0tw1r3’s picture

Status: Needs work » Needs review
StatusFileSize
new483 bytes

Patch attached based on code above.

drewish’s picture

StatusFileSize
new1.19 KB

testing 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.

drewish’s picture

Status: Needs review » Fixed

had davidstrauss take a look at it on IRC and he though it was okay so i committed it.

pcdonohue’s picture

Status: Fixed » Closed (fixed)

Great,

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

drewish’s picture

Status: Closed (fixed) » Needs review
StatusFileSize
new1.02 KB

missed on avenue of viewing...

drewish’s picture

Status: Needs review » Closed (fixed)

hetta opened up an issue specifically for this so i'm going to move it over there.