Hi,
I want to allow a role (of admins) to upload any kind of files, so I wrote a little patch that allows "*" as value in the list of accepted extensions. Entering a * there will accept just any file with any extension.

What do you think?

CommentFileSizeAuthor
webfm.all_uploads.patch1.14 KBFrank Steiner

Comments

jvieille’s picture

Subscribing: need this in an official release

should be done also in core upload and all file related modules, but I've seen crazy discussions about such an issue preventing a common sense decision.

robmilne’s picture

I'll consider for the next rev. It is already within the administrators rights to set whatever extension they want anyway, however the caveat here is that a malicious uploader could place an evil file on the server that is 'executed'. I think the wildcard option would have to come with a warning. Maybe the choice of a blacklist (with default extensions) rather than a whitelist?

Frank Steiner’s picture

Hi Ron,
how would that "execution" work? Of course I don't want php files to be uploaded and executed, but I would like to understand how such a file could be executed. Would it be enough to just click on the link?

avpaderno’s picture

Arbitrary extensions for uploaded files are not accepted even in Drupal core modules.
I would implement the feature in the same way it is implemented in Drupal core code.

Frank Steiner’s picture

That's almost unusable at our site. Our research assistants need to upload a bunch of different materials for students, lectures etc. They can't ask me every time to add a new extension when they decided to upload a .dvi or .latex or .ruby or .avi etc. They just need to be able to do it.

avpaderno’s picture

It's enough to ask them which files they upload more frequently, or to make clear which files type you allow them to upload.

Modules code must be thought to generally suit all situations; generally speaking, it is not a good idea to accept a file upload without to know which file type is being uploaded (and how the file can be used in the OS running the web server).

robmilne’s picture

A '*' wildcard could be safely incorporated if I implement special handling of files. One option is to encode the contents of the file into a new .php file that has the first line set to a simple 404 header and exit (so much for php file 'execution'). I haven't tested this so there may be efficiency issues. If I went this route it would probably happen in concert with taking files out of webroot.

Frank Steiner’s picture

> It's enough to ask them which files they upload more frequently,
> or to make clear which files type you allow them to upload.

You are not working at a university I guess :-) I can ask how often I want, they won't know that kind of addon material they use for their next lectures or programming course. They will know one day after I asked.
A university is a very special environment where professors and research assistents must be able to do thinkgs without asking. They finish the web page for the next seminar 5 minutes before the seminar starts and they present the URL in the talk, causing the first students to access it.
This *cannot* be delayed just because I'm not in the office 5 minutes before the seminar starts. They could do it with apache and static html, they must be able to do it with drupal. Especially my boss is not going to discuss if drupal likes it or not, he just tells me he wants to any kind of upload or have a different CMS that allows him to do it. That's the situation and I can't change it :-)

Btw, I'm not asking to allow arbitrary uploads as default. I'm just asking if we can give people the ability to chose it. A blacklist is fine with me, too.

jvieille’s picture

Many file related modules accept "*" (as an option
Stop being paranoid. As long as the responsibility is to the site administrator (by providing a non default option), the Drupal programmers have nothing to be affraid about.

avpaderno’s picture

There must be a reason, if the Default permitted file extensions field used in the File uploads settings page doesn't accept an asterisk like input.

Frank Steiner’s picture

I'm sure there is a reason. But I always prefer the Linux-like "Let the user override whatever he wants" instead of a Mac-like "We tell the user what he wants to do" :-)

jvieille’s picture

I really don't see the background for this. One can always chose the smarter cck Filefield that don't even need a "*" to explicitely remove any constraint:
"Extensions a user can upload to this field. Separate extensions with a space and do not include the leading dot. Leaving this blank will allow users to upload a file with any extension."

It prudently only allows "txt" by default...

avpaderno’s picture

The difference between Drupal, and Linux is that Linux is a OS, not a CMS; the paragon is not appropriate, as an operating system always have more chances to protect itself.

jvieille’s picture

I would agree that modules should try to follow the core general policies.
But here the practice contradicts obsolete or inappropriate policy: Filefield, which is so dangerous and potentially destructive is downloaded 40000 times a week - Web file manager "only" 2500...

If everything that can be misused is to be avoided in core, Drupal should become a set of safe recommendations, letting module developpers bearing all the risks...

I have created an issue against the Core upload module, but WFM might not have to wait for its resolution
http://drupal.org/node/453348

jvieille’s picture

Title: Accept arbitrary extensions for upload » webfm to Accept arbitrary extensions for upload

Any follow up?

Frank Steiner’s picture

I know that Ron is very busy, so I guess this won't be on his hot-topic list. Can you apply the patch yourself or do you have to work with an installation that uses only official releases?

jvieille’s picture

This is just for making maintenance easier:
I have to remember to add the lline each time the module is updated.

Additional reason for this request (I may have mentionned it already): there are not enough space in the field to define more than a dozen of file extensions, though more than hundred extensions are quite popular.

Frank Steiner’s picture

I'm using my own RPM for this which is build from the drupal source, all modules used and about 20 patches. Every time I get an updated module I'm rebuild the RPM, so I never forget to add a patch.

jvieille’s picture

Looks interesting, what is an RPM?

avpaderno’s picture

It's a package file format, mainly used on Linux.

jvieille’s picture

How do you do that?
Does this update a multi-site Drupal install whithout the burden of swithcing off/on modules too?
Is there any recommended ready to use solution for handling that?

Thank you

nhck’s picture

Status: Needs review » Needs work

Thank you all for helping to make webfm better and sharing your thoughts!

Basically this requires some kind of detection of the content - if a server executable file would be uploaded (e.g. php or server side includes) the security of the server could be compromised - thats the problem.
I understand your peoples need on the other hand - the only way I see to implement this is to make use of mimedetect or to implement filefield directly as requested in #206322: Web File Manager File Field for CCK and more extensively discussed in #446818: Use the Drupal "files" Table for file records.

Now I would rather like a filefield implementation, but if someone provides a mimedetect implement which requires mimedetect as an optional module it would be fine. Until then this is a "needs work", sorry :-/

Still thank you all for your work!

jvieille’s picture

In case it would help, I switched to File Framework and all my problems vanished.
For this particular situation, it invokes an antivirus to authorize an upload (just a side feature among an extravagant package). All constraints are configurable.

nhck’s picture

Status: Needs work » Closed (works as designed)
Frank Steiner’s picture

> Basically this requires some kind of detection of the content - if a server executable file would be
> uploaded (e.g. php or server side includes) the security of the server could be compromised -
> thats the problem.

So what? If an admin decides to allow "php" as valid extension you should not prevent that because there might be situations where php files should be uploaded, how could you know... And if php files can be uploaded when one allows the .php extension why shouldn't it be possible if one allows *every* extension?

This discussion is a typical case of "He, I know better than you what you want to do". Of course you don't, but it doesn't matter that much because everybody is free to apply a little patch to his own system.

avpaderno’s picture

Not even the Drupal core Upload module allows to set arbitrary extensions; you need to explicitly set the extensions you accept, without the possibility of using wild-chars.
If Drupal core code doesn't offer that possibility, there must be a reason.

jvieille’s picture

These are age old obsolete practices. Extensions are not by far a reliable means to detect a possible threat.
File Framework does not restrict upload by default and check files using the available server antivirus (Clamav for example)
For paranoid people, an optional module allows any kind of restrictions.

cgmonroe’s picture

WARNING: SOAPBOX ON.. lol

IMHO, protecting security ignorant people from themselves is a high priority in any PhP application. There is enough perception out there that PhP is unsecure because of all the hacked PhP sites (like phpNuke and it's ilk). Drupal has a good reputation for being secure (enough that Whitehouse.gov is using it...), but if Drupal sites start being hacked because of "I know what I'm doing so I turned off security" problems, the perception will be that Drupal is unsecure... even thought it was the admin who was at fault. Personally, protecting the Drupal's security reputation by being conservative on stuff like this is much more important than making it convenient for the few cases that *NEED* take chances with wildcard extensions.

SOAPBOX OFF...

That said, IF a file upload module was to allow any extension, I'd expect there to be a couple of golden rules:

1) If enabled, a test to see if there is security in place that disallows direct access. E.g. that .htaccess blocks direct URL calls to any uploaded .php files. E.g., the admin screen does an ajax call to test if the file store is "open" or not. If open access is allowed, you can't use it.

The reason behind this is to prevent people from executing malicious code on your server. E.g. uploading a php file that will change the admin password via direct database calls, then running it via calling the direct web url which makes the uploaded php file execute in on your server. The .htaccess will make files only available via the webfm URLs.

This doesn't protect the users who DL and run Trojan exes from your site, but at least your site won't easily be hacked.

2) That there is a big WARNING: DO NOT USE UNLESS YOU KNOW WHAT YOU ARE DOING! message... possibly with multiple "Yes I'm REALLY sure" confirmations. Just to make sure people turning this on at least think about the security implications and not just the usability / convenience side of things.

Just my 2$/EU worth.

vascot’s picture

Status: Closed (works as designed) » Needs work

Would be a nice feature. I have many different extensions here. To add all 26^3 possible 3 char combinations is from optimal. cgmonroe already give some simple handguides to make it secure.

nhck’s picture

Status: Needs work » Closed (won't fix)