From c5a253135a23a5fabe8af0d0bd670f48a70bc04b Mon Sep 17 00:00:00 2001
From: Sybille Peters <sypets@gmx.de>
Date: Mon, 8 Apr 2024 06:52:36 +0200
Subject: [PATCH] [BUGFIX] Fix array access error in EditableRestriction

The class EditableRestriction is used in EXT:linkvalidator to apply
permission restrictions to database queries for current (non-admin)
BE user.

In case of table sys_file_reference, the value for
$GLOBALS['TCA'][$table]['ctrl']['type'] might be "uid_local:type". In
that case, the class EditableRestriction tried to access the TCA
configuration for this field via $GLOBALS['TCA']['sys_file_reference']
['columns']['uid_local:type']['config']
when in fact this will be empty (and the type refers to the table
sys_file).

We now check if the resulting array is empty and skip the check if
that is the case.

Resolves: #103559
Related: #83835
Releases: main, 12.4, 11.5
Change-Id: Idbe653ef9f1c21c077fcb79c03212e606cc71830
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/84829
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: core-ci <typo3@b13.com>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
---
 .../Classes/QueryRestrictions/EditableRestriction.php      | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/typo3/sysext/linkvalidator/Classes/QueryRestrictions/EditableRestriction.php b/typo3/sysext/linkvalidator/Classes/QueryRestrictions/EditableRestriction.php
index 0c1668c796a1..7091351a3040 100644
--- a/typo3/sysext/linkvalidator/Classes/QueryRestrictions/EditableRestriction.php
+++ b/typo3/sysext/linkvalidator/Classes/QueryRestrictions/EditableRestriction.php
@@ -66,7 +66,12 @@ class EditableRestriction implements QueryRestrictionInterface
         foreach ($searchFields as $table => $fields) {
             if ($table !== 'pages' && ($GLOBALS['TCA'][$table]['ctrl']['type'] ?? false)) {
                 $type = $GLOBALS['TCA'][$table]['ctrl']['type'];
-                $fieldConfig = $GLOBALS['TCA'][$table]['columns'][$type]['config'];
+                $fieldConfig = $GLOBALS['TCA'][$table]['columns'][$type]['config'] ?? [];
+                if ($fieldConfig === []) {
+                    // $type might be "uid_local:type" for table "sys_file_reference" and then $fieldConfig will be empty
+                    // in this case we skip because we do not join with the other table and will not have this value
+                    continue;
+                }
                 // Check for items
                 if ($fieldConfig['type'] === 'select'
                     && is_array($fieldConfig['items'] ?? false)
-- 
GitLab