Rewrite Rules: Only treat a leading www. as optional in url_to_postid() - #13019
Rewrite Rules: Only treat a leading www. as optional in url_to_postid()#13019youknowriad wants to merge 1 commit into
www. as optional in url_to_postid()#13019Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
…tid()`. `url_to_postid()` compares the URL's host to the site's host after removing `www.` from both. The removal is unanchored, so it also strips a `www.` that appears in the middle of a host name: `exwww.ample.com` and `example.cwww.om` both reduce to `example.com`. A URL on either domain therefore resolves to a post ID on a site hosted at `example.com`, and both are ordinary registrations. Anchor the removal to the start of the host, matching the idiom already used in `ms-functions.php` and `ms-blogs.php`. See #65016. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
c43aacf to
55288be
Compare
| * @param string $path Path relative to the home URL. Blank string if no path is specified. | ||
| * @param string|null $orig_scheme Scheme to give the home URL context. | ||
| * @param int|null $_blog_id Site ID, or null for the current site. | ||
| * @param int|null $blog_id Site ID, or null for the current site. |
There was a problem hiding this comment.
Is this an unintentional change? The parameter name is $_blog_id and doesn't need to change.
johnbillion
left a comment
There was a problem hiding this comment.
The switch to a regex looks good, thanks. The unintentional change to the $_blog_id parameter in the test isn't needed though.
url_to_postid()compares the URL's host to the site's host after removingwww.from both. The removal is unanchored, so it stripswww.from anywhere in the host, not just the prefix. On a site atexample.com:Both are ordinary registrations (
ample.com;cwww.omunder Oman's TLD). Since a post ID from this function is widely treated as proof that a URL is internal, a lookalike domain currently passes that test.Trac ticket: https://core.trac.wordpress.org/ticket/65016
This surfaced while reviewing #12870 on that ticket, which uses
url_to_postid()for a trust decision. Worth fixing on its own regardless of what happens to that PR.Changes
Anchor the removal so only a leading
www.is optional, matching the idiom already used inms-functions.phpandms-blogs.php:Testing
A data-provided case in
tests/phpunit/tests/rewrite.phpcovers the site host, thewww.prefix, both collisions, an unrelated host, and the site host as an attacker subdomain. Reverting only the source change fails exactly the two collision cases.npm run test:php -- --filter Tests_Rewrite # 92 tests, 279 assertionsUse of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5
Used for: Research, implementation, and tests; reviewed and edited by me.