From e263a85f89e9e3c2cc0b996fbf209072be64deb9 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 26 Mar 2026 21:16:46 +0100 Subject: [PATCH] FIX #GHSA-ph29-326p-chw4 - disable+sanitize deprecated load/save files --- htdocs/core/ajax/ajaxextrafield.php | 2 +- htdocs/core/ajax/ajaxfield.php | 8 ++++---- htdocs/core/ajax/loadinplace.php | 5 +++-- htdocs/core/ajax/saveinplace.php | 12 ++++++++---- htdocs/core/class/commonobject.class.php | 20 +++++++++++++++++++- htdocs/core/class/fieldsmanager.class.php | 3 +-- 6 files changed, 36 insertions(+), 14 deletions(-) diff --git a/htdocs/core/ajax/ajaxextrafield.php b/htdocs/core/ajax/ajaxextrafield.php index 3ec67801286..482a9424cac 100644 --- a/htdocs/core/ajax/ajaxextrafield.php +++ b/htdocs/core/ajax/ajaxextrafield.php @@ -55,7 +55,7 @@ $objecttype = GETPOST('objecttype', 'aZ09arobase'); $objectkey = GETPOST('objectkey', 'restricthtml'); $search = GETPOST('search', 'restricthtml'); $page = GETPOSTINT('page'); -$mode = GETPOSTINT('mode'); +$mode = GETPOST('mode', 'aZ09'); $value = GETPOST('value', 'alphanohtml'); $limit = 10; $offset = (($page - 1) * $limit); diff --git a/htdocs/core/ajax/ajaxfield.php b/htdocs/core/ajax/ajaxfield.php index 8eb40de4a42..e4c763b04e3 100644 --- a/htdocs/core/ajax/ajaxfield.php +++ b/htdocs/core/ajax/ajaxfield.php @@ -19,7 +19,8 @@ /** * \file htdocs/core/ajax/ajaxfield.php * \ingroup core - * \brief This script returns content of extrafield. See extrafield to update value. + * \brief This script returns content of fields or extrafields (using new class/fields/*.class.php files). + * TODO This may depreciate htdoc/core/ajax/ajaxextrafields.php */ if (!defined('NOTOKENRENEWAL')) { @@ -40,15 +41,14 @@ if (!defined('NOHEADERNOFOOTER')) { } require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; -require_once DOL_DOCUMENT_ROOT . '/core/class/fieldsmanager.class.php'; - /** * @var Conf $conf * @var DoliDB $db * @var Translate $langs * @var User $user */ +require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/class/fieldsmanager.class.php'; // object id $objectid = GETPOST('objectid', 'aZ09'); diff --git a/htdocs/core/ajax/loadinplace.php b/htdocs/core/ajax/loadinplace.php index 125c3d258fb..db0d775ed65 100644 --- a/htdocs/core/ajax/loadinplace.php +++ b/htdocs/core/ajax/loadinplace.php @@ -18,8 +18,9 @@ */ /** - * \file htdocs/core/ajax/loadinplace.php - * \brief File to load field value. used only when option "Edit In Place" is set (MAIN_USE_JQUERY_JEDITABLE). + * \file htdocs/core/ajax/loadinplace.php + * \brief File to load (loadinplace.php) or update (saveinplace.php) a field value. + * Was used in past when option "Edit In Place" is set (MAIN_USE_JQUERY_JEDITABLE). */ if (!defined('NOTOKENRENEWAL')) { diff --git a/htdocs/core/ajax/saveinplace.php b/htdocs/core/ajax/saveinplace.php index 82db21a5d77..72a22b1e8ff 100644 --- a/htdocs/core/ajax/saveinplace.php +++ b/htdocs/core/ajax/saveinplace.php @@ -18,8 +18,9 @@ */ /** - * \file htdocs/core/ajax/saveinplace.php - * \brief File to load or update field value. Was used in past when option "Edit In Place" is set (MAIN_USE_JQUERY_JEDITABLE). + * \file htdocs/core/ajax/saveinplace.php + * \brief File to load (loadinplace.php) or update (saveinplace.php) a field value. + * Was used in past when option "Edit In Place" is set (MAIN_USE_JQUERY_JEDITABLE). */ if (!defined('NOTOKENRENEWAL')) { @@ -94,6 +95,10 @@ if (!$result) { httponly_accessforbidden('Not allowed by restrictArea'); } +if (!getDolGlobalString('MAIN_USE_JQUERY_JEDITABLE')) { + httponly_accessforbidden('Can be used only when option MAIN_USE_JQUERY_JEDITABLE is set'); +} + /* * View @@ -117,7 +122,6 @@ if (!empty($field) && !empty($element) && !empty($table_element) && !empty($fk_e //$savemethod = GETPOST('savemethod', 'alpha', 2); //$savemethodname = (!empty($savemethod) ? $savemethod : 'setValueFrom'); - $savemethodname = 'setValueFrom'; $newelement = $element; $subelement = null; @@ -200,7 +204,7 @@ if (!empty($field) && !empty($element) && !empty($table_element) && !empty($fk_e $object->fk_element = $fk_element; $object->element = $element; - $ret = $object->$savemethodname($field, $newvalue, $table_element, (int) $fk_element, $format); + $ret = $object->setValueFrom($field, $newvalue, $object->table_element, (int) $fk_element, $format); if ($ret > 0) { if ($type == 'numeric') { $value = price($newvalue); diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index a4db2047553..40f38a494ef 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2238,7 +2238,16 @@ abstract class CommonObject { $result = false; if (!empty($id) && !empty($field) && !empty($table)) { - $sql = "SELECT ".$field." FROM ".$this->db->prefix().$table; + if (!preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/', $table)) { + dol_syslog(get_class($this).'::getValueFrom Bad table name: '.$table, LOG_WARNING); + return -1; + } + if (!preg_match('/^[a-zA-Z_][a-zA-Z0-9_.]*$/', $field)) { + dol_syslog(get_class($this).'::getValueFrom Bad field name: '.$field, LOG_WARNING); + return -1; + } + + $sql = "SELECT ".$this->db->sanitize($field)." FROM ".$this->db->prefix().$this->db->sanitize($table); $sql .= " WHERE rowid = ".((int) $id); dol_syslog(get_class($this).'::getValueFrom', LOG_DEBUG); @@ -2310,6 +2319,15 @@ abstract class CommonObject $fk_user_field = ''; } + if (!preg_match('/^[a-zA-Z_][a-zA-Z0-9_]*$/', $table)) { + dol_syslog(get_class($this).'::getValueFrom Bad table name: '.$table, LOG_WARNING); + return -1; + } + if (!preg_match('/^[a-zA-Z_][a-zA-Z0-9_.]*$/', $field)) { + dol_syslog(get_class($this).'::getValueFrom Bad field name: '.$field, LOG_WARNING); + return -1; + } + $oldvalue = null; if ($trigkey) { $sql = "SELECT " . $this->db->sanitize($field); diff --git a/htdocs/core/class/fieldsmanager.class.php b/htdocs/core/class/fieldsmanager.class.php index deb92f82546..af84f0e32c5 100644 --- a/htdocs/core/class/fieldsmanager.class.php +++ b/htdocs/core/class/fieldsmanager.class.php @@ -455,11 +455,10 @@ class FieldsManager */ public function getFieldsInfos($key, &$object, &$extrafields = null, $mode = 'view', $params = array()) { - global $langs; - $fieldInfos = null; $patternObjectPrefix = getDolGlobalInt('MAIN_FIELDS_NEW_OBJECT_KEY_PREFIX') ? 'object_' : ''; + $matches = array(); if (preg_match('/^options_(.*)/i', $key, $matches)) { $fieldKey = $matches[1]; $fieldInfos = $this->getFieldInfosFromExtraField($object, $extrafields, $fieldKey, $mode, $params);