And more new features for reasonable paranoia.

git-svn-id: file:///svn/phpbb/branches/phpBB-3_0_0@8555 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Henry Sudhof 2008-05-15 14:10:11 +00:00
parent 9413af5e1a
commit fc12c00219
10 changed files with 79 additions and 9 deletions

View file

@ -105,6 +105,7 @@
<li>[Fix] Correctly display subforum read/unread icons from RTL in FF3, Konqueror and Safari3+. (thanks arod-1 for the fix, related to Bug #14830)</li> <li>[Fix] Correctly display subforum read/unread icons from RTL in FF3, Konqueror and Safari3+. (thanks arod-1 for the fix, related to Bug #14830)</li>
<li>[Feature] Added optional referer validation of POST requests as additional CSRF protection.</li> <li>[Feature] Added optional referer validation of POST requests as additional CSRF protection.</li>
<li>[Fix] Added missing form token in acp (thanks NBBN).</li> <li>[Fix] Added missing form token in acp (thanks NBBN).</li>
<li>[Feature] Added optional stricter upload validation to avoid mime sniffing in addition to the safeguards provided by file.php. (thanks to Nicolas Grekas for compiling the list).</li>
</ul> </ul>
<a name="v300"></a><h3>1.ii. Changes since 3.0.0</h3> <a name="v300"></a><h3>1.ii. Changes since 3.0.0</h3>

View file

@ -117,7 +117,9 @@ class acp_attachments
'max_attachments_pm' => array('lang' => 'MAX_ATTACHMENTS_PM', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => false), 'max_attachments_pm' => array('lang' => 'MAX_ATTACHMENTS_PM', 'validate' => 'int', 'type' => 'text:3:3', 'explain' => false),
'secure_downloads' => array('lang' => 'SECURE_DOWNLOADS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'secure_downloads' => array('lang' => 'SECURE_DOWNLOADS', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'secure_allow_deny' => array('lang' => 'SECURE_ALLOW_DENY', 'validate' => 'int', 'type' => 'custom', 'method' => 'select_allow_deny', 'explain' => true), 'secure_allow_deny' => array('lang' => 'SECURE_ALLOW_DENY', 'validate' => 'int', 'type' => 'custom', 'method' => 'select_allow_deny', 'explain' => true),
'secure_allow_empty_referer' => array('lang' => 'SECURE_EMPTY_REFERRER', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'secure_allow_empty_referer' => array('lang' => 'SECURE_EMPTY_REFERRER', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'check_attachment_content' => array('lang' => 'CHECK_CONTENT', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),
'legend2' => $l_legend_cat_images, 'legend2' => $l_legend_cat_images,
'img_display_inlined' => array('lang' => 'DISPLAY_INLINED', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true), 'img_display_inlined' => array('lang' => 'DISPLAY_INLINED', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true),

View file

@ -358,6 +358,11 @@ function upload_attachment($form_name, $forum_id, $local = false, $local_storage
include_once($phpbb_root_path . 'includes/functions_upload.' . $phpEx); include_once($phpbb_root_path . 'includes/functions_upload.' . $phpEx);
$upload = new fileupload(); $upload = new fileupload();
if ($config['check_attachment_content'])
{
$upload->set_disallowed_content(explode('|', $config['mime_triggers']));
}
if (!$local) if (!$local)
{ {
$filedata['post_attach'] = ($upload->is_valid($form_name)) ? true : false; $filedata['post_attach'] = ($upload->is_valid($form_name)) ? true : false;

View file

@ -229,6 +229,34 @@ class filespec
return @filesize($filename); return @filesize($filename);
} }
/**
* Check the first 256 bytes for forbidden content
*/
function check_content($disallowed_content)
{
if (empty($disallowed_content))
{
return true;
}
$fp = @fopen($this->filename, 'rb');
if ($fp !== false)
{
$ie_mime_relevant = fread($fp, 256);
fclose($fp);
foreach ($disallowed_content as $forbidden)
{
if (stripos($ie_mime_relevant, '<' . $forbidden) !== false)
{
return false;
}
}
}
return true;
}
/** /**
* Move file to destination folder * Move file to destination folder
* The phpbb_root_path variable will be applied to the destination path * The phpbb_root_path variable will be applied to the destination path
@ -427,6 +455,7 @@ class fileerror extends filespec
class fileupload class fileupload
{ {
var $allowed_extensions = array(); var $allowed_extensions = array();
var $disallowed_content = array();
var $max_filesize = 0; var $max_filesize = 0;
var $min_width = 0; var $min_width = 0;
var $min_height = 0; var $min_height = 0;
@ -446,12 +475,13 @@ class fileupload
* @param int $max_height Maximum image height (only checked for images) * @param int $max_height Maximum image height (only checked for images)
* *
*/ */
function fileupload($error_prefix = '', $allowed_extensions = false, $max_filesize = false, $min_width = false, $min_height = false, $max_width = false, $max_height = false) function fileupload($error_prefix = '', $allowed_extensions = false, $max_filesize = false, $min_width = false, $min_height = false, $max_width = false, $max_height = false, $disallowed_content = false)
{ {
$this->set_allowed_extensions($allowed_extensions); $this->set_allowed_extensions($allowed_extensions);
$this->set_max_filesize($max_filesize); $this->set_max_filesize($max_filesize);
$this->set_allowed_dimensions($min_width, $min_height, $max_width, $max_height); $this->set_allowed_dimensions($min_width, $min_height, $max_width, $max_height);
$this->set_error_prefix($error_prefix); $this->set_error_prefix($error_prefix);
$this->set_disallowed_content($disallowed_content);
} }
/** /**
@ -463,6 +493,7 @@ class fileupload
$this->min_width = $this->min_height = $this->max_width = $this->max_height = 0; $this->min_width = $this->min_height = $this->max_width = $this->max_height = 0;
$this->error_prefix = ''; $this->error_prefix = '';
$this->allowed_extensions = array(); $this->allowed_extensions = array();
$this->disallowed_content = array();
} }
/** /**
@ -498,6 +529,17 @@ class fileupload
} }
} }
/**
* Set disallowed strings
*/
function set_disallowed_content($disallowed_content)
{
if ($disallowed_content !== false && is_array($disallowed_content))
{
$this->disallowed_content = $disallowed_content;
}
}
/** /**
* Set error prefix * Set error prefix
*/ */
@ -830,6 +872,12 @@ class fileupload
{ {
$file->error[] = sprintf($user->lang[$this->error_prefix . 'DISALLOWED_EXTENSION'], $file->get('extension')); $file->error[] = sprintf($user->lang[$this->error_prefix . 'DISALLOWED_EXTENSION'], $file->get('extension'));
} }
// MIME Sniffing
if (!$this->valid_content($file))
{
$file->error[] = sprintf($user->lang[$this->error_prefix . 'DISALLOWED_CONTENT']);
}
} }
/** /**
@ -869,6 +917,15 @@ class fileupload
return (isset($_FILES[$form_name]) && $_FILES[$form_name]['name'] != 'none') ? true : false; return (isset($_FILES[$form_name]) && $_FILES[$form_name]['name'] != 'none') ? true : false;
} }
/**
* Check for allowed extension
*/
function valid_content(&$file)
{
return ($file->check_content($this->disallowed_content));
}
/** /**
* Return image type/extension mapping * Return image type/extension mapping
*/ */

View file

@ -1952,7 +1952,7 @@ function avatar_upload($data, &$error)
// Init upload class // Init upload class
include_once($phpbb_root_path . 'includes/functions_upload.' . $phpEx); include_once($phpbb_root_path . 'includes/functions_upload.' . $phpEx);
$upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $config['avatar_filesize'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height']); $upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $config['avatar_filesize'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], explode('|', $config['mime_triggers']));
if (!empty($_FILES['uploadfile']['name'])) if (!empty($_FILES['uploadfile']['name']))
{ {

View file

@ -1737,13 +1737,14 @@ function change_database_data($version)
} }
} }
// TODO: remove all form token min times
break; break;
case '3.0.1': case '3.0.1':
set_config('referer_validation', '1'); set_config('referer_validation', '1');
set_config('check_attachment_content', '1');
set_config('mime_triggers', 'body|head|html|img|plaintext|a href|pre|script|table|title');
} }
} }

View file

@ -64,6 +64,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('captcha_gd', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('captcha_gd_foreground_noise', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('captcha_gd_foreground_noise', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('captcha_gd_x_grid', '25'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('captcha_gd_x_grid', '25');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('captcha_gd_y_grid', '25'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('captcha_gd_y_grid', '25');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('check_attachment_content', '1');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('check_dnsbl', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('check_dnsbl', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('chg_passforce', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('chg_passforce', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('cookie_domain', ''); INSERT INTO phpbb_config (config_name, config_value) VALUES ('cookie_domain', '');
@ -172,8 +173,7 @@ INSERT INTO phpbb_config (config_name, config_value) VALUES ('max_sig_urls', '5'
INSERT INTO phpbb_config (config_name, config_value) VALUES ('min_name_chars', '3'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('min_name_chars', '3');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('min_pass_chars', '6'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('min_pass_chars', '6');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('min_search_author_chars', '3'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('min_search_author_chars', '3');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('min_time_reg', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('mime_triggers', 'body|head|html|img|plaintext|a href|pre|script|table|title');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('min_time_terms', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('override_user_style', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('override_user_style', '0');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('pass_complex', 'PASS_TYPE_ANY'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('pass_complex', 'PASS_TYPE_ANY');
INSERT INTO phpbb_config (config_name, config_value) VALUES ('pm_edit_time', '0'); INSERT INTO phpbb_config (config_name, config_value) VALUES ('pm_edit_time', '0');

View file

@ -71,6 +71,8 @@ $lang = array_merge($lang, array(
'CAT_QUICKTIME_FILES' => 'Quicktime media files', 'CAT_QUICKTIME_FILES' => 'Quicktime media files',
'CAT_RM_FILES' => 'RealMedia media files', 'CAT_RM_FILES' => 'RealMedia media files',
'CAT_WM_FILES' => 'Windows Media media files', 'CAT_WM_FILES' => 'Windows Media media files',
'CHECK_CONTENT' => 'Check attachment files',
'CHECK_CONTENT_EXPLAIN' => 'Some browsers can be tricked to assume an incorrect mimetype for uploaded files. This option ensures that such files likely to cause this are rejected.',
'CREATE_GROUP' => 'Create new group', 'CREATE_GROUP' => 'Create new group',
'CREATE_THUMBNAIL' => 'Create thumbnail', 'CREATE_THUMBNAIL' => 'Create thumbnail',
'CREATE_THUMBNAIL_EXPLAIN' => 'Create a thumbnail in all possible situations.', 'CREATE_THUMBNAIL_EXPLAIN' => 'Create a thumbnail in all possible situations.',

View file

@ -78,6 +78,7 @@ $lang = array_merge($lang, array(
'ATTACHED_IMAGE_NOT_IMAGE' => 'The image file you tried to attach is invalid.', 'ATTACHED_IMAGE_NOT_IMAGE' => 'The image file you tried to attach is invalid.',
'AUTHOR' => 'Author', 'AUTHOR' => 'Author',
'AUTH_NO_PROFILE_CREATED' => 'The creation of a user profile was unsuccessful.', 'AUTH_NO_PROFILE_CREATED' => 'The creation of a user profile was unsuccessful.',
'AVATAR_DISALLOWED_CONTENT' => 'The upload was rejected because the uploaded file was identified as a possible attack vector.',
'AVATAR_DISALLOWED_EXTENSION' => 'This file cannot be displayed because the extension <strong>%s</strong> is not allowed.', 'AVATAR_DISALLOWED_EXTENSION' => 'This file cannot be displayed because the extension <strong>%s</strong> is not allowed.',
'AVATAR_EMPTY_REMOTE_DATA' => 'The specified avatar could not be uploaded because the remote data appears to be invalid or corrupted.', 'AVATAR_EMPTY_REMOTE_DATA' => 'The specified avatar could not be uploaded because the remote data appears to be invalid or corrupted.',
'AVATAR_EMPTY_FILEUPLOAD' => 'The uploaded avatar file is empty.', 'AVATAR_EMPTY_FILEUPLOAD' => 'The uploaded avatar file is empty.',

View file

@ -82,6 +82,7 @@ $lang = array_merge($lang, array(
'DISABLE_BBCODE' => 'Disable BBCode', 'DISABLE_BBCODE' => 'Disable BBCode',
'DISABLE_MAGIC_URL' => 'Do not automatically parse URLs', 'DISABLE_MAGIC_URL' => 'Do not automatically parse URLs',
'DISABLE_SMILIES' => 'Disable smilies', 'DISABLE_SMILIES' => 'Disable smilies',
'DISALLOWED_CONTENT' => 'The upload was rejected because the uploaded file was identified as a possible attack vector.',
'DISALLOWED_EXTENSION' => 'The extension %s is not allowed.', 'DISALLOWED_EXTENSION' => 'The extension %s is not allowed.',
'DRAFT_LOADED' => 'Draft loaded into posting area, you may want to finish your post now.<br />Your draft will be deleted after submitting this post.', 'DRAFT_LOADED' => 'Draft loaded into posting area, you may want to finish your post now.<br />Your draft will be deleted after submitting this post.',
'DRAFT_LOADED_PM' => 'Draft loaded into message area, you may want to finish your private message now.<br />Your draft will be deleted after submitting this private message.', 'DRAFT_LOADED_PM' => 'Draft loaded into message area, you may want to finish your private message now.<br />Your draft will be deleted after submitting this private message.',