Skip to content

Marlformed query strings can cause infinate redirects #541

@joehoyle

Description

@joehoyle

This is quite similar to #302 from what I can see.

Steps to reproduce:

  1. Set your front-page to a page in WP settings
  2. Make sure batcache is enabled
  3. Request https://yoursite.com/?=123
  4. Observe redirect_canonical should redirect to https://yoursite.com/
  5. Try to request https://yoursite.com/
  6. Observe an infinite redirect to https://yoursite.com/

When the query string is "malformed", specifically in this case, it's an empty key in ?=123 (no key, value of 123). In these situations $_GET is [], but $_SERVER['QUERY_STRING'] is =123. And, parse_url will be ["query"]=> string(4) "=123"

As you can maybe imagine, this causes issues when the assumption is the query / URL can be re-built from $_GET. One place that makes this assumption is Batcache. Effectively the cache will be stored as if there were no query params (see https://github.com/humanmade/batcache/blob/master/advanced-cache.php#L555, parse_str('=123', $result ) === []).

As redirect_canonical will do a 301 redirect, that redirect will get stored in Batcache against the homepage with no url params cache key. Therefore, the homepage will infinite redirect.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugExisting functionality isn't behaving as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions