From f20581cf86f9e53cb994ea4da8d914801d38be61 Mon Sep 17 00:00:00 2001 From: VIAL-GOUTEYRON Quentin Date: Fri, 14 Aug 2026 17:56:23 +0200 Subject: [PATCH] FIX Contact documents were readable by any external user (#39516) dol_check_secure_access_document() built its protection query against a table named socpepople, which does not exist. The query therefore always failed, so document.php and viewimage.php never iterated its result and never lowered $accessallowed back to 0. Any external user having the permission to read contacts could consequently download the documents of any contact, including the contacts of other third parties. Note that this also restores the intended behaviour for the contacts having no third party: an external user no longer has access to their documents, since the query returns a NULL fk_soc that cannot match their own. The typo was introduced in 0dd9e6acc25 on 2026-07-20, so only develop and the 24.0 branch are affected, no released version is. Co-authored-by: Laurent Destailleur --- htdocs/core/lib/files.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index e3806896372..42c914411d7 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -3445,7 +3445,7 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, $accessallowed = 1; } $original_file = $conf->societe->multidir_output[$entity].'/contact/'.$original_file; - $sqlprotectagainstexternals = "SELECT fk_soc FROM ".MAIN_DB_PREFIX."socpepople WHERE rowid = ".((int) $refname)." AND entity IN (".getEntity('contact').")"; + $sqlprotectagainstexternals = "SELECT fk_soc FROM ".MAIN_DB_PREFIX."socpeople WHERE rowid = ".((int) $refname)." AND entity IN (".getEntity('contact').")"; } elseif (($modulepart == 'facture' || $modulepart == 'invoice') && !empty($conf->invoice->multidir_output[$entity])) { // Wrapping for invoices if ($fuser->hasRight('facture', $lire) || preg_match('/^specimen/i', $original_file)) {