From 5446eca125dacbddc4d045eef5e2b2143594d57f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 31 May 2026 15:42:24 +0200 Subject: [PATCH] Use the default hash method for online signature instead of password hash --- htdocs/core/class/commonobject.class.php | 2 +- htdocs/core/lib/security.lib.php | 2 +- htdocs/core/lib/signature.lib.php | 8 ++++---- htdocs/public/onlinesign/newonlinesign.php | 15 +++++++-------- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 6052eb076be..494ec1faecf 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -10828,7 +10828,7 @@ abstract class CommonObject if (array_key_exists('ref', $fieldvalues)) { $fieldvalues['ref'] = dol_string_nospecial($fieldvalues['ref']); // If field is a ref, we sanitize data } - if (getDolGlobalString('MAIN_DISABLE_AUTO_UPDATE_OF_TMS_FIELDS') && array_key_exists('tms', $fieldvalues)) { // If we want the explicit update of tms fields instead of deprecated update by database + if (getDolGlobalString('MAIN_DISABLE_AUTO_UPDATE_OF_TMS_FIELDS') && array_key_exists('tms', $fieldvalues)) { // If we want the explicit update of tms fields instead of the deprecated update by database $fieldvalues['tms'] = $this->db->idate($now); } diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index 2be8567db8b..f41af9dde1e 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -359,7 +359,7 @@ function dol_hash($chain, $type = '0', $nosalt = 0, $mode = 0) * * @param string $chain String to hash (not hashed string) * @param string $hash hash to compare - * @param string $type Type of hash ('0':auto, '1':sha1, '2':sha1+md5, '3':md5, '4': for OpenLdap, '5':sha256). Use '3' here, if hash is not needed for security purpose, for security need, prefer '0'. + * @param string $type Type of hash ('0':auto, '1':sha1, '2':sha1+md5, '3':md5, '4': for OpenLdap, '5':sha256, 'hash'). Use '3' here, if hash is not needed for security purpose, for security need, prefer '0'. * @return bool True if the computed hash is the same as the given one * @see dol_hash() */ diff --git a/htdocs/core/lib/signature.lib.php b/htdocs/core/lib/signature.lib.php index ad7a4696a51..ba78d5c008c 100644 --- a/htdocs/core/lib/signature.lib.php +++ b/htdocs/core/lib/signature.lib.php @@ -116,7 +116,7 @@ function getOnlineSignatureUrl($mode, $type, $ref = '', $localorexternal = 1, $o if ($mode == 1) { $out .= "hash('".$securekeyseed."' + '".$type."' + proposal_ref)"; } else { - $out .= '&securekey='.urlencode(dol_hash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? (empty($obj->entity) ? '' : $obj->entity) : ''), '0')); + $out .= '&securekey='.urlencode(dol_hash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? (empty($obj->entity) ? '' : $obj->entity) : ''), 'hash')); } /* if ($mode == 1) { @@ -160,7 +160,7 @@ function getOnlineSignatureUrl($mode, $type, $ref = '', $localorexternal = 1, $o if ($mode == 1) { $out .= "hash('".$securekeyseed."' + '".$type."' + contract_ref)"; } else { - $out .= '&securekey='.urlencode(dol_hash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? (empty($obj->entity) ? '' : (int) $obj->entity) : ''), '0')); + $out .= '&securekey='.urlencode(dol_hash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? (empty($obj->entity) ? '' : (int) $obj->entity) : ''), 'hash')); } } elseif ($type == 'fichinter') { $securekeyseed = getDolGlobalString('FICHINTER_ONLINE_SIGNATURE_SECURITY_TOKEN', $defaultsalt); @@ -180,7 +180,7 @@ function getOnlineSignatureUrl($mode, $type, $ref = '', $localorexternal = 1, $o if ($mode == 1) { $out .= "hash('".$securekeyseed."' + '".$type."' + fichinter_ref)"; } else { - $out .= '&securekey='.urlencode(dol_hash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? (empty($obj->entity) ? '' : (int) $obj->entity) : ''), '0')); + $out .= '&securekey='.urlencode(dol_hash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? (empty($obj->entity) ? '' : (int) $obj->entity) : ''), 'hash')); } } else { // For example $type = 'societe_rib' $securekeyseed = getDolGlobalString(dol_strtoupper($type).'_ONLINE_SIGNATURE_SECURITY_TOKEN', $defaultsalt); @@ -200,7 +200,7 @@ function getOnlineSignatureUrl($mode, $type, $ref = '', $localorexternal = 1, $o if ($mode == 1) { $out .= "hash('".$securekeyseed."' + '".$type."' + $type + '_ref)"; } else { - $out .= '&securekey='.urlencode(dol_hash($securekeyseed.$type.$ref.(!isModEnabled('multicompany') ? '' : $obj->entity), '0')); + $out .= '&securekey='.urlencode(dol_hash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? (empty($obj->entity) ? '' : (int) $obj->entity) : ''), 'hash')); } } diff --git a/htdocs/public/onlinesign/newonlinesign.php b/htdocs/public/onlinesign/newonlinesign.php index 6521ed4a581..5579a12b97f 100644 --- a/htdocs/public/onlinesign/newonlinesign.php +++ b/htdocs/public/onlinesign/newonlinesign.php @@ -52,13 +52,6 @@ if (is_numeric($entity)) { // Load Dolibarr environment require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; -require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php'; - /** * @var Conf $conf * @var DoliDB $db @@ -69,6 +62,12 @@ require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php'; * * @var string $dolibarr_main_url_root */ +require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/payments.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php'; // Load translation files $langs->loadLangs(array("main", "other", "dict", "bills", "companies", "errors", "members", "paybox", "stripe", "propal", "commercial")); @@ -157,7 +156,7 @@ if ($source == 'proposal') { } elseif ($source == 'societe_rib') { $securekeyseed = getDolGlobalString('SOCIETE_RIB_ONLINE_SIGNATURE_SECURITY_TOKEN', $defaultsalt); } -if (!dol_verifyHash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? $entity : ''), $SECUREKEY, '0')) { +if (!dol_verifyHash($securekeyseed.$type.$ref.(isModEnabled('multicompany') ? $entity : ''), $SECUREKEY, 'hash')) { httponly_accessforbidden('Bad value for securitykey. Value provided '.dol_escape_htmltag($SECUREKEY).' does not match expected value for ref='.dol_escape_htmltag($ref), 403, 1); }