From 9faae11381f148221e12cafef31ea79351a96d7f Mon Sep 17 00:00:00 2001 From: Tony Murray Date: Fri, 31 May 2019 07:43:12 -0500 Subject: [PATCH] Sanitize graph input (#10276) Could execute arbitrary rrdtool commands such as cd and ls. --- LibreNMS/Util/Clean.php | 22 ++++++++++++++++++++++ includes/html/graphs/common.inc.php | 16 +++++++++------- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/LibreNMS/Util/Clean.php b/LibreNMS/Util/Clean.php index f82bb4481d..0b84cb167a 100644 --- a/LibreNMS/Util/Clean.php +++ b/LibreNMS/Util/Clean.php @@ -43,6 +43,28 @@ class Clean return preg_replace('/[^a-zA-Z0-9\-._]/', '', $file); } + /** + * Sanitize string to only contain alpha, numeric, dashes, and underscores + * + * @param string $string + * @return string + */ + public static function alphaDash($string) + { + return preg_replace('/[^a-zA-Z0-9\-_]/', '', $string); + } + + /** + * Sanitize string to only contain alpha, numeric, dashes, underscores, and spaces + * + * @param string $string + * @return string + */ + public static function alphaDashSpace($string) + { + return preg_replace('/[^a-zA-Z0-9\-_ ]/', '', $string); + } + /** * Clean a string for display in an html page. * For use in non-blade pages diff --git a/includes/html/graphs/common.inc.php b/includes/html/graphs/common.inc.php index 9791e9c387..0c8f447b2a 100644 --- a/includes/html/graphs/common.inc.php +++ b/includes/html/graphs/common.inc.php @@ -1,15 +1,17 @@