In #594518: file_munge_filename() doc mentions watchdog but shouldn't the Doxygen documentation for file_munge_filename() was improved. However, it still does not answer the obvious questions:

  1. When should filenames be munged?
  2. Why is “exploit.php.pps” a dangerous name?
  3. Which extensions may be left unaltered without compromising security?

I don't know the answers to these questions myself.

Comments

jhodgdon’s picture

Me neither, but I'll see what I can find out.

robeano’s picture

dww describes the reason #693084-73: Regression: file_munge_filename() extension handling broken by move to File Field which I am copying and pasting here for ease of use:

If Apache doesn't recognize the file type it'll skip the extension and keep moving on until it finds one it recognizes. If filename is filename.php.pps and Apache doesn't recognize pps then it'll execute the file as a PHP file resulting in a possible hacked server. My understanding is that file munging is done to protect such a scenario.

This answers #2 in the Description.

jhodgdon’s picture

And it answers #1 as well. That seems like a good thing to add to the doc.

It also answers #3: anything Apache recognizes should be added to $extensions.

Good thing to add to the doc...

jhodgdon’s picture

Status: Active » Needs review
StatusFileSize
new1.67 KB

Here's a patch for the doc for file_munge_filename(), which incorporates the information from #2 to answer the questions posed in this issue report. Hopefully.

dale42’s picture

This information is excellent and answers the questions to the degree they need answering. #3 isn't explicitly answered, but I think that's OK in this context.

The voice is somewhat passive, I suggest changing to active form:

Munging a file name prevents unknown file extensions from masking
exploit files. When web servers such as Apache
decide how to process a URL request, they use the file extension. If
the extension is not recognized, Apache skips that extension and uses
the previous file extension. For example, if the file being requested
is exploit.php.pps, and Apache does not recognize the '.pps' extension, it
treats the file as PHP and executes it. To make this file name safe for
Apache and prevent it from executing as PHP, the .php extension is "munged"
into .php_, making the safe file name exploit.php_.pps.

Specifically, this function adds an underscore to all extensions that are between 2 and 5
characters in length, internal to the file name, and not included in
$extensions. If variable 'allow_insecure_uploads' evaluates to TRUE, no
alterations will be made.

Last line seems like it's just tacked on, and it's important. Maybe:

Specifically, this function adds an underscore to all extensions that are between 2 and 5
characters in length, internal to the file name, and not included in
$extensions.

Function behavior is controlled by the variable 'allow_insecure_uploads'. If 'allow_insecure_uploads' evaluates to TRUE, no
alterations will be made, if it evaluates to FALSE, the filename is 'munged'.

jhodgdon’s picture

So make a new patch?

dale42’s picture

Sorry for being wishy-washy. It could go in as-is, but I think would be even better in a more active voice. So I guess that's a yes?

jhodgdon’s picture

Please make a new patch. Active voice is better.

dale42’s picture

StatusFileSize
new1.79 KB

New patch with active voice per #5/#8

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, thanks!

dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to CVS HEAD. Thanks.

jhodgdon’s picture

Version: 7.x-dev » 6.x-dev
Status: Fixed » Patch (to be ported)

We should probably port this to D6 as well.

rdrh555’s picture

Assigned: Unassigned » rdrh555
Status: Patch (to be ported) » Needs review
StatusFileSize
new1.77 KB

Done!

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me. Thanks!

gábor hojtsy’s picture

Status: Reviewed & tested by the community » Fixed

Committed, thanks.

Status: Fixed » Closed (fixed)

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