Query: Add unit test for redirect_guess_404_permalink() post_type array leak - #12941
Query: Add unit test for redirect_guess_404_permalink() post_type array leak#12941irozum wants to merge 1 commit into
Conversation
|
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. |
What this adds: a new data-provider case for
Tests_Canonical::test_redirect_guess_404_permalink_post_types()intests/phpunit/tests/canonical.php, coveringredirect_guess_404_permalink()insrc/wp-includes/canonical.php.Function under test:
redirect_guess_404_permalink(), specifically the branch that builds the SQLpost_type IN (...)clause whenpost_typeis queried as an array (src/wp-includes/canonical.php, around line 985-989).Case covered and why: a mix of one publicly viewable post type (
page) and one non-viewable post type (wp_tests_private) in thepost_typearray, where a post of the non-viewable type matches the requestednameprefix. Before the fix landed in trunk (efa21b21dd, ticket #44964), this branch built the SQLIN (...)clause from the raw, unfilteredget_query_var( 'post_type' )array instead of the$post_typeslist already intersected against publicly viewable types two lines above — so a private/non-viewable post could be found and its permalink leaked as the guessed 404 redirect target, even though it should never have been considered. The existing data set already covered a single private post type (which short-circuits via theempty( $post_types )guard before ever reaching the vulnerable SQL line) and a single public type, but nothing exercised the mixed-array path where the bug actually lived. I verified this test fails against the pre-fix code (reverting the one-line fix locally reproduces the leak and turns this exact case red) and passes against current trunk.This is test-only — it adds no production behaviour.
git diff trunkfor this branch touches onlytests/phpunit/tests/canonical.php.Trac ticket: https://core.trac.wordpress.org/ticket/44964
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5
Used for: Surveying Trac for a coverage candidate, verifying the fix had landed in trunk and no test existed for it, drafting the test case and data-provider entry, and running the red/green verification loop (breaking the fix locally to confirm the new test fails, then reverting). I reviewed the diff, ticket, and test output before submitting.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.