Skip to content

Don't cache requests with a malformed Host header - #1116

Merged
stephdau merged 1 commit into
trunkfrom
fix/malformed-host-caching
Nov 2, 2026
Merged

stephdau merged 1 commit into
trunkfrom
fix/malformed-host-caching

Conversation

@stephdau

@stephdau stephdau commented Nov 2, 2026

Copy link
Copy Markdown
Member

wpsc_is_get_query() checked for a query string by parsing the request URI together with the Host header, so a malformed Host header could make it miss one, and the page could be cached under the wrong URL.

The fix

  • wp-cache-base.php validates the Host header with a new wpsc_is_valid_http_host(): a hostname or a bracketed IPv6 literal, with an optional port from 1 to 65535 written without leading zeros. Anything else turns caching off for that request: nothing is served from the cache or written to it, and the page renders normally.
  • wpsc_is_get_query() now decides from REQUEST_URI alone, through a new wpsc_uri_has_query().
  • wpsc_remove_tracking_params_from_uri() returns the URI unchanged when it can't parse it, rather than an empty string.

Behaviour changes

  • Requests with a malformed Host header are not cached. Browsers and well-behaved clients always send a valid one.
  • A Host header with raw non-ASCII bytes counts as malformed. Browsers send internationalised domain names in punycode, so real visitors aren't affected.

Testing

  • make test: 160 tests, green. The new tests are in WpscIsValidHttpHostTest, WpscUriHasQueryTest and WpscRemoveTrackingParamsTest.
  • make test-integration: 53 tests, green.
  • make lint: clean.

Release Notes

  • Fix: requests with a malformed Host header are no longer cached or served from the cache, so they can no longer overwrite another page's cached copy.

@stephdau stephdau added this to the 3.1.5 milestone Nov 2, 2026
@stephdau stephdau self-assigned this Nov 2, 2026
@stephdau
stephdau merged commit b3a5359 into trunk Nov 2, 2026
7 checks passed
@stephdau
stephdau deleted the fix/malformed-host-caching branch November 2, 2026 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant