From aa51e46350ec933fef0d01d52d9133fcd4159a9a Mon Sep 17 00:00:00 2001 From: cjwbath <40788773+cjwbath@users.noreply.github.com> Date: Mon, 8 Jun 2020 14:16:40 +0100 Subject: [PATCH] Don't call clean() on the inputs to the SNMP settings form (#11709) * Don't call clean() on the inputs to the SNMP settings form, it'll call strip_tags() and break values with angle brackets in. * Call htmlspecialchars when outputting DB values to HTML instead * Escape other stuff that should have been validated elsewhere, just in case --- includes/html/pages/device/edit/snmp.inc.php | 66 ++++++++++---------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/includes/html/pages/device/edit/snmp.inc.php b/includes/html/pages/device/edit/snmp.inc.php index 593184e233..a3da269812 100644 --- a/includes/html/pages/device/edit/snmp.inc.php +++ b/includes/html/pages/device/edit/snmp.inc.php @@ -5,18 +5,18 @@ use LibreNMS\Config; if ($_POST['editing']) { if (Auth::user()->hasGlobalAdmin()) { $force_save = ($_POST['force_save'] == 'on'); - $poller_group = isset($_POST['poller_group']) ? clean($_POST['poller_group']) : 0; + $poller_group = isset($_POST['poller_group']) ? $_POST['poller_group'] : 0; $snmp_enabled = ($_POST['snmp'] == 'on'); if ($snmp_enabled) { - $max_repeaters = clean($_POST['max_repeaters']); - $max_oid = clean($_POST['max_oid']); - $port = $_POST['port'] ? clean($_POST['port']) : Config::get('snmp.port'); - $port_assoc_mode = clean($_POST['port_assoc_mode']); - $retries = clean($_POST['retries']); - $snmpver = clean($_POST['snmpver']); - $transport = $_POST['transport'] ? clean($_POST['transport']) : $transport = 'udp'; - $timeout = clean($_POST['timeout']); + $max_repeaters = $_POST['max_repeaters']; + $max_oid = $_POST['max_oid']; + $port = $_POST['port'] ? $_POST['port'] : Config::get('snmp.port'); + $port_assoc_mode = $_POST['port_assoc_mode']; + $retries = $_POST['retries']; + $snmpver = $_POST['snmpver']; + $transport = $_POST['transport'] ? $_POST['transport'] : $transport = 'udp'; + $timeout = $_POST['timeout']; $update = array( 'poller_group' => $poller_group, @@ -34,7 +34,7 @@ if ($_POST['editing']) { } if ($snmpver != "v3") { - $community = clean($_POST['community']); + $community = $_POST['community']; $update['community' ] = $community; } @@ -48,24 +48,24 @@ if ($_POST['editing']) { if ($snmpver == "v3") { $community = ''; // if v3 works, we don't need a community - $v3['authalgo'] = clean($_POST['authalgo']); - $v3['authlevel'] = clean($_POST['authlevel']); - $v3['authname'] = clean($_POST['authname']); - $v3['authpass'] = clean($_POST['authpass']); - $v3['cryptoalgo'] = clean($_POST['cryptoalgo']); - $v3['cryptopass'] = clean($_POST['cryptopass']); + $v3['authalgo'] = $_POST['authalgo']; + $v3['authlevel'] = $_POST['authlevel']; + $v3['authname'] = $_POST['authname']; + $v3['authpass'] = $_POST['authpass']; + $v3['cryptoalgo'] = $_POST['cryptoalgo']; + $v3['cryptopass'] = $_POST['cryptopass']; $update = array_merge($update, $v3); } } else { // snmp is disabled $update['features'] = null; - $update['hardware'] = clean($_POST['hardware']); + $update['hardware'] = $_POST['hardware']; $update['icon'] = null; - $update['os'] = $_POST['os'] ? clean($_POST['os_id']) : "ping"; + $update['os'] = $_POST['os'] ? $_POST['os_id'] : "ping"; $update['poller_group'] = $poller_group; $update['snmp_disable'] = 1; - $update['sysName'] = $_POST['sysName'] ? clean($_POST['sysName']) : null; + $update['sysName'] = $_POST['sysName'] ? $_POST['sysName'] : null; $update['version'] = null; } @@ -156,7 +156,7 @@ if ($_POST['editing']) { } if ($snmp_enabled && ($force_save !== true && !$device_issnmpable)) { - $update_failed_message[] = "Could not connect to " . $device['hostname'] . " with those SNMP settings. To save anyway, turn on Force Save."; + $update_failed_message[] = "Could not connect to " . htmlspecialchars($device['hostname']) . " with those SNMP settings. To save anyway, turn on Force Save."; $update_message[] = 'SNMP settings reverted'; } @@ -230,19 +230,19 @@ echo "
- +
- +
- +
@@ -259,7 +259,7 @@ echo "
- +
- +
- +
@@ -307,13 +307,13 @@ echo "
- +
- +
@@ -323,7 +323,7 @@ echo "
- +
@@ -344,13 +344,13 @@ echo "
- +
- +
@@ -365,7 +365,7 @@ echo "
- +
@@ -399,7 +399,7 @@ if (Config::get('distributed_poller') === true) { echo ' selected'; } - echo '>'.$group['group_name'].''; + echo '>'.htmlspecialchars($group['group_name']).''; } echo '