Make WordPress Core

Opened 8 years ago

Last modified 8 days ago

#44899 new defect (bug)

redirect_canonical redirects to another URL when it should not

Reported by: melicerte Owned by:
Priority: normal Milestone: Awaiting Review
Component: Canonical Version: 4.9.8
Severity: critical Keywords: has-patch has-unit-tests
Cc: Focuses:

Description

Hi,

on a fresh install of WordPress 4.9.8 :

​http://sub.yourdomain.com/?xtor=AD-4970-%5BSocial%5D-%5B%5D-%5BPPL%5D-%5BFacebook%5D-%5B228284160&105478095%5D-%5B0%5D

will be redirected to :

​http://sub.yourdomain.com/?xtor=AD-4970-%5BSocial%5D-%5B%5D-%5BPPL%5D-%5BFacebook%5D-%5B228284160&105478095]-%5B0%5D

Problem is : it does an 301. And, combined with Facebook mobile on Iphone link to the WordPress, it retries forever. 21 000 hits / 5 minutes on our server. Glad it was strong enough to sustain until we find the bug and temporarily deactivated

redirect_canonical

with :

<?php
remove_action('template_redirect', 'redirect_canonical');

Change History (5)

#1 @melicerte
8 years ago

  • Summary redirect_canonical redirects to another URL → redirect_canonical redirects to another URL when it should not

#2 @SergeyBiryukov
8 years ago

  • Component General → Canonical
  • Keywords needs-unit-tests added

This ticket was mentioned in ​PR #13654 on ​WordPress/wordpress-develop by ​@faisalahammad.


7 weeks ago
#3

  • Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed

https://core.trac.wordpress.org/ticket/44899

Add a regression test for encoded query string keys on a static front page. The existing canonical redirect logic already handles these keys correctly, but the ticket has no direct test covering the reported URL shape.

The test confirms that redirect_canonical() does not generate a redirect when the query string contains an encoded closing bracket in a parameter name.

Scope:
This change is limited to PHPUnit coverage for the canonical redirect behavior. No production code, public APIs, UI, accessibility, CSS, RTL, administration, or performance behavior is changed.

Testing:

  • docker exec wordpress-develop-php-1 sh -lc 'cd /var/www && ./vendor/bin/phpunit --filter test_encoded_query_string_keys_on_front_page tests/phpunit/tests/canonical.php'
  • vendor/bin/phpcs --standard=phpcs.xml.dist tests/phpunit/tests/canonical.php

#4 @lancewillett
8 days ago

In 65132:

Tests: Cover canonical redirect regressions.

Verify encoded query keys on a static front page and prevent redirect guesses from exposing a private post type mixed with a public one.

Developed in: ​https://github.com/WordPress/wordpress-develop/pull/13654, ​https://github.com/WordPress/wordpress-develop/pull/12941

Props faisalahammad, huzaifaalmesbah, irozum.
See #44899, #44964.

Note: See TracTickets for help on using tickets.