-
Notifications
You must be signed in to change notification settings - Fork 338
Closed
Labels
Exp: SPP0High priorityHigh priorityType: BugSomething isn't workingSomething isn't workingType: SupportSupport requestSupport request
Description
Bug Description
In #5868 we implemented a fix which resolves redirect issues on sites using internationalized domain names (IDN). This involves the use of a core PHP multibyte string function which may not exist on some environments. While the mbstring module is commonly enabled, it is not enabled by default so we cannot rely on it to be generally available.
WordPress polyfills a few mb_* functions, (e.g. mb_substr, and mb_strlen) but not all of them.
Steps to reproduce
- Reproducing this requires the
mbstringPHP module to be disabled - Various actions could raise this error as the hooked function runs during
wp_validate_redirectwhich itself is called by various functions, notably wp_safe_redirect() - E.g. disconnect your user in Site Kit and navigate to the splash page
- Change the
googlesitekit-splashin the URL togooglesitekit-dashboardand then attempt to navigate to that URL to invoke the redirect - See error
Support topics
Do not alter or remove anything below. The following sections will be managed by moderators only.
Acceptance criteria
- Site Kit should not raise fatal errors in environments where the
mbstringPHP module is not enabled- More specifically, Site Kit should not rely on any
mb_*function to be provided by PHP
- More specifically, Site Kit should not rely on any
- The behavior introduced by Incorrect redirects to WP Dashboard for sites with Internationalised Domain Names #5868 should be preserved
Implementation Brief
- Remove the
allowed_redirect_hostsfilter callback fromPlugin - Reimplement the existing behavior from the
Authentication::allowed_redirect_hostsmethod- Parse the site's hostname with
URL::parseinstead of(wp_)parse_urlfunctions can have problems with multibyte hostnames (see Permuting site URLs can fail for some domains and environments #4776)- Note: we probably want to use
admin_urlas the URL to parse here rather than thehome_urlfor accuracy. The hosts should be the same because SK does not support them being different but this is more accurate because SK only does redirects within WP admin
- Note: we probably want to use
- Replace the use of
mb_check_encodingwith the sameis_asciicheck we use inModule::permute_site_hosts
- Parse the site's hostname with
Test Coverage
- Add test coverage for the behavior in
AuthenticationTestperhaps by testing a number of redirects usingwp_safe_redirectwith ascii + unicode domains and ensure the destination location is as expected (seeRedirectExceptionin our tests for examples)
QA Brief
- Follow the steps to reproduce above, to ensure the error no longer happens
- This issue modifies how the changes in Incorrect redirects to WP Dashboard for sites with Internationalised Domain Names #5868 were implemented but it should continue to work the same as before in a way that is safe for environments that don't have the
mbstringmodule/extension enabled
Changelog entry
- Fix potential errors raised when the
mbstringPHP extension is not loaded.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Exp: SPP0High priorityHigh priorityType: BugSomething isn't workingSomething isn't workingType: SupportSupport requestSupport request