Changeset 1836

Show
Ignore:
Timestamp:
12/08/2011 11:21:48 PM (18 months ago)
Author:
BrianKoontz
Message:

Sanitized file parameters (now restricted to restricted charset). Refs
#1097.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/actions/files/files.php

    r1828 r1836  
    188188} 
    189189 
     190// Sanitize filenames to prevent path traversal attacks 
    190191$action = $this->GetSafeVar('action', 'get'); 
    191192$file = $this->GetSafeVar('file', 'get'); 
    192193$file_to_delete = $this->GetSafeVar('file_to_delete', 'post'); 
    193 $prohibited_filepath_tokens = "/^[\.\/\\\]/"; 
    194 if(preg_match($prohibited_filepath_tokens, $file) || 
    195    preg_match($prohibited_filepath_tokens, $file_to_delete)) 
    196 { 
    197         $this->Redirect($this->Href(), T_("Sorry, files of this type are not allowed.")); 
    198 } 
     194 
     195$fileregex = "/^.*?([^\.\/\\\]+\.[A-Za-z0-9]{2,4})$/"; 
     196if(isset($_GET['file'])) 
     197{ 
     198        $matches = ''; 
     199        preg_match($fileregex, $file, $matches); 
     200        if(isset($matches[1])) 
     201                $file = $matches[1]; 
     202        else 
     203                $this->Redirect('', T_("Invalid filename")); 
     204} 
     205if(isset($_POST['file_to_delete'])) 
     206{ 
     207        $matches = ''; 
     208        preg_match($fileregex, $file_to_delete, $matches); 
     209        if(isset($matches[1])) 
     210                $file_to_delete = $matches[1]; 
     211        else 
     212                $this->Redirect('', T_("Invalid filename")); 
     213} 
     214 
    199215 
    200216// 1a. User has requested a file to be deleted