Aleksander Machniak
2013-10-17 197203727417a03d87053a47e5aa5175a76e3e0b
Fix vulnerability in handling _session argument of utils/save-prefs (#1489382)

Conflicts:

CHANGELOG
program/lib/Roundcube/rcube_plugin_api.php
program/steps/utils/save_pref.inc
3 files modified
28 ■■■■ changed files
CHANGELOG 2 ●●●●● patch | view | raw | blame | history
program/include/rcube_plugin_api.php 7 ●●●●● patch | view | raw | blame | history
program/steps/utils/save_pref.inc 19 ●●●● patch | view | raw | blame | history
CHANGELOG
@@ -1,6 +1,8 @@
CHANGELOG Roundcube Webmail
===========================
- Fix vulnerability in handling _session argument of utils/save-prefs (#1489382)
RELEASE 0.7.4
-------------
- Fix security issue in save-pref command
program/include/rcube_plugin_api.php
@@ -27,13 +27,14 @@
class rcube_plugin_api
{
  static private $instance;
  public $dir;
  public $url = 'plugins/';
  public $output;
  public $config;
  public $allowed_prefs = array();
  public $allowed_prefs         = array();
  public $allowed_session_prefs = array();
  public $handlers = array();
  private $plugins = array();
  private $tasks = array();
program/steps/utils/save_pref.inc
@@ -16,16 +16,26 @@
 +-----------------------------------------------------------------------+
*/
$name = get_input_value('_name', RCUBE_INPUT_POST);
$value = get_input_value('_value', RCUBE_INPUT_POST);
$name     = get_input_value('_name', RCUBE_INPUT_POST);
$value    = get_input_value('_value', RCUBE_INPUT_POST);
$sessname = get_input_value('_session', RCUBE_INPUT_POST);
// Whitelisted preferences and session variables, others
// can be added by plugins
$whitelist = array(
    'preview_pane',
    'list_cols',
    'collapsed_folders',
    'collapsed_abooks',
);
$whitelist_sess = array(
    'list_attrib/columns',
);
if (!in_array($name, array_merge($whitelist, $RCMAIL->plugins->allowed_prefs))) {
$whitelist      = array_merge($whitelist, $RCMAIL->plugins->allowed_prefs);
$whitelist_sess = array_merge($whitelist_sess, $RCMAIL->plugins->allowed_session_prefs);
if (!in_array($name, $whitelist) || ($sessname && !in_array($sessname, $whitelist_sess))) {
    raise_error(array('code' => 500, 'type' => 'php',
        'file' => __FILE__, 'line' => __LINE__,
        'message' => sprintf("Hack attempt detected (user: %s)", $_SESSION['username'])),
@@ -39,7 +49,7 @@
$RCMAIL->user->save_prefs(array($name => $value));
// update also session if requested
if ($sessname = get_input_value('_session', RCUBE_INPUT_POST)) {
if ($sessname) {
    // Support multidimensional arrays...
    $vars = explode('/', $sessname);
@@ -54,4 +64,3 @@
$OUTPUT->reset();
$OUTPUT->send();