Skip to content

Commit

Permalink
% Запрещена заливка PHP файлов даже в случае, если расширение 'php' в…
Browse files Browse the repository at this point in the history
…несено в спискок разрешенных для заливки

+ Добавлена опция "настройки системы" => "безопасность" => "Разрешить загрузку файлов/изображений с двойными (и более) расширениями", по умолчанию выставлено в "Нет" (лишние точки будут заменены на подчерки). Эта опция позволит избежать ситуации, когда web сервер apache некорректно распрознаёт реальное расширение файла и смотрит все расширения (к примеру, файл filename.php.blabla может быть расценен как php скрипт).
  • Loading branch information
ngcms committed Oct 8, 2012
1 parent 1c8219a commit 2916b3e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions engine/actions/configuration.php
Expand Up @@ -165,6 +165,7 @@ function systemConfigEditForm(){
'home_url' => $config['home_url'],
'admine_url' => $config['admin_url'],
'news_multicat_url' => MakeDropDown(array(0 => $lang['news_multicat:0'], 1 => $lang['news_multicat:1']), "save_con[news_multicat_url]", $config['news_multicat_url']),
'multiext_files' => MakeDropDown(array(0 => $lang['noa'], 1 => $lang['yesa']), "save_con[allow_multiext]", $config['allow_multiext']),
);

// Prepare file name for STAMP
Expand Down
12 changes: 9 additions & 3 deletions engine/includes/classes/upload.class.php
@@ -1,7 +1,7 @@
<?php

//
// Copyright (C) 2006-2011 Next Generation CMS (http://ngcms.ru/)
// Copyright (C) 2006-2012 Next Generation CMS (http://ngcms.ru/)
// Name: upload.class.php
// Description: Files/Images upload managment
// Author: Vitaly Ponomarev
Expand Down Expand Up @@ -240,8 +240,9 @@ function file_upload($param){
$fil = explode(".", strtolower($fname));
$ext = count($fil)?array_pop($fil):'';

// * File type
if (array_search($ext, $this->required_type) === FALSE) {

// * File type [ don't allow to upload PHP files in any case ]
if ((array_search(strtolower($ext), $this->required_type) === FALSE)||(array_search(strtolower($ext), array('php', 'pht', 'phtml', 'php3', 'php4', 'php5')) !== FALSE)) {
if ($param['rpc']) {
return array('status' => 0, 'errorCode' => 304, 'errorText' => str_replace('{fname}', $fname, iconv('Windows-1251', 'UTF-8', $lang['upload.error.ext'])), 'errorDescription' => iconv('Windows-1251', 'UTF-8', str_replace('{ext}', join(", ",$this->required_type), $lang['upload.error.ext#info'])));
} else {
Expand All @@ -250,6 +251,11 @@ function file_upload($param){
}
}

// Manage multiple extensions
if (!$config['allow_multiext']) {
$fil = array(join("_", $fil));
}

$parse = new parse();

$fil = trim(str_replace(array(' ','\\','/',chr(0)),array('_', ''),join(".",$fil)));
Expand Down
2 changes: 2 additions & 0 deletions engine/lang/english/admin/configuration.ini
Expand Up @@ -251,3 +251,5 @@ load_desc = "This feature allows to collect and display load information for la
load_profiler = "Activate detailed SQL queries and activities logs for <b>XX</b> sec"
load_profiler_desc = "Enter number of seconds (from current moment) for that you need to collect detailed information. Please note, this mode will heavily load mysql database"
news_view_counters#2 = "Delayed"
multiext_files = "Allow upload files/images with multiple extensions"
multiext_files_desc = "<b>No</b> - &quot;extra&quot; extensions will be deleted<br/><b>Yes</b> - user will be able to use multiple extensions (<font color='red'><b>unsecured!</b></font>)"
2 changes: 2 additions & 0 deletions engine/lang/russian/admin/configuration.ini
Expand Up @@ -260,3 +260,5 @@ load_profiler_desc = "
news_view_counters#2 = "Отложенное"
news_view_counters = "Учёт просмотра новостей"
news_view_counters#desc = "<b>Да</b> - просмотр новостей будет учитываться в реальном времени<br/><b>Нет</b> - просмотр новостей не будет учитываться<br/><b>Отложенное</b> - просмотр будет обновляться каждые 15 минут"
multiext_files = "Разрешить загрузку файлов/изображений с двойными (и более) расширениями"
multiext_files_desc = "<b>Нет</b> - &quot;лишние&quot; расширения будут удаляться<br/><b>Да</b> - пользователь сможет загружать файлы с несколькими расширениями (<font color='red'><b>небезопасно!</b></font>)"
4 changes: 4 additions & 0 deletions engine/skins/default/tpl/configuration.tpl
Expand Up @@ -139,6 +139,10 @@ function ChangeOption(selectedOption) {
<td class="contentEntry1">{l_sql_error}<br /><small>{l_sql_error_desc}</small></td>
<td class="contentEntry2" valign="middle">{sql_error}</td>
</tr>
<tr>
<td class="contentEntry1">{l_multiext_files}<br /><small>{l_multiext_files_desc}</small></td>
<td class="contentEntry2" valign="middle">{multiext_files}</td>
</tr>
</table>
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<tr>
Expand Down

0 comments on commit 2916b3e

Please sign in to comment.