Problem/Motivation

Since #3423454: Form Builder does not fully allow Ajax GET requests, FormBuilder::buildForm() throws BrokenPostRequestException when a request has the ajax_form query parameter but no form_id. The check is meant for POST requests truncated by post_max_size, but it also runs for GET requests. This happens when a form submitted with Ajax redirects to itself: the URL becomes /foo?ajax_form=1&_wrapper_format=drupal_ajax, and the browser follows it with GET.

Steps to reproduce

  1. Use a form that is submitted with Ajax and redirects to the same page after submission.
  2. Submit the form. The redirect is a GET request with ajax_form=1&_wrapper_format=drupal_ajax.
  3. The form is not shown. The response contains the error "An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (2 MB) that this server supports."

Shorter way: as an anonymous user, open /user/login?ajax_form=1. The same error is shown instead of the login form.

Proposed resolution

Only throw the exception for POST requests. GET requests with ajax_form are built normally.

Remaining tasks

Review.

User interface changes

None.

API changes

None.

Data model changes

None.

AI usage

An LLM helped with the test fix in MR !17294 and with this summary. The steps to reproduce were checked on main.

Issue fork drupal-3443176

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mkalkbrenner created an issue. See original summary.

mkalkbrenner’s picture

mkalkbrenner’s picture

Status: Active » Needs review
StatusFileSize
new760 bytes
smustgrave’s picture

Version: 10.2.x-dev » 11.x-dev
Status: Needs review » Needs work
Issue tags: +Needs tests

Thanks for reporting. Sounds like something that may need test coverage, 60/40 on that. Since it's a small change but is marked major.

sahana _n made their first commit to this issue’s fork.

sahana _n’s picture

Status: Needs work » Needs review

Hi,

I tried to reproduce the issue in Drupal 11. x and successfully the issue is reproduced.

Reproducing steps
1. Install Drupal Core 11.x
2. Created the custom form with the file element.
3. On submission called Ajax callback.

I created an MR please review it.
If there are any inaccuracies, I would greatly appreciate your suggestions for improvement.
Thanks!!

smustgrave’s picture

Status: Needs review » Needs work

Previously tagged for tests which still appear to be needed

Also MR appears to be the same as the patch, was there any change?

anchal_gupta’s picture

StatusFileSize
new223.89 KB
new91.23 KB

I have test this issue with the latest merge request. Its working fine as per expectation.
Also attach screenshot.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

brandonlira made their first commit to this issue’s fork.

brandonlira’s picture

Status: Needs work » Needs review

Opened a new MR against current main: MR!17294.

The previous MR was significantly behind main and had conflicts, so I recreated the change on a fresh branch.

This keeps BrokenPostRequestException limited to broken AJAX POST submissions and adds direct test coverage for AJAX GET form requests with ajax_form=1 but no form_id.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new1.16 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

mehdi.najeddine made their first commit to this issue’s fork.

mehdi.najeddine’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

Pushed a commit to MR !17294. It replaces the @legacy-covers annotation on testGetAjaxRequestWithoutFormId with @see ::buildForm. Core PHPStan no longer allows @legacy-covers on test methods, which caused the failure reported by the bot. With the FormBuilder.php change reverted, testGetAjaxRequestWithoutFormId fails with BrokenPostRequestException. With the change, all 51 tests in FormBuilderTest pass, and the form unit and kernel tests pass too.

Generated with the help of an LLM.

smustgrave’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update, +Needs steps to reproduce

Can the summary template be updated, can mention use of AI there too.

But as a bug should have the steps to reproduce section

mehdi.najeddine’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs issue summary update, -Needs steps to reproduce

Updated the issue summary with the bug template and steps to reproduce. The AI use is noted there.

Generated with the help of an LLM.

mehdi.najeddine’s picture

Issue summary: View changes