Changeset 1833

Show
Ignore:
Timestamp:
12/07/2011 11:23:02 PM (18 months ago)
Author:
BrianKoontz
Message:

Sanitized file input to disallow pathname chars and variants. Refs #1097.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/handlers/files.xml/files.xml.php

    r1828 r1833  
    4848        // invocation of files.xml must provide $_GET['file'] and $_GET['action']. 
    4949        // todo: add an error message here: probably, T_("The parameters you supplied are incorrect, one of the two revisions may have been removed.") should be splitted. 
    50         $this->Redirect(''); 
     50        $this->Redirect(); 
    5151} 
    5252 
    53 $file = $this->GetSafeVar('file', 'get'); 
    54 if(preg_match("/^[\.\/\\\]/", $file)) 
     53// Sanitize the filename to prevent path traversal attacks 
     54$file = $this->GetSafeVar('file','get'); 
     55$matches = ''; 
     56preg_match("/^.*?([^\.\/\\\]+\.[A-Za-z0-9]{2,4})$/", $file, $matches); 
     57if(isset($matches[1])) 
     58        $file = $matches[1]; 
     59else 
    5560{ 
    56         $this->Redirect($this->Href(), T_("Sorry, files of this type are not allowed.")); 
     61        $this->SetRedirectMessage(T_("Invalid filename")); 
     62        $this->Redirect(); 
    5763} 
     64 
    5865// do the action 
    5966$action = $this->GetSafeVar('action', 'get');