wp search-replace silently writes malformed URLs causing fatal error on next page load
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Start at the search-replace command entry point and reproduce the supplied command with http;//localhost as the replacement. Trace how replacements reach siteurl and home in wp_options; done means malformed URL input is detected before database writes and the user receives the requested clear abort or warning.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug Report
- Yes, I reviewed the [contribution guidelines](https://make.wordpress.org/cli/handbook/contributing/).
- Yes, more specifically, I reviewed the guidelines on [how to write clear bug reports](https://make.wordpress.org/cli/handbook/bug-reports/).
Describe the current, buggy behavior
When running wp search-replace during a site migration, WP-CLI accepts any replacement string without validating it. If the user makes a typo in the new URL — for example http;//localhost instead of http://localhost (; instead of :, a common keyboard mistake when typing without Shift) — the invalid value is written silently to all tables, including siteurl and home in wp_options.
WP-CLI reports success (X replacements made), giving no indication that anything is wrong. On the next page load, WordPress throws a fatal error:
Fatal error: Uncaught ValueError: setcookie(): "path" option cannot contain ",", ";", " ", "\t", "\r", "\n", "\013", or "\014"
in /public_html/wp-content/plugins/polylang-pro/vendor/wpsyntex/polylang/src/cookie.php on line 88
The error originates in cookie-handling code (WordPress core or plugins such as Polylang, WooCommerce, etc.) and gives no hint that the root cause is a typo in the wp search-replace replacement string.
The user sees WordPress's built-in fatal error screen ("There has been a critical error on this website"), which confirms something is broken but still gives no indication that the root cause is a malformed URL written by wp search-replace. The actual ValueError and its cause remain hidden without WP_DEBUG enabled or access to the server error log.
Describe how other contributors can replicate this bug
- Set up a WordPress installation with a working
siteurlandhome, e.g.https://production.example.com - Run a migration search-replace with a typo in the replacement URL:
wp search-replace 'https://production.example.com' 'http;//localhost' --all-tables
- Visit any page of the site
WP-CLI will report success. The site will throw a fatal ValueError in setcookie() on the next page load. The error message references cookie path handling and gives no indication that the replacement URL is malformed.
Describe what you would expect as the correct outcome
WP-CLI should detect that the replacement string contains characters that are illegal in cookie paths (;, ,, space, tab, etc.) when replacing known URL fields (siteurl, home), and either:
- Abort with a clear error: "The replacement string does not appear to be a valid URL. Aborting."
- Or at minimum, print a warning before proceeding: "Warning: replacement string contains characters that may cause issues in cookie paths."
At the very least, the replacement string should be validated as a well-formed URL when it will affect siteurl or home.
Let us know what environment you are running this on
(Paste the output of "wp cli info" into this box)
Confirmed to affect:
- PHP 8.0+ (where
setcookie()throws a fatalValueErrorinstead of silently ignoring illegal characters as PHP 7.x did) - Any WordPress version that derives
COOKIEPATH/SITECOOKIEPATHfromsiteurl/home
Provide a possible solution
In the search-replace command, validate the replacement string as a URL if it resembles one (starts with http:// or https://). Specifically:
- Check for characters forbidden in cookie paths:
;,,, space,\t,\r,\n - If found, abort or warn before writing to the database
Alternatively, an interactive prompt such as "Replacement string looks unusual, continue? [y/N]" could help catch such typos before any data is written.
Provide additional context
This issue became significantly more impactful with PHP 8.0, which changed setcookie() behavior from silently ignoring invalid path characters to throwing a fatal ValueError. Sites that had malformed URLs in their database for years without issues will now crash immediately after migrating to PHP 8+.
The wp search-replace command is the standard recommended tool for WordPress migrations, making it the most common entry point for this class of error. The combination of factors below makes it difficult to diagnose without prior knowledge, particularly on shared hosting:
wp search-replacereports success with no warnings- The site shows WordPress's generic critical error screen with no details about the cause
- The server error log — if accessible at all — points to cookie-handling code, not to the malformed URL
- The connection between a typo in the migration command and a fatal error in cookie handling is non-obvious
OS: Linux 4.18.0-553.111.1.lve.el8.x86_64 #1 SMP Fri Mar 13 13:42:17 UTC 2026 x86_64
Shell: /bin/bash
PHP binary: /opt/alt/php83/usr/bin/php
PHP version: 8.3.30
php.ini used: /opt/alt/php83/etc/php.ini
MySQL binary: /usr/bin/mariadb
MySQL version: mariadb from 11.4.10-MariaDB, client 15.2 for Linux (x86_64) using EditLine wrapper
SQL modes:
WP-CLI root dir: phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir: phar://wp-cli.phar/vendor
WP_CLI phar path: phar:///home/yser/bin/wp-cli.phar
WP-CLI packages dir: /home/user/.wp-cli/packages/
WP-CLI cache dir: /home/user/.wp-cli/cache
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.12.0
- Ngôn ngữ chính
- Gherkin
- Star
- 61
- Fork
- 47
- Merge trung bình
- 8 phút
- Pull request đã merge (30 ngày)
- 1
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của wp-cli/search-replace-command
-
command:search-replace
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
wp-cli/search-replace-command#194 · 1 bình luận ·
-
command:search-replace contributor-day
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 25/100
wp-cli/search-replace-command#186 · 2 bình luận · 11 reaction ·
-
command:search-replace
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
wp-cli/search-replace-command#142 · 5 bình luận · 2 reaction ·
-
command:search-replace
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
wp-cli/search-replace-command#137 · 6 bình luận · 4 reaction ·
-
Progress bar Đang mởcommand:search-replace
wp-cli/search-replace-command#134 · 1 bình luận · 6 reaction · 1 người được giao ·
Tất cả issue của wp-cli/search-replace-command
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
qgis/QGIS-Documentation#11275 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
milvus-io/birdwatcher#545 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
-
area:tools bug good first issue help wanted priority:P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
TaewoooPark/Motifcode#14 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
newrelic-experimental/preflight#793 · 1 bình luận ·