Problem/Motivation

The menu callback for 'media/%file/format-form' is linked to view file_entity_access. This access is typically granted to anonymous users. However, the format-form generates multiple derived images. Which opens the door to things like: https://www.drupal.org/SA-CORE-2013-002.

Proposed resolution

Secure using 'access media browser' permission. Why, might you ask use that permission and not create a new one? Because the media wysiwyg is linked to the browser already. If this where a separate permission, it wouldn't make sense.

Remaining tasks

Review patch.

User interface changes

n/a

API changes

n/a

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

heddn’s picture

Patch attached.

heddn’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 1: media_wysiwyg-DoS_image_derivatives-2349977_1.patch, failed testing.

heddn’s picture

Status: Needs work » Needs review
FileSize
590 bytes
2.05 KB

Try this.

heddn’s picture

After a lengthy chat with @azinck off-line, I've moved this to a separate permission tied to Media WYSIWYG module, rather than use media browser. This is so we can add the restricted flag on the permission. Media browser doesn't let anyone generate a list of derivative URLs. But Media WYSIWYG does.

Not sure if this really should be a restricted permission or not, but it does provide a mechanism to harvest a large number of valid image derivative URLs.

I've also written a hook_update to move things over to the new permission from the existing 'view file' permissiion. I pondered for a moment not granting the anonymous RID access. Instead I simply print the updates access from hook_update and leave it to the reader as an exercise to update permissions. It doesn't give any more access to people than previously, so this seems acceptable.

svenryen’s picture

Status: Needs review » Reviewed & tested by the community

I tested the patch and it works as expected. I did a security review which resulted in Access denied for people who had no access.

When the patch was applied, I could no longer load pages like /media/1/format-form unless the permission was set to allow that. Loading the url for a user that did not have the permission resulted in an Access denied message.

Further, running dbupdate resulted in an update DB patch being applied, and it did give access to the format-form to everybody that had access to view files before the update was run.

I also did not see any side-effects after applying the patch to the current dev.

Dave Reid’s picture

  1. +++ b/modules/media_wysiwyg/media_wysiwyg.install
    @@ -18,3 +18,23 @@ function media_wysiwyg_uninstall() {
    + * Accommodate the introduction of a new permission which restricts access to
    + * use media_wysiwyg by granting it to existing users who were able to access
    + * it.
    + */
    

    Needs a one-line summary first.

  2. +++ b/modules/media_wysiwyg/media_wysiwyg.install
    @@ -18,3 +18,23 @@ function media_wysiwyg_uninstall() {
    +  return t('Use Media WYSIWYG permission was granted to: @roles. Visit !link to change these permissions.', array(
    +    '@roles' => check_plain(implode(', ', $roles)),
    +    '!link' => l(t('permissions'), 'admin/people/permissions', array(
    +      'absolute' => TRUE,
    +      'fragment' => 'module-media_wysiwyg',
    +    ))
    +  ));
    +}
    

    Let's leave out the second sentence of this string. Just notifying which roles have new permissions added is the best benefit.

  3. +++ b/modules/media_wysiwyg/media_wysiwyg.module
    @@ -31,13 +31,14 @@ function media_wysiwyg_hook_info() {
    +    'access arguments' => array('use media wysiwyg'),
    

    I wonder if we need a custom access callback that also checks file_entity_access()? Is this a regression if we're not checking that in addition to the new permission?

heddn’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
1.95 KB
3.63 KB

#7.1, #7.2, 7.3 are all addressed.

I've opened a follow-up to update the description in media module as well, from which this was simply a copy. https://www.drupal.org/node/2351377#comment-9221005

izmeez’s picture

Status: Needs review » Needs work

The patch in #8 applies cleanly to the current media-7.x-2.x-dev release and works as expected. It adds a new permission to deny users access to media/%file/format-form

Media WYSIWYG
Use Media WYSIWYG in an editor
Warning: Give to trusted roles only; this permission has security implications.

However, when the patch is applied and creates this new permission it grants access to anonymous users despite the warning. Access should not be granted to anonymous users.

azinck’s picture

Status: Needs work » Needs review
FileSize
3.44 KB
872 bytes

True @izmeez.

I've updated the patch to only grant the permission to roles that have the "access media browser" permission, but there's still a very good chance that that will include anonymous users on many sites, in light of media_update_7226().

I'm torn with this one. If we don't grant it to anons, then we may break some sites, but if we do, then many sites will go needlessly unprotected. And my understanding here of the security concern is not so much strictly a DoS problem as it is a diskspace issue: it makes easy for an attacker to fill your disk with image derivatives. We have to weigh that against the possible damage done by "breaking" sites.

azinck’s picture

And here's a more conservative version of the patch that won't grant the perm to anons.

izmeez’s picture

This approach seems like a good way to go.

And the change in #11 is less code than that in #10 which is usually a good thing.

azinck’s picture

Actually #11 has almost exactly the same amount of code as #10 (less code by just 1 character!) :). Thanks for testing, izmeez.

izmeez’s picture

Just a note, similar to what I posted in #1792738-182: Allow custom file view modes for WYSIWYG display, the patch in this thread has some lines overlapping with the patch in the other thread and depending on which is committed first the other will need a re-roll.

izmeez’s picture

Sorry, I misunderstood, I thought the interdiff in both #10 and #11 was from the patch in #8 rather than incremental.

izmeez’s picture

Status: Needs review » Reviewed & tested by the community

The patch in #11 applies to the current media-7.x-2.x-dev and works as expected. It preserves and uses the access media browser permission and does not allow anonymous users the use media wysiwyg permission.

Thanks. The status is changed to RTBC.

If this patch is committed the patch in #1792738: Allow custom file view modes for WYSIWYG display will need to be re-rolled.

izmeez’s picture

There appears to be a duplicate of this issue at #2337305: Media wysiwyg exposes fields attached to a file entity via media_wysiwyg_format_form callback which maybe could be closed.

  • aaron committed 02b3142 on 7.x-2.x
    Issue #2349977 by heddn, azinck: DoS image derivatives in Media WYSIWYG
    
aaron’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

izmeez’s picture

I have an issue that may be related to this and I will have to open a separate issue. Not sure if it belongs in media or file_entity queue.

Surprised to see on new install anonymous users see content with youtube video as expected but also see above the video a menu with two items, Edit and Delete. These are links to the paths file/%/edit and file/%/delete which since the commit of the patch in this thread returns access denied.

Still it's a surprise to see this menu showing to anonymous users and not showing to admin roles when logged in.

Firebug shows them to be contextual links.

Just looking into this now. Any suggestions are welcome. Thanks.

izmeez’s picture