From 03b5a921ff308eeab21bf9d240f27783c8591965 Mon Sep 17 00:00:00 2001 From: Michael Kaufmann Date: Fri, 7 Jul 2023 09:46:31 +0200 Subject: [PATCH] validate generated config-json parameter string Signed-off-by: Michael Kaufmann --- admin_configfiles.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/admin_configfiles.php b/admin_configfiles.php index ac4630db..0770c8a7 100644 --- a/admin_configfiles.php +++ b/admin_configfiles.php @@ -33,6 +33,7 @@ use Froxlor\Settings; use Froxlor\UI\Panel\UI; use Froxlor\UI\Request; use Froxlor\UI\Response; +use Froxlor\Validate\Validate; if ($userinfo['change_serversettings'] == '1') { if ($action == 'setconfigured') { @@ -91,6 +92,7 @@ if ($userinfo['change_serversettings'] == '1') { } if ($distribution != "" && isset($_POST['finish'])) { + $valid_keys = ['http', 'dns', 'smtp', 'mail', 'ftp', 'system', 'distro']; unset($_POST['finish']); unset($_POST['csrf_token']); $params = $_POST; @@ -99,6 +101,20 @@ if ($userinfo['change_serversettings'] == '1') { foreach ($_POST['system'] as $sysdaemon) { $params['system'][] = $sysdaemon; } + // validate params + foreach ($params as $key => $value) { + if (!in_array($key, $valid_keys)) { + unset($params[$key]); + continue; + } + if (!is_array($value)) { + $params[$key] = Validate::validate($value, $key); + } else { + foreach ($value as $subkey => $subvalue) { + $params[$key][$subkey] = Validate::validate($subvalue, $key.'.'.$subkey); + } + } + } $params_content = json_encode($params); $params_filename = FileDir::makeCorrectFile(Froxlor::getInstallDir() . 'install/' . Froxlor::genSessionId() . '.json'); file_put_contents($params_filename, $params_content);