Skip to content

Query: Add unit test for redirect_guess_404_permalink() post_type array leak - #12941

Open
irozum wants to merge 1 commit into
WordPress:trunkfrom
irozum:task/44964-redirect-guess-404-post-type-tests
Open

Query: Add unit test for redirect_guess_404_permalink() post_type array leak#12941
irozum wants to merge 1 commit into
WordPress:trunkfrom
irozum:task/44964-redirect-guess-404-post-type-tests

Conversation

@irozum

@irozum irozum commented Aug 7, 2026

Copy link
Copy Markdown

What this adds: a new data-provider case for Tests_Canonical::test_redirect_guess_404_permalink_post_types() in tests/phpunit/tests/canonical.php, covering redirect_guess_404_permalink() in src/wp-includes/canonical.php.

Function under test: redirect_guess_404_permalink(), specifically the branch that builds the SQL post_type IN (...) clause when post_type is 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 the post_type array, where a post of the non-viewable type matches the requested name prefix. Before the fix landed in trunk (efa21b21dd, ticket #44964), this branch built the SQL IN (...) clause from the raw, unfiltered get_query_var( 'post_type' ) array instead of the $post_types list 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 the empty( $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 trunk for this branch touches only tests/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.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

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 props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props irozum.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

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