85705[BUGFIX] Fix undefined array key table in ContextMenuController
Commit message
Review
-
Code review CR +2 Done
- Benni Mack +2
- Markus Klein +1
-
Verified V +2 Done
- Benni Mack +2
- Markus Klein +1
- core-ci +1 CI
Issues 1
Files 5
- Build/Sources/TypeScript/backend/tree/page-tree-element.ts+1 −1
- Build/Sources/TypeScript/backend/context-menu.ts13+12 −4
- typo3/sysext/backend/Classes/Controller/ContextMenuController.php12+8 −1
- typo3/sysext/backend/Resources/Public/JavaScript/tree/page-tree-element.js+1 −1
- typo3/sysext/backend/Resources/Public/JavaScript/context-menu.js+1 −1
Review log 7997
Show 5872 earlier messages
-
Thomas Hohn uploaded patch set 1 08/21/24, 04:53
-
core-ci voted on patch set 1 V +1 08/21/24, 04:58 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63875
-
Garvin Hicking commented on patch set 1 08/21/24, 05:15
-
Thomas Hohn commented on patch set 1 08/21/24, 05:31
ContextMenuController.php:43ReplyAs mentioned it the issue it's a weird race condition - the uid is -1 might help somebody. Used 1/2 day yesterday to try to reproduce it -
Garvin Hicking commented on patch set 1 08/21/24, 06:51
ContextMenuController.php:43ReplyI guess it should be executed via ContextMenu.show() in Build/Sources/TypeScript/backend/context-menu.ts (which you probably also found). There I can see: ``` private handleContextMenuEvent(event: PointerEvent, element: HTMLElement): void { const contextTrigger: string = element.dataset.contextmenuTrigger; if (contextTrigger === 'click' || contextTrigger === event.type) { event.preventDefault(); this.show( element.dataset.contextmenuTable ?? '', element.dataset.contextmenuUid ?? '', element.dataset.contextmenuContext ?? '', '', '', element, event ); } } ``` so it seems possible that the AJAX request is done with an empty table (but probably a contextmenuUid of -1). Adding JS debugging to be persisted in a logfile is tricky, else I would suggest to do some logging at that point and see what shows up, and log a stacktrace that leads to an empty table. I just feel that by fixing the symptom, we might not find the cause here. -
Andreas Kienast commented on patch set 1 CR -1 08/21/24, 06:59
Context menus are not designed to use an empty table. It might solve the issue, but it's not a real fix. It's interesting whether the call come from Core or a bogus 3rd party extension. -
Thomas Hohn commented on patch set 1 08/21/24, 07:05
Reply
Hi - could you explain how that could be configured - then I'll have a look - but I'm pretty sure we only use solr and I dont think there is a specific context menu there... -
Garvin Hicking commented on patch set 1 08/21/24, 07:06
Reply
Should handleContextMenuEvent then abort or throw exceptions in case element.dataset.contextmenuTable is empty, instead of ?? '' and executing the request? -
Andreas Kienast commented on patch set 1 08/21/24, 08:24
Reply
@tho@gyldendal.dk: there are two ways to trigger context menus: 1. JavaScript 2. plain markup Either check the calls to `ContextMenu.show()` in JavaScript code, or check whether markup, that uses `data-contextmenu-trigger` also has `data-contextmenu-table` set to a proper value. -
Thomas Hohn uploaded patch set 2
CR -1V +108/21/24, 08:36 -
core-ci voted on patch set 2 V +1 08/21/24, 08:43 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63887
-
Garvin Hicking commented on patch set 2 08/21/24, 08:43
context-menu.ts:227Maybe check for both NULL and empty string? I suppose this to help with debugging for now? -
Thomas Hohn commented on patch set 2 08/21/24, 08:53
Reply
At least that would be better than thrown the PHP errorcontext-menu.ts:227ReplyHi - did as @a.fernandez@scripting-base.de suggested - could not find code like that in whats is installed (besides core) ... Only place in core - could be here: data-contextmenu-table="{item.table}" data-contextmenu-uid="{item.record.uid}"> -
Thomas Hohn commented on patch set 2 08/21/24, 09:00
context-menu.ts:227ReplyBut since data-contextmenu-table is not set - it cant be the case here. -
Thomas Hohn uploaded patch set 3
V +108/21/24, 09:06 -
Thomas Hohn commented on patch set 3 08/21/24, 09:07
Reply
Donecontext-menu.ts:227ReplyDoneContextMenuController.php:43ReplyDone -
core-ci voted on patch set 3 V +1 08/21/24, 09:14 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63890
-
Garvin Hicking commented on patch set 3 CR +1 V +1 09/05/24, 08:36
This check would be fine by me to prevent forwarding errors to PHP land, thanks! :) -
Benjamin Franzke commented on patch set 3 CR -1 09/30/24, 07:13
A PHP warning can never be "fixed" by changed the frontend. It's a workaround, but does not solve the backend issue (adapting the frontend is fine, but the backend needs to be fixed in any case). -
Garvin Hicking commented on patch set 3 09/30/24, 08:05
Reply
IMO the PHP error that occurs would be valid/wanted, because the AJAX endpoint would be called with "invalid" parameters, with the current frontend. So what this patch addresses is to prevent an invalid AJAX request getting sent. If we fix the PHP backend by preventing a PHP error, that would make an invalid request not fail properly? -
Thomas Hohn uploaded patch set 4
CR +1V +109/30/24, 08:07 -
Andreas Kienast commented on patch set 3 09/30/24, 08:08
Reply
We can check the mandatory arguments and throw a BadRequestException, which is still a "failing" request, but a controlling one. -
Thomas Hohn commented on patch set 4 09/30/24, 08:10
Reply
Is guess the frontend catches both now 😊 -
Benjamin Franzke commented on patch set 4 09/30/24, 08:11
ContextMenuController.php:42This needs to return a bad request and not handle it as if it was valid input, so: ``` return new JsonRespone([], 400); ``` if `table` or `identifier` is not defined or an empty string. -
Thomas Hohn commented on patch set 4 09/30/24, 08:14
ContextMenuController.php:42ReplyAcknowledged -
core-ci voted on patch set 4 V -1 09/30/24, 08:15 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66836
-
Thomas Hohn uploaded patch set 5
V -109/30/24, 08:21 -
core-ci voted on patch set 5 V -1 09/30/24, 08:30 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66837
-
Thomas Hohn commented on patch set 5 09/30/24, 08:33
ContextMenuController.php:42ReplyHrm @ben@bnf.dev - the tests seems to dislike that solution - or ? -
Thomas Hohn updated the commit message in patch set 6
V -110/01/24, 10:16 -
core-ci voted on patch set 6 V -1 10/01/24, 10:25 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66884
-
Thomas Hohn uploaded patch set 7
V -110/01/24, 12:23 -
core-ci voted on patch set 7 V -1 10/01/24, 12:32 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66889
-
Thomas Hohn uploaded patch set 8
V -110/01/24, 12:33 -
core-ci voted on patch set 8 V +1 10/01/24, 12:39 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/66890
-
Thomas Hohn commented on patch set 8 10/01/24, 12:40
Reply
DoneContextMenuController.php:42ReplyDone -
Garvin Hicking voted on patch set 8 CR +1 V +1 10/02/24, 19:19
-
Guido Schmechel voted on patch set 8 CR +1 10/02/24, 21:14
-
Markus Klein voted on patch set 8 CR +1 V +1 10/04/24, 12:20
-
Benjamin Franzke voted on patch set 8 CR +1 10/07/24, 16:30
-
Benjamin Franzke commented on patch set 8 CR -1 V -1 10/08/24, 05:00
context-menu.ts:227value is `undefined` not `null` if unset. -
Benjamin Franzke uploaded patch set 9
CR +1V +110/08/24, 05:04 -
Benjamin Franzke commented on patch set 9 10/08/24, 05:04
context-menu.ts:227ReplyDone -
Garvin Hicking voted on patch set 9 CR +1 V +1 10/08/24, 05:13
-
core-ci voted on patch set 9 V +1 10/08/24, 05:14 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67310
-
Andreas Kienast commented on patch set 9 CR -1 10/08/24, 05:41
ContextMenuController.php:45What's the reason we use trim() only for the condition, but not for subsequent usages? -
Thomas Hohn commented on patch set 9 10/08/24, 05:45
ContextMenuController.php:45ReplyYou could argue that it would make sense to use it there too - I guess it was more to catch weird variants of an "empty" string -
Thomas Hohn uploaded patch set 10
CR +1V +110/08/24, 05:51 -
Andreas Kienast commented on patch set 10 10/08/24, 05:54
ContextMenuController.php:45ReplyWhy can't we simply do ``` $table = trim($params['table'] ?? ''); $identifier = trim($params['uid'] ?? ''); ``` -
core-ci voted on patch set 10 V +1 10/08/24, 05:56 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67315
-
Thomas Hohn uploaded patch set 11
V +110/08/24, 05:59 -
Thomas Hohn commented on patch set 11 10/08/24, 06:00
ContextMenuController.php:45ReplyAcknowledged -
core-ci voted on patch set 11 V +1 10/08/24, 06:06 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67316
-
Andreas Kienast voted on patch set 11 CR +1 10/08/24, 06:07
-
Oli Bartsch commented on patch set 11 10/08/24, 06:26
As this won't be - especially because of the JS - no straighforward backport, T think about dropping v11 here. -
Thomas Hohn updated the commit message in patch set 12
CR +1V +110/08/24, 06:28 -
Thomas Hohn commented on patch set 12 10/08/24, 06:29
Reply
Acknowledged -
core-ci voted on patch set 12 V +1 10/08/24, 06:35 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67318
-
Benjamin Franzke commented on patch set 12 CR -1 10/08/24, 06:56
not going to be merged now, this needs more workcontext-menu.ts:231This check is now unneededcontext-menu.ts:233If we check table we also need to check these ones. -
Benjamin Franzke uploaded patch set 13
CR -1V +110/08/24, 07:08 -
Benjamin Franzke commented on patch set 13 10/08/24, 07:08
context-menu.ts:231ReplyDonecontext-menu.ts:233ReplyDone -
Garvin Hicking commented on patch set 12 10/08/24, 07:18
TL;DR: We should closer look at `BackendUtility::wrapClickMenuOnIcon` Since I could never reproduce the race condition myself, I tested this with a custom javascript call which triggers the js check. Sorry, this gets longer, but we've spent so much time on this already, we should catch a breath and go above patching the symptom but finding the cause. The build process turns this: ``` if (element.dataset.contextmenuTable === undefined || element.dataset.contextmenuTable === '') { ``` into this: ``` if(e.preventDefault(),void 0===t.dataset.contextmenuTable ||""===t.dataset.contextmenuTable) ``` which doesn't properly check for a `undefined/null` value. I used the Backend User list which has a context menu trigger on the avatar. Then I edited the minified file and inserted these tests: ``` delete t.dataset.contextmenuTable; // Properly trigger the error t.dataset.contextmenuTable = ''; // Properly trigger the error t.dataset.contextmenuTable = 0; // does NOT trigger the error t.dataset.contextmenuTable = null; // does NOT trigger the error t.dataset.contextmenuTable = undefined; // does NOT trigger the error ``` I am not so skilled in JS so I don't know if that would be the expectation, and not sure how to write TypeScript that this undefined check doesn't get optimized away like this. Now I still wonder where/how exactly the race condition is triggered in your instance. All places I search for with `(contextmenu-trigger|contextmenuTrigger)` in the core only yielded places where always a hard-coded string is passed on to data-contextmenu-trigger: drag-uploader.ts: sys_file EXT:backend/.../NewPages.html: pages EXT:backend/.../RecordsOverview.html: pages EXT:backend/.../SiteConfiguration/Overview.html: pages EXT:beuser/.../BackendUser/PaginatedList.html: be_users EXT:beuser/.../BackendUserGroup/PaginatedList.html: be_groups EXT:beuser/.../Information.html: pages, be_groups, sys_filemounts, sys_category, sys_workspace EXT:beuser/.../Filemount/PaginatedList.html: sys_filemounts EXT:beuser/.../BackendUser/List.html: be_users EXT:beuser/.../Online.html: be_users EXT:beuser/.../BackendUserGroup/List.html: be_groups EXT:reactions/.../Overview.html: sys_reaction EXT:sys_note/List.html: sys_note EXT:webhooks/Overview.html: sys_webhook The only place that looked fishy is in EXT:backend/Resources/Private/Partials/PageLayout/RecordDefault.html which passes `item.table` along; however if `item` would be empty, several other errors should occur already. In PHP-scope though, a call to `BackendUtility::wrapClickMenuOnIcon` has weak type hinting and could actually pass 'null' as a $table value, which gets cast to an empty string when passed along to `getContextMenuAttributes`. So I do think this could be the culprit here and would warrant deeper inspection. In that case the JS could stay unchanged and "just" that wrapClickMenuOnIcon method would need guarding? -
core-ci voted on patch set 13 V +1 10/08/24, 07:21 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/67324
-
Benjamin Franzke commented on patch set 13 CR 0 V 0 10/08/24, 12:46
Reply
Hey, Garvin, Thanks a lot, I'll have a look. Upfront: `void 0 ===` is fine (as `void 0` is `undefined`, but shorter, therefore `terser` replaced that). But I modified to null coalesce which catches `undefined` and `null` and is better anyway. I agree: we should find the curlpit, if there is one. I assumed that this is caused by wrong markup from custom extensions, but we'd need Thomas to analyze his site to verify that. -
Benjamin Franzke voted on patch set 13 CR -1 10/08/24, 12:46
-
Thomas Hohn commented on patch set 13 10/08/24, 13:44
Reply
So - "just" had one today - uid is -1 and context is tree - if that can inspire somebody to come up with a way to reproduce it? -
Oliver Hader updated the commit message in patch set 14
CR -1V +110/18/24, 14:00 -
core-ci voted on patch set 14 V +1 10/18/24, 20:09 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/68100
-
Thomas Hohn commented on patch set 14 02/03/25, 07:25
Reply
Still seeing this error - would be really nice to have it merged -
Benni Mack commented on patch set 14 03/27/25, 17:40
I wonder if your database is set up correctly. We usually check integrity with the dbdoctor package to see if our integrity is correct (I have this with installations that have been running for quite some major versions of TYPO3). If done so and the problem still exists, please come back here and rebase the patch. -
Benni Mack marked it work in progress 03/27/25, 17:40
-
Thomas Hohn commented on patch set 14 03/31/25, 06:12
Reply
So everything is green - was yelling out for the rebase act - since there has been a lot of changes
-
Benni Mack uploaded patch set 15
V +103/31/25, 08:54 -
core-ci voted on patch set 15 V +1 03/31/25, 09:08 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/76718
-
Thomas Hohn marked it ready for review 03/31/25, 09:12
-
Thomas Hohn commented on patch set 15 03/31/25, 09:13
Reply
Thx for the rebase -
Thomas Hohn commented on patch set 15 03/31/25, 09:14
Reply
Site was green with dbdoctor and still occurs occasionally -
Benni Mack commented on patch set 15 03/31/25, 09:21
Reply
running v12 or v13? -
Thomas Hohn commented on patch set 15 03/31/25, 09:22
Reply
Hi - we are still on 12 - the migration for our +3000 sites is planned for fall -
Thomas Hohn commented on patch set 15 04/01/25, 05:36
Reply
Done -
Georg Ringer voted on patch set 15 CR +1 V +1 04/01/25, 06:00
-
Thomas Hohn uploaded patch set 16
CR +1V +104/10/25, 05:56 -
core-ci voted on patch set 16 V +1 04/10/25, 06:02 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/77385
-
Markus Klein voted on patch set 16 CR +1 V +1 04/10/25, 06:13
-
Andreas Kienast commented on patch set 16 04/10/25, 06:18
context-menu.ts:122It would be great to have another `console.error()` referencing the element to have a slight change to debug this. It would also be possible to add `cause` to the Error object, but browsers don't display that in their console: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error/cause#providing_structured_data_as_the_error_cause -
Thomas Hohn commented on patch set 16 04/10/25, 06:21
context-menu.ts:122ReplyIf you could find the time to add this I would be happy -
Andreas Kienast commented on patch set 16 CR -1 04/10/25, 07:37
on it -
Andreas Kienast rebased onto patch set 17
CR +1V +104/10/25, 07:46 -
Andreas Kienast uploaded patch set 18 04/10/25, 07:46
-
Andreas Kienast commented on patch set 18 04/10/25, 07:47
context-menu.ts:122ReplyDone -
core-ci voted on patch set 17 V +1 04/10/25, 07:54 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/77396
-
core-ci voted on patch set 18 V +1 04/10/25, 07:58 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/77397
-
Markus Klein voted on patch set 18 CR +1 V +1 04/10/25, 09:31
-
Benni Mack commented on patch set 18 CR +1 V +1 04/11/25, 12:31
I have checked through our server logs, and I have never ever seen this behavior. For the record, I truly hate patches like this, where we cannot reproduce a behavior. Let's move on because this topic is just dragging along for just too long. -
Thomas Hohn commented on patch set 18 04/11/25, 13:29
Reply
Just checked our logs and we had it recently. We have 3000+ and 1000+ editors - so we see it time to time! -
Benni Mack voted on patch set 18 CR +2 V +2 04/11/25, 14:01
-
Benni Mack merged patch set 19 04/11/25, 14:01
ContextMenuController.php:43