Problem/Motivation

Follow-up to #2263569-263: Bypass form caching by default for forms using #ajax.
Steps to reproduce
On drupal frash install.
Convert auto tagging widget on article to autocomplete
Click add more item button multiple time
Check request query
See the screenshot

Proposed resolution

Unknown

Remaining tasks

TBD

User interface changes

None

API changes

Unknown

Data model changes

Unknown

CommentFileSizeAuthor
#54 2508796_ajax_414_error.mp46.73 MBcarolpettirossi
#49 2508796-49.patch2.97 KB_utsavsharma
#49 interdiff_48-49.txt2.74 KB_utsavsharma
#48 core-check_query_for_FORMAT_WRAPPER-2508796-48.patch3.33 KBvidorado
#43 core-check_query_for_FORMAT_WRAPPER-2508796-43.patch3.12 KBChismen
#42 core-check_query_for_FORMAT_WRAPPER-2508796-41.patch3.09 KBChismen
#41 core-check_query_for_FORMAT_WRAPPER-2508796-41.patch3.09 KBChismen
#38 after_2508796-37.png18.46 KBPancho
#38 before_2508796-37.png18.07 KBPancho
#37 core-check_query_for_FORMAT_WRAPPER-2508796-37.patch1.31 KBPancho
#22 Screen Shot 2015-11-16 at 6.40.18 PM.png210.13 KBdeepakaryan1988
#22 interdiff-2508796-13-22.txt0 bytesdeepakaryan1988
#22 core-check_query_for_FORMAT_WRAPPER-2508796-22.patch1.41 KBdeepakaryan1988
#15 Screen Shot 2015-09-16 at 15.15.30.png160.47 KBgints.erglis
#15 Screen Shot 2015-09-16 at 15.14.43.png133.03 KBgints.erglis
#13 core-check_query_for_FORMAT_WRAPPER-2508796-13.patch1.41 KBbruvers
#13 interdiff-10-13.txt460 bytesbruvers
#10 core-check_query_for_FORMAT_WRAPPER-2508796-10.patch1.41 KBbruvers
#9 core-check_query_for_FORMAT_WRAPPER-2508796-9.patch1.4 KBbruvers
#5 2508796.ajax_fixed.20150908.png22.12 KBjaxxed
#2 ajax-check_url_for_FORMAT_WRAPPER-2508796-2.patch1.18 KBbruvers
Screenshot from 2015-06-19 13:54:53.png64.31 KBjibran

Issue fork drupal-2508796

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:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

effulgentsia’s picture

I think the problem is in ajax.js:

ajax.options.url += Drupal.ajax.WRAPPER_FORMAT + '=drupal_' + (element_settings.dialogType || 'ajax');

That runs without checking if ajax.options.url already has that query param in it.

bruvers’s picture

Status: Active » Needs review
FileSize
1.18 KB

The submitted patch checks if the URL already contains FORMAT_WRAPPER and does not append it a second time.

Status: Needs review » Needs work

The last submitted patch, 2: ajax-check_url_for_FORMAT_WRAPPER-2508796-2.patch, failed testing.

Status: Needs work » Needs review
jaxxed’s picture

@bruvers fix looks to have fixed the repeated URL argument.

Attached is a screenshot of traffic captured following the instructions provided in the issue.

Notes:
- originally I wondered why the code didn't replace existing URL values with subsequent values, but @bruvers fix is more elegant, and uses a "first value passed", instead of "last value passed" approach.
- note that there are > 100 coding standards issues with the views module (out of scope for this issue) according to the coder project.

jaxxed’s picture

Status: Needs review » Reviewed & tested by the community
webchick’s picture

Assigned: Unassigned » nod_
Status: Reviewed & tested by the community » Needs review
Issue tags: +JavaScript

Would be good to get nod_ to take a gander at this, since it affects JS.

nod_’s picture

My brain is wrecked right now but it seems possible that the format would change after a request. It means we do not only have to detect the presence of the variable but also it's value.

bruvers’s picture

Updated the patch. It now replaces the value of FORMAT_WRAPPER if it has been set earlier instead of just leaving it unchanged.

bruvers’s picture

Same patch as #9, just changed variable name for consistency with comments.

jaxxed’s picture

Status: Needs review » Reviewed & tested by the community

confirmed testing process. Functionality still behaves as expected.

I am also not aware of any case where the wrapper format changes, but the code should still work.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/misc/ajax.js
@@ -427,15 +427,19 @@
+      var regexPattern = new RegExp(Drupal.ajax.WRAPPER_FORMAT + '=\\w*');

Are we sure that this regex is good enough? Don't we really mean select up the next & or the end? Yes atm wrapper formats don't contain odd characters but it's not hard to imaging a - getting into one.

bruvers’s picture

The new patch improves the regular expression: ignores case and the parameter value now matches any character except the ampersand "&". This should cover any special characters that could appear in the URL.

gints.erglis’s picture

Tested patch from #13 , it solved the issue.

gints.erglis’s picture

There are screenshots with request strings.

gints.erglis’s picture

Status: Needs review » Reviewed & tested by the community

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 13: core-check_query_for_FORMAT_WRAPPER-2508796-13.patch, failed testing.

droplet’s picture

  1. +++ b/core/misc/ajax.js
    @@ -427,15 +427,19 @@
    +    if (ajax.options.url.indexOf(Drupal.ajax.WRAPPER_FORMAT) === -1) {
    

    this condition is also case sensitive.

  2. +++ b/core/misc/ajax.js
    @@ -427,15 +427,19 @@
    +      var regexPattern = new RegExp(Drupal.ajax.WRAPPER_FORMAT + '=[^&]*', 'i');
    

    shouldn't it missing g flag? To clean them all in edge cases.

  3. +++ b/core/misc/ajax.js
    @@ -427,15 +427,19 @@
    +      var regexPattern = new RegExp(Drupal.ajax.WRAPPER_FORMAT + '=[^&]*', 'i');
    

    although it works, I think it still worth to add hardcoded `drupal_` namespace to regex.

  4. var WRAPPER_FORMAT = '_wrapper_format';
    var regexPattern = new RegExp( WRAPPER_FORMAT + '=[^&]*', 'i');
    "test?should_not_replaced_this_wrapper_format=z".replace(regexPattern, '!!!OUCH!!!');
    

    additional to above point, it's rarely but may occur.

jibran’s picture

Issue tags: +Needs reroll
deepakaryan1988’s picture

Assigned: Unassigned » deepakaryan1988
deepakaryan1988’s picture

deepakaryan1988’s picture

Assigned: deepakaryan1988 » Unassigned
Status: Needs work » Needs review
ajalan065’s picture

This patch fine for me..
+1

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

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

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Manuel Garcia’s picture

Issue tags: -Needs reroll

Patch on #22 still applies fine.

Fabianx’s picture

This is blocked on tests.

Manuel Garcia’s picture

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

tim.plunkett’s picture

Status: Needs work » Postponed

Copying my comment from #2905676: ajax.js overwrites WRAPPER_FORMAT when already specified, which is apparently a duplicate:

I believe this issue is confusing because of #2504709: Prevent _wrapper_format and ajax_form parameters from bleeding through to generated URLs.

There are a couple things to consider here:
1) _wrapper_format is present on links when it shouldn't be, because of the above issue
2) Appending multiple values for the same key is confusing, and the behavior is not documented. Currently the last value "wins"
3) If you purposefully specify a _wrapper_format, it is currently ignored (solved by my patch)
4) Manually specifying a _wrapper_format may be incorrect, as explained by @droplet in #9

The fix proposed in #10 to me seems like the opposite of the previous fix, and also seems like a workaround for the other issue.

Next steps:
Fix the linked issue so that _wrapper_format doesn't bleed through to links.
Investigate using another mechanism for specifying the wrapper format on a link (not query string)

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Falco010’s picture

Not exactly sure if this is the right issue to address this but here I go..

Currently I am having issues with the wrapper_format bleeding through my urls in the Core modal popup, this is my scenario:

I am using Drupal core modal popup and rendering node detail in the popup.

    return [
      '#type' => 'link',
      '#title' => $this->t('Read on'),
      '#url' => Url::fromRoute('entity.node.canonical', ['node' => $entity->id()]),
      '#attributes' => [
        'class' => ['use-ajax'],
        'data-dialog-type' => 'modal',
        'data-dialog-options' => Json::encode([
          'title' => '',
          'maxWidth' => 915,
          'width' => '80%',
          'height' => 'auto',
          'maxHeight' => '3000',
          'closeOnEscape' => TRUE,
          'closeText' => $this->t('Back to selection'),
        ]),
      ],
    ];

In this popup multiple fields and entities are rendered from the node detail view. Some of these fields are rendered links, the wrapper_format is bleeding trough in all these links and when clicked I see this:
ajax response

As a workaround we are going to remove the wrapper_format query parameter from all urls in the popup with javascript. Does anybody have a better solution for this? Also tried removing these query parameter with hook_link_alter(), but this doesn't work.

Pancho’s picture

Status: Postponed » Needs review
FileSize
1.31 KB

Still experiencing query strings being appended multiple times. Unsure if fixing this might contribute to a solution for #2934463: Ajax is broken in forms built within an Ajax callback, however here's my best-effort plain reroll of the 3 year old and no longer applying patch #22. I'm not a JS expert, so the tests might give an indication if I got it right or not.

@Falco010: No, that's the other issue, see #2504709: Prevent _wrapper_format and ajax_form parameters from bleeding through to generated URLs.

Pancho’s picture

Priority: Normal » Minor
FileSize
18.07 KB
18.46 KB

Tests seem to be passing. The fix doesn't seem to help much with any other issues (as tim.plunkett said, the last value "wins" anyway), but it doesn't hurt either and it is definitely cleaner now, see the before/after screenshots with my working and my failing AJAX callback (lines 2 and 3):

Before:
before

After:
after

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Chismen’s picture

Chismen’s picture

Chismen’s picture

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

vidorado’s picture

_utsavsharma’s picture

Fixed CCF for #48.
Please review.

smustgrave’s picture

Status: Needs review » Needs work

Failures in last builds

Also was previously tagged for tests in #26 which still needs to happen.

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

carolpettirossi’s picture

FileSize
6.73 MB

I'm facing an issue with Drupal 10.1 where the Media Library pagination doesn't work, which might be related to this.

I get 414 URI-Request too long error.

Here's a screencast:
414 error with media pagination

catch’s picture

That's more likely to be solved by #3348789: Compress ajax_page_state.

kevinquillen’s picture

Getting the same issue as #54 now, we cannot paginate any Media Library widgets in use and the patches in #3348789: Compress ajax_page_state won't apply (10.1.3).

vensires’s picture

Status: Needs work » Needs review

I set it as needs review for the MR https://git.drupalcode.org/project/drupal/-/merge_requests/4685 I created.
It contains the fixes from #49 but does apply to Drupal 9.5.x.
For newer versions we would require a rebase or a newer branch.

smustgrave’s picture

Version: 9.5.x-dev » 11.x-dev
Status: Needs review » Needs work

11.x is the current development branch.

Has anyone tried to see if https://www.drupal.org/project/drupal/issues/3348789 fixes the issue?

Also was previously tagged for tests which are still needed

thanks.

akalam’s picture

I can confirm the commit on the issue #3348789: Compress ajax_page_state helps by reducing the size of the request uri, but doesn't solve the duplication when consecutive ajax calls get triggered on a Drupal 10.1 instance.

catch’s picture

#3403077: media_library_opener leads to massive GET requests that break varnish etc. looks like the worst culprit here. If people are seeing the same thing with other AJAX implementations it would be good to document that here.

catch’s picture

Priority: Minor » Major

Bumping to major because this can cause URLs that are too long for varnish and etc.

akalam’s picture

We have found this issue when trying to update a view to use facets v3 as exposed filters and ajax enabled. The view have 7 exposed filters (6 of them are facets) and 1 exposed sorting criteria. The error happens after changing the filters a few times (not too many), for example, applying the filters one by one.

UPDATE: We are facing the issue locally with apache, without varnish. The url raises more than 10k characters long. For example the "sort_by" parameter is duplicated 7 times

akalam’s picture

Finally, our issue was coming from the following patch: https://www.drupal.org/project/drupal/issues/2605218#comment-15002530

After applying the latest version of the MR on #2605218: Views Block Display skips preBlockBuild() call on ajax rebuild the issue went away!

Tom Konda made their first commit to this issue’s fork.

Tom Konda’s picture

I think using URLSearchParams() instead of RegExp(), it makes code more simple than patch #49.
I committed for the 2508796-query-string-for-11.x branch.

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

kwinten-hardies’s picture

I have the same issue as #56 on 10.2.5. The query parameters are duplicated and is too long for our WAF policy.

I am not using facets module.

Patches I have tried: