From c0eea755cf10375a2bdd26a42c5576b7584ae791 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Sun, 26 Apr 2020 08:02:53 +0200 Subject: [PATCH] Fix local file inclusion (and code execution) via crafted 'plugins' option --- program/lib/Roundcube/rcube_plugin_api.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/program/lib/Roundcube/rcube_plugin_api.php b/program/lib/Roundcube/rcube_plugin_api.php index d86c97e7b..5da7d0220 100644 --- a/program/lib/Roundcube/rcube_plugin_api.php +++ b/program/lib/Roundcube/rcube_plugin_api.php @@ -163,6 +163,14 @@ class rcube_plugin_api $plugins_dir = unslashify($dir->path); } + // Validate the plugin name to prevent from path traversal + if (preg_match('/[^a-zA-Z0-9_-]/', $plugin_name)) { + rcube::raise_error(array('code' => 520, + 'file' => __FILE__, 'line' => __LINE__, + 'message' => "Invalid plugin name: $plugin_name"), true, false); + return false; + } + // plugin already loaded? if (!$this->plugins[$plugin_name]) { $fn = "$plugins_dir/$plugin_name/$plugin_name.php"; @@ -282,6 +290,14 @@ class rcube_plugin_api $fn = unslashify($dir->path) . "/$plugin_name/$plugin_name.php"; $info = false; + // Validate the plugin name to prevent from path traversal + if (preg_match('/[^a-zA-Z0-9_-]/', $plugin_name)) { + rcube::raise_error(array('code' => 520, + 'file' => __FILE__, 'line' => __LINE__, + 'message' => "Invalid plugin name: $plugin_name"), true, false); + return false; + } + if (!class_exists($plugin_name, false)) { if (is_readable($fn)) { include($fn);