Review main Merged

85705[BUGFIX] Fix undefined array key table in ContextMenuController

Thomas Hohn CR +2 V +2 Easy +23 −8 updated 04/11/25, 14:01

Commit message

Ensure that the ContextMenuController checks if the required
table and uid query parameters are provided and return a 400
if not.

Also make sure the frontend part throws an error if invalid
markup is used that would lead to the mentioned 400 response.

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

Review log 7997

Show 5872 earlier messages
  1. Thomas Hohn uploaded patch set 1 08/21/24, 04:53

  2. 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

  3. Garvin Hicking commented on patch set 1 08/21/24, 05:15

    ContextMenuController.php:43

    Hm, a query wouldn't make sense without having the table set? I feel like we would rather need to detect where a contexrMenuAction gets called without that param, and prevent that? Having a json request get executed without the proper parameters sounds like the real bug?
  4. Thomas Hohn commented on patch set 1 08/21/24, 05:31

    ContextMenuController.php:43 Reply

    As 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
  5. Garvin Hicking commented on patch set 1 08/21/24, 06:51

    ContextMenuController.php:43 Reply

    I 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.
  6. 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.
  7. 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...
  8. 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?
  9. 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.
  10. Thomas Hohn uploaded patch set 2 CR -1 V +1 08/21/24, 08:36

  11. 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

  12. Garvin Hicking commented on patch set 2 08/21/24, 08:43

    context-menu.ts:227

    Maybe check for both NULL and empty string? I suppose this to help with debugging for now?
  13. Thomas Hohn commented on patch set 2 08/21/24, 08:53

    Reply

    At least that would be better than thrown the PHP error

    context-menu.ts:227 Reply

    Hi - 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}">
  14. Thomas Hohn commented on patch set 2 08/21/24, 09:00

    context-menu.ts:227 Reply

    But since data-contextmenu-table is not set - it cant be the case here.
  15. Thomas Hohn uploaded patch set 3 V +1 08/21/24, 09:06

  16. Thomas Hohn commented on patch set 3 08/21/24, 09:07

    Reply

    Done

    context-menu.ts:227 Reply

    Done

    ContextMenuController.php:43 Reply

    Done
  17. 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

  18. 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! :)
  19. 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).
  20. 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?
  21. Thomas Hohn uploaded patch set 4 CR +1 V +1 09/30/24, 08:07

  22. 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.
  23. Thomas Hohn commented on patch set 4 09/30/24, 08:10

    Reply

    Is guess the frontend catches both now 😊
  24. Benjamin Franzke commented on patch set 4 09/30/24, 08:11

    ContextMenuController.php:42

    This 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.
  25. Thomas Hohn commented on patch set 4 09/30/24, 08:14

    ContextMenuController.php:42 Reply

    Acknowledged
  26. 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

  27. Thomas Hohn uploaded patch set 5 V -1 09/30/24, 08:21

  28. 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

  29. Thomas Hohn commented on patch set 5 09/30/24, 08:33

    ContextMenuController.php:42 Reply

    Hrm @ben@bnf.dev - the tests seems to dislike that solution - or ?
  30. Thomas Hohn updated the commit message in patch set 6 V -1 10/01/24, 10:16

  31. 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

  32. Thomas Hohn uploaded patch set 7 V -1 10/01/24, 12:23

  33. 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

  34. Thomas Hohn uploaded patch set 8 V -1 10/01/24, 12:33

  35. 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

  36. Thomas Hohn commented on patch set 8 10/01/24, 12:40

    Reply

    Done

    ContextMenuController.php:42 Reply

    Done
  37. Garvin Hicking voted on patch set 8 CR +1 V +1 10/02/24, 19:19

  38. Guido Schmechel voted on patch set 8 CR +1 10/02/24, 21:14

  39. Markus Klein voted on patch set 8 CR +1 V +1 10/04/24, 12:20

  40. Benjamin Franzke voted on patch set 8 CR +1 10/07/24, 16:30

  41. Benjamin Franzke commented on patch set 8 CR -1 V -1 10/08/24, 05:00

    context-menu.ts:227

    value is `undefined` not `null` if unset.
  42. Benjamin Franzke uploaded patch set 9 CR +1 V +1 10/08/24, 05:04

  43. Benjamin Franzke commented on patch set 9 10/08/24, 05:04

    context-menu.ts:227 Reply

    Done
  44. Garvin Hicking voted on patch set 9 CR +1 V +1 10/08/24, 05:13

  45. 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

  46. Andreas Kienast commented on patch set 9 CR -1 10/08/24, 05:41

    ContextMenuController.php:45

    What's the reason we use trim() only for the condition, but not for subsequent usages?
  47. Thomas Hohn commented on patch set 9 10/08/24, 05:45

    ContextMenuController.php:45 Reply

    You 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
  48. Thomas Hohn uploaded patch set 10 CR +1 V +1 10/08/24, 05:51

  49. Andreas Kienast commented on patch set 10 10/08/24, 05:54

    ContextMenuController.php:45 Reply

    Why can't we simply do ``` $table = trim($params['table'] ?? ''); $identifier = trim($params['uid'] ?? ''); ```
  50. 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

  51. Thomas Hohn uploaded patch set 11 V +1 10/08/24, 05:59

  52. Thomas Hohn commented on patch set 11 10/08/24, 06:00

    ContextMenuController.php:45 Reply

    Acknowledged
  53. 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

  54. Andreas Kienast voted on patch set 11 CR +1 10/08/24, 06:07

  55. 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.
  56. Thomas Hohn updated the commit message in patch set 12 CR +1 V +1 10/08/24, 06:28

  57. Thomas Hohn commented on patch set 12 10/08/24, 06:29

    Reply

    Acknowledged
  58. 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

  59. Benjamin Franzke commented on patch set 12 CR -1 10/08/24, 06:56

    not going to be merged now, this needs more work

    context-menu.ts:231

    This check is now unneeded

    context-menu.ts:233

    If we check table we also need to check these ones.
  60. Benjamin Franzke uploaded patch set 13 CR -1 V +1 10/08/24, 07:08

  61. Benjamin Franzke commented on patch set 13 10/08/24, 07:08

    context-menu.ts:231 Reply

    Done

    context-menu.ts:233 Reply

    Done
  62. 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?
  63. 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

  64. 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.
  65. Benjamin Franzke voted on patch set 13 CR -1 10/08/24, 12:46

  66. 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?
  67. Oliver Hader updated the commit message in patch set 14 CR -1 V +1 10/18/24, 14:00

  68. 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

  69. 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
  70. 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.
  71. Benni Mack marked it work in progress 03/27/25, 17:40

  72. 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
  1. Benni Mack uploaded patch set 15 V +1 03/31/25, 08:54

  2. 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

  3. Thomas Hohn marked it ready for review 03/31/25, 09:12

  4. Thomas Hohn commented on patch set 15 03/31/25, 09:13

    Reply

    Thx for the rebase
  5. Thomas Hohn commented on patch set 15 03/31/25, 09:14

    Reply

    Site was green with dbdoctor and still occurs occasionally
  6. Benni Mack commented on patch set 15 03/31/25, 09:21

    Reply

    running v12 or v13?
  7. 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
  8. Thomas Hohn commented on patch set 15 04/01/25, 05:36

    Reply

    Done
  9. Georg Ringer voted on patch set 15 CR +1 V +1 04/01/25, 06:00

  10. Thomas Hohn uploaded patch set 16 CR +1 V +1 04/10/25, 05:56

  11. 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

  12. Markus Klein voted on patch set 16 CR +1 V +1 04/10/25, 06:13

  13. Andreas Kienast commented on patch set 16 04/10/25, 06:18

    context-menu.ts:122

    It 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
  14. Thomas Hohn commented on patch set 16 04/10/25, 06:21

    context-menu.ts:122 Reply

    If you could find the time to add this I would be happy
  15. Andreas Kienast commented on patch set 16 CR -1 04/10/25, 07:37

    on it
  16. Andreas Kienast rebased onto patch set 17 CR +1 V +1 04/10/25, 07:46

  17. Andreas Kienast uploaded patch set 18 04/10/25, 07:46

  18. Andreas Kienast commented on patch set 18 04/10/25, 07:47

    context-menu.ts:122 Reply

    Done
  19. 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

  20. 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

  21. Markus Klein voted on patch set 18 CR +1 V +1 04/10/25, 09:31

  22. 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.
  23. 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!
  24. Benni Mack voted on patch set 18 CR +2 V +2 04/11/25, 14:01

  25. Benni Mack merged patch set 19 04/11/25, 14:01