Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent false positive in redirect_extraneous_paired_endpoint which needlessly redirects (into infinity) #6494

Merged
merged 3 commits into from
Jul 30, 2021

Conversation

westonruter
Copy link
Member

Summary

The remove_query_arg() function in WordPress is non-idempotent, meaning that if a query var is not present it can still result in a change to the URL (such as converting %20 to +):

wp> remove_query_arg('amp', '/?test=one+two+three')
=> string(20) "/?test=one+two+three"
wp> remove_query_arg('amp', '/?test=one%20two%20three')
=> string(20) "/?test=one+two+three"

This is problematic because redirect_canonical() does the opposite when it re-constructs the URL with parse_str() and rawurlencode_deep(), where rawurlencode_deep() results in spaces being encoded as %20 instead of +.

The result is an infinite redirects between URLs with + and %20 when trying to access a URL with a query string that contains spaces in it.

The fix is to check whether the URL explicitly has the query var before trying to remove it, rather than checking if the URL with the query var removed was changed. This is essentially the same thing that was done before in #5804.

Fixes #6492

Checklist

  • My code is tested and passes existing tests.
  • My code follows the Engineering Guidelines (updates are often made to the guidelines, check it out periodically).

@westonruter westonruter added the Routing Handling URLs label Jul 28, 2021
@westonruter westonruter added this to the v2.1.4 milestone Jul 28, 2021
@westonruter westonruter requested a review from pierlon July 28, 2021 23:54
@westonruter westonruter changed the title Avoid redirect_extraneous_paired_endpoint from needlessly redirecting Avoid redirect_extraneous_paired_endpoint from needlessly redirecting (into infinity) Jul 28, 2021
@westonruter westonruter changed the title Avoid redirect_extraneous_paired_endpoint from needlessly redirecting (into infinity) Prevent false positive in redirect_extraneous_paired_endpoint which needlessly redirects (into infinity) Jul 28, 2021
@github-actions
Copy link
Contributor

Plugin builds for 92e7855 are ready 🛎️!

Copy link
Contributor

@pierlon pierlon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow nice find! LGTM :shipit:.

@pierlon pierlon merged commit 8a91ba5 into develop Jul 30, 2021
@pierlon pierlon deleted the fix/redirect-extraneous-paired-endpoint branch July 30, 2021 00:30
westonruter added a commit that referenced this pull request Jul 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Routing Handling URLs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Redirect Loop with multiple spaces in the url
2 participants