From 136be3c1968cd43dc658c3860da82697a2bffeb9 Mon Sep 17 00:00:00 2001 From: Jam Balaya Date: Wed, 22 Jul 2026 03:31:00 +0900 Subject: [PATCH] FIX #34667 checkUserAccessToObject: skip entity check for non-multientity objects (multicompany) (#39246) When the multicompany module is enabled, checkUserAccessToObject() (used by restrictedArea(), e.g. from an ajax tooltip) ran the entity check unconditionally in its default/custom-object branch, building "AND dbt.entity IN (...)". For a custom object whose table has no entity column (ismultientitymanaged = 0), that SQL fails, nb comes back 0 and access is wrongly denied. Guard the branch so the entity test only runs when the object is actually multi-entity managed. Keep the test for legacy classes that never define ismultientitymanaged (null/unset) and for a non-object $object, and skip it only when a class explicitly sets ismultientitymanaged = 0. Supersedes the stale #34667 (by @jyhere) and applies the condition requested by @eldy in its review. Co-authored-by: Claude Opus 4.8 --- htdocs/core/lib/security.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index 15c8baec1bf..8c00a057fac 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -1187,7 +1187,7 @@ function checkUserAccessToObject($user, array $featuresarray, $object = 0, $tabl $sql .= " AND dbt.entity IN (".getEntity($sharedelement, 1).")"; $sql .= " AND (sc.fk_user = ".((int) $user->id)." OR sc.fk_user IS NULL)"; } - } elseif (isModEnabled('multicompany')) { + } elseif (isModEnabled('multicompany') && (!empty($object->ismultientitymanaged) || !isset($object->ismultientitymanaged))) { // If multicompany, and user is an internal user with all permissions, check that object is in correct entity $sql = "SELECT COUNT(dbt.".$dbt_select.") as nb"; $sql .= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt";