contao icon indicating copy to clipboard operation
contao copied to clipboard

Selecting a file results in 400 Bad Request Ajax Response if selection happens immediately after creating the record

Open chris74656 opened this issue 1 year ago • 2 comments

Affected version(s)

5.4.3

Description

Steps to reproduce in demo.contao.org:

  1. login as k.jones (admin)
  2. click on "themes"
  3. click on "new"
  4. Without doing anything else first, click on "Change selection" of the "Screenshot" field to open the filepicker.
  5. Select any file
  6. Click "Apply" to select the file

The file will not be selected. Network Tools show a 400 Bad Request Error from the Ajax Request: image

This is not a problem specific to the Theme module. The Theme module is just the easiest place to reproduce the issue in the demo installation as it is one of the few places one can open the filepicker immediately after creating a new record, without loading a different (sub)palette first by checking a checkbox or selecting a type. Even just clicking on "new theme" and refreshing the empty form before opening the filepicker will prevent the error from happening. This problem occurs anywhere if the initial palette (not necessarily "default" palette) allows to select a file. In my installation this happens in custom modules and also for the content element "Image" if permissions for a user are set in a way that "Image" is the default type being loaded, so that the content element "type" does not need to be changed to "Image" before opening the picker.

In my logs i can see the 400 error is raised by Ajax.php:231 by a missing parameter "id"

[2024-10-17T16:43:51.460490+02:00] request.ERROR: Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\BadRequestHttpException: "Bad request" at Ajax.php line 231 {"exception":"[object] (Symfony\\Component\\HttpKernel\\Exception\\BadRequestHttpException(code: 0): Bad request at /usr/www/users/maschu/2024/dev/vendor/contao/core-bundle/contao/classes/Ajax.php:231)"} {"request_uri":"https://XXXXXXXXXXXXX/contao?do=mariContentPublication&id=2&ref=1DSQfILQ&rt=2e2414a29f5b3b0166af50dd75aafda5.f5N3N2UtD0E09woeFTjssQnQ69ytnxWZpkHUoKq_5z0.KNQ1ZABEOhZEwUx7W3aPyDyzqrHr133t6nCVjf_HilAW9CEFNBhMbGLFeQ&table=tl_mari_publicationissue","request_method":"POST"}

chris74656 avatar Oct 17 '24 18:10 chris74656

I can not reproduce it in a normal installed demo (5.4, 5.x). This seems to be just related to demo.contao.org, most likely because there is modifications so you can not modify files in the online demo

zoglo avatar Oct 17 '24 18:10 zoglo

I looked into reproducing it in a freshly installed 5.4.3 and at first it seemed to work but i found it requires an additional navigation step inbetween to trigger the error. Maybe i did that at some point in my initial tests without realizing it was necessary to trigger the behavior, sorry. I'll use the theme module again:

  1. login as admin (non-admin has the same issue but this is a fresh install, so all i have is the admin)
  2. go to themes
  3. click on new
  4. set title to "test" and autor to "test"
  5. save and close
  6. click on the modules icon of the new theme (works with layouts and image sizes as well. really just any submodule)
  7. go back to themes by clicking "themes" in the main navigation ("go back" button also works)
  8. click on new to create a second theme
  9. click on change selection for the screenshot input
  10. select any image and click apply

contao

I can provide access to this installation if it is of any help.

This way i can replicate the error reliably in this fresh 5.4.3, in demo.contao.org, as well as 2 other websites running 5.4.3. The error does not happen in 5.3.x

chris74656 avatar Oct 18 '24 09:10 chris74656

Using these reproduction steps I was unable to reproduce the issue in Contao 5.4.x unfortunately.

fritzmg avatar Nov 03 '24 18:11 fritzmg

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Apr 26 '25 02:04 stale[bot]

While I still wasn't able to reproduce this exactly, I did notice that if you click on Save directly after selecting a file (or changing it) the new file won't be saved. You don't even have to be that quick.

fritzmg avatar May 08 '25 08:05 fritzmg

I cannot reproduce this in Contao 5.6. Pretty sure it has been fixed by https://github.com/contao/contao/pull/8036

aschempp avatar Aug 06 '25 19:08 aschempp

I can still reproduce this in 5.6.x-dev.

fritzmg avatar Aug 07 '25 08:08 fritzmg

That is a different issue though, and one that exists since forever. You should create a separate issue for it.

aschempp avatar Aug 07 '25 09:08 aschempp

True 👍

fritzmg avatar Aug 07 '25 09:08 fritzmg