Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

Commit 1d05dd0

Browse files
author
dries
committed
- Patch #710640 by jhodgdon, torelad: improve documentation for file_munge_filename().
1 parent 8b156eb commit 1d05dd0

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

includes/file.inc

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
2-
// $Id: file.inc,v 1.220 2010-08-01 01:33:42 webchick Exp $
2+
// $Id: file.inc,v 1.221 2010-08-08 01:37:34 dries Exp $
33

44
/**
55
* @file
@@ -850,11 +850,23 @@ function file_unmanaged_move($source, $destination = NULL, $replace = FILE_EXIST
850850
/**
851851
* Modify a filename as needed for security purposes.
852852
*
853-
* Dangerous file names will be altered; for instance, the file name
854-
* "exploit.php.pps" will become "exploit.php_.pps". All extensions that are
853+
* Munging a file name prevents unknown file extensions from masking exploit
854+
* files. When web servers such as Apache decide how to process a URL request,
855+
* they use the file extension. If the extension is not recognized, Apache
856+
* skips that extension and uses the previous file extension. For example, if
857+
* the file being requested is exploit.php.pps, and Apache does not recognize
858+
* the '.pps' extension, it treats the file as PHP and executes it. To make
859+
* this file name safe for Apache and prevent it from executing as PHP, the
860+
* .php extension is "munged" into .php_, making the safe file name
861+
* exploit.php_.pps.
862+
*
863+
* Specifically, this function adds an underscore to all extensions that are
855864
* between 2 and 5 characters in length, internal to the file name, and not
856-
* included in $extensions will be altered by adding an underscore. If variable
857-
* 'allow_insecure_uploads' evaluates to TRUE, no alterations will be made.
865+
* included in $extensions.
866+
*
867+
* Function behavior is also controlled by the Drupal variable
868+
* 'allow_insecure_uploads'. If 'allow_insecure_uploads' evaluates to TRUE, no
869+
* alterations will be made, if it evaluates to FALSE, the filename is 'munged'.
858870
*
859871
* @param $filename
860872
* File name to modify.

0 commit comments

Comments
 (0)