From 648fcf570964ad512d18d6df7e07d5bcec2ae830 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Wed, 27 Mar 2013 11:32:51 -0400
Subject: [PATCH] Whitelist configuration options (user preferences) that can be changed using save-pref command

---
 program/steps/utils/save_pref.inc          |   16 ++++++++++++++++
 program/lib/Roundcube/rcube_plugin_api.php |    6 ++++++
 program/lib/Roundcube/rcube_plugin.php     |    8 ++++++++
 3 files changed, 30 insertions(+), 0 deletions(-)

diff --git a/program/lib/Roundcube/rcube_plugin.php b/program/lib/Roundcube/rcube_plugin.php
index 9ea0f73..167a9eb 100644
--- a/program/lib/Roundcube/rcube_plugin.php
+++ b/program/lib/Roundcube/rcube_plugin.php
@@ -60,6 +60,14 @@
      */
     public $noframe = false;
 
+    /**
+     * A list of config option names that can be modified
+     * by the user via user interface (with save-prefs command)
+     *
+     * @var array
+     */
+    public $allowed_prefs;
+
     protected $home;
     protected $urlbase;
     private $mytask;
diff --git a/program/lib/Roundcube/rcube_plugin_api.php b/program/lib/Roundcube/rcube_plugin_api.php
index 111c177..a89f147 100644
--- a/program/lib/Roundcube/rcube_plugin_api.php
+++ b/program/lib/Roundcube/rcube_plugin_api.php
@@ -36,6 +36,7 @@
     public $task = '';
     public $output;
     public $handlers = array();
+    public $allowed_prefs = array();
 
     protected $plugins = array();
     protected $tasks = array();
@@ -202,6 +203,11 @@
                         $plugin->init();
                         $this->plugins[$plugin_name] = $plugin;
                     }
+
+                    if (!empty($plugin->allowed_prefs)) {
+                        $this->allowed_prefs = array_merge($this->allowed_prefs, $plugin->allowed_prefs);
+                    }
+
                     return true;
                 }
             }
diff --git a/program/steps/utils/save_pref.inc b/program/steps/utils/save_pref.inc
index b550ad7..7def873 100644
--- a/program/steps/utils/save_pref.inc
+++ b/program/steps/utils/save_pref.inc
@@ -21,6 +21,22 @@
 
 $name = get_input_value('_name', RCUBE_INPUT_POST);
 $value = get_input_value('_value', RCUBE_INPUT_POST);
+$whitelist = array(
+    'preview_pane',
+    'list_cols',
+    'collapsed_folders',
+    'collapsed_abooks',
+);
+
+if (!in_array($name, array_merge($whitelist, $RCMAIL->plugins->allowed_prefs))) {
+    raise_error(array('code' => 500, 'type' => 'php',
+        'file' => __FILE__, 'line' => __LINE__,
+        'message' => sprintf("Hack attempt detected (user: %s)", $RCMAIL->get_user_name())),
+        true, false);
+
+    $OUTPUT->reset();
+    $OUTPUT->send();
+}
 
 // save preference value
 $RCMAIL->user->save_prefs(array($name => $value));

--
Gitblit v1.9.1