Skip to content

Commit

Permalink
Checking of remote file-types during import and other cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
CaMer0n committed Dec 17, 2021
1 parent d8ce385 commit 90108ea
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 9 deletions.
6 changes: 5 additions & 1 deletion e107_admin/image.php
Expand Up @@ -2486,7 +2486,11 @@ function processUploadUrl($import = false, $cat='_common')
$fileName = empty($uploadCaption) ? str_replace(array('.php', '.html', '.asp', '.htm'),'',$fileName). '_' .time() : eHelper::dasherize(strtolower($uploadCaption));
}

if(!$fl->getRemoteFile($tp->filter($_POST['upload_url'], 'url'), $fileName, 'import'))
if(!$fl->isAllowedType($_POST['upload_url']))
{
$mes->addError(defset('IMALAN_190', "Importing of this file-type is not allowed."));
}
elseif(!$fl->getRemoteFile($tp->filter($_POST['upload_url'], 'url'), $fileName, 'import'))
{
$mes->addError(IMALAN_176);
}
Expand Down
2 changes: 1 addition & 1 deletion e107_handlers/comment_class.php
Expand Up @@ -271,7 +271,7 @@ function form_comment($action, $table, $id, $subject, $content_type, $return = F
$text = "\n<div{$indent}>\n".e107::getMessage()->render('postcomment', true, false);//temporary here

// $text .= "Indent = ".$indent;
$text .= "<form id='{$formid}' method='post' action='".str_replace('http:', '', $_SERVER['REQUEST_URI'])."' >";
$text .= "<form id='{$formid}' method='post' action='".str_replace('http:', '', e_REQUEST_URI)."' >";

$data = array(
'action' => $action,
Expand Down
16 changes: 15 additions & 1 deletion e107_handlers/file_class.php
Expand Up @@ -2177,7 +2177,7 @@ function isClean($filename, $target_name = '', $allowed_filetypes = array(), $un

/**
* New in v2.1.9
* Check filename or path against filetypes.xml
* Check filename, path or URL against filetypes.xml
*
* @param $file - real path to file.
* @param string $targetFile
Expand All @@ -2191,12 +2191,26 @@ public function isAllowedType($file, $targetFile = '')
$targetFile = $file;
}

$remote = false;

if(strpos($targetFile,'http') === 0) // remote file.
{
$tmp = parse_url($targetFile);
$targetFile = $tmp['path'];
$remote = true;
}

$ext = pathinfo($targetFile, PATHINFO_EXTENSION);

$types = $this->getAllowedFileTypes();

if(isset($types[$ext]))
{
if($remote)
{
return true;
}

$maxSize = $types[$ext] * 1024;
$fileSize = filesize($file);

Expand Down
6 changes: 3 additions & 3 deletions e107_languages/English/admin/help/menus.php
Expand Up @@ -27,7 +27,7 @@
{
$sql->select("menus","*", "menu_location='".$mc."' ORDER BY menu_order");
$count = 1;
$sql2 = new db;
$sql2 = e107::getDb('sql2');
while(list($menu_id, $menu_name, $menu_location, $menu_order) = $sql->fetch())
{
$sql2 ->update("menus", "menu_order='$count' WHERE menu_id='$menu_id' ");
Expand All @@ -48,7 +48,7 @@
If you find the menus are not updating correctly, clicking the refresh button below may help.
[html]
<form method='post' id='menurefresh' action='".$_SERVER['PHP_SELF']."'>
<form method='post' id='menurefresh' action='".e_SELF."'>
<div>
".$frm->admin_button('reset','Refresh','cancel')."</div>
</form>
Expand All @@ -58,4 +58,4 @@
";

$text = $tp->toHTML($text, true);
$ns->tablerender("Menu Manager Help", $text);
e107::getRender()->tablerender("Menu Manager Help", $text);
3 changes: 2 additions & 1 deletion e107_languages/English/admin/lan_image.php
Expand Up @@ -214,4 +214,5 @@

define("IMALAN_187", "Convert to webp during import");
define("IMALAN_188", "Convert to webp during render");
define("IMALAN_189", "JPEG, PNG and GIF files will be automatically converted to webp format. (icons excluded)");
define("IMALAN_189", "JPEG, PNG and GIF files will be automatically converted to webp format. (icons excluded)");
define("IMALAN_190", "Importing of this file-type is not allowed.");
10 changes: 8 additions & 2 deletions e107_tests/tests/unit/e_fileTest.php
Expand Up @@ -152,8 +152,14 @@ public function testIsAllowedType()

$isAllowedTest = array(
array('path'=> 'somefile.bla', 'expected' => false), // suspicious
array('path'=> e_SYSTEM."filetypes.xml", 'expected' => true), // okay
array('path'=> e_PLUGIN."gallery/images/butterfly.jpg", 'expected' => true), // okay
array('path'=> 'somefile.php', 'expected' => false), // suspicious
array('path'=> 'somefile.exe', 'expected' => false), // suspicious
array('path'=> e_SYSTEM."filetypes.xml", 'expected' => true), // permitted
array('path'=> e_PLUGIN."gallery/images/butterfly.jpg", 'expected' => true), // permitted
array('path'=> 'http://127.0.0.1:8070/file.svg', 'expected'=>false), // not permitted
array('path'=> 'http://127.0.0.1:8070/butterfly.jpg', 'expected'=>true), // permitted
array('path'=> 'http://127.0.0.1/bla.php', 'expected'=>false), // suspicious
array('path'=> 'http://127.0.0.1/bla.php?butterfly.jpg', 'expected'=>false), // suspicious
);

foreach($isAllowedTest as $file)
Expand Down

0 comments on commit 90108ea

Please sign in to comment.