Make WordPress Core

Opened 13 months ago

Last modified 8 days ago

#62777 new defect (bug)

Force a 404 when no sitemap provider is found

Reported by: romainmrhenry's profile romainmrhenry Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: General Keywords: has-patch has-unit-tests has-screenshots
Focuses: Cc:

Description

Currently WordPress does not force a 404 when no sitemap provider is found and instead continues down the regular template hierarchy.

This can be tested with:

  • /wp-sitemap-foo-1.xml
  • ?sitemap=foo

Where foo is not a registered provider.

I would expect a 404 when the url matches the sitemap url patterns but no provider is gound.

Attachments (1)

Screenshot 2025-01-08 at 11.54.41.png (125.7 KB) - added by thabotswana 13 months ago.

Download all attachments as: .zip

Change History (11)

This ticket was mentioned in PR #8085 on WordPress/wordpress-develop by romainmenke.


13 months ago
#1

  • Keywords has-patch has-unit-tests added

#2 @samiamnot
13 months ago

See the related #61293.

#3 @thabotswana
13 months ago

Reproduction Report

I'm currently unable to reproduce the problem.

Environment

  • OS: macOS 15.2
  • Web Server: PHP.wasm
  • PHP: 7.4.31-dev
  • WordPress: 6.8-alpha-20250103.134745
  • Browser: Firefox 133.0.3
  • Theme: Twenty Twenty-Five
  • Active Plugins: None activated

Actual Results

  • ❌ Error condition does not occur (unexpected).
Last edited 13 months ago by thabotswana (previous) (diff)

#4 follow-up: @romainmrhenry
13 months ago

@thabotswana That is unexpected :)

Did you see this test? https://github.com/WordPress/wordpress-develop/pull/8085/files#diff-6a57f412101368a64c09359f72a1007cc7b027db986f454a4666648b801b9f14

It fails when removing the patch.

How are permalinks configured during your manual test?

#5 in reply to: ↑ 4 @thabotswana
13 months ago

Replying to romainmrhenry:

@thabotswana That is unexpected :)

Did you see this test? https://github.com/WordPress/wordpress-develop/pull/8085/files#diff-6a57f412101368a64c09359f72a1007cc7b027db986f454a4666648b801b9f14

It fails when removing the patch.

How are permalinks configured during your manual test?

The permalink structure is set to Day and name

https://playground.wordpress.net/scope:calm-chic-park/2025/01/08/sample-post/

Maybe the difference is I'm using a WordPress Playground instance? 🤷🏾‍♂️

This ticket was mentioned in Slack in #core-test by oglekler. View the logs.


13 months ago

#7 follow-up: @tremidkhar
13 months ago

  • Keywords needs-testing added

Reproduction Report

Description

During the Test Team triage, we observed that the current behavior involves navigating through the template hierarchy when no sitemap provider matches the expected behavior, forcing a 404 error prematurely could lead to unexpected results. Further investigation may be required to fully understand the issue and determine if any adjustments are needed.

Environment

  • WordPress: 6.7.1
  • PHP: 8.3.6
  • Server: Apache/2.4.62 (Win64) OpenSSL/3.1.6 PHP/8.3.6 mod_fcgid/2.3.10-dev
  • Database: mysqli (Server: 11.1.2-MariaDB / Client: mysqlnd 8.3.6)
  • Browser: Chrome 131.0.0.0
  • OS: Windows 10/11

Actual Results

  1. A 404 page is displayed when no sitemap provider is found.

#8 in reply to: ↑ 7 @romainmrhenry
13 months ago

Replying to tremidkhar:

Reproduction Report

Description

During the Test Team triage, we observed that the current behavior involves navigating through the template hierarchy when no sitemap provider matches the expected behavior, forcing a 404 error prematurely could lead to unexpected results. Further investigation may be required to fully understand the issue and determine if any adjustments are needed.

Environment

  • WordPress: 6.7.1
  • PHP: 8.3.6
  • Server: Apache/2.4.62 (Win64) OpenSSL/3.1.6 PHP/8.3.6 mod_fcgid/2.3.10-dev
  • Database: mysqli (Server: 11.1.2-MariaDB / Client: mysqlnd 8.3.6)
  • Browser: Chrome 131.0.0.0
  • OS: Windows 10/11

Actual Results

  1. A 404 page is displayed when no sitemap provider is found.

The same could be said for the other conditions where a 404 is already being forced in the render_sitemaps function.
Only in this very specific scenario is the template hierarchy used.
This behavior has no test coverage, no explaining comment and no discussion as far as I can tell.

There also are better escape hatches to disable or manipulate the rendering of sitemaps.

#9 @wildworks
8 weeks ago

  • Version trunk deleted

I checked this ticket in preparation for the 6.9 dry run.

I would like to remove the version number, as this issue is not the first to occur, at least not in unreleased development versions.

#10 @ozgursar
8 days ago

  • Keywords has-screenshots added; needs-testing removed

Test Report

Description

This report validates whether the indicated patch works as expected.

Patch tested: https://github.com/WordPress/wordpress-develop/pull/8085

Environment

  • WordPress: 7.0-alpha-61215-src
  • PHP: 8.2.29
  • Server: nginx/1.29.4
  • Database: mysqli (Server: 8.4.7 / Client: mysqlnd 8.2.29)
  • Browser: Chrome 143.0.0.0
  • OS: macOS
  • Theme: Twenty Twenty-Five 1.4
  • MU Plugins: None activated
  • Plugins:
    • Classic Editor 1.6.7
    • Test Reports 1.2.1

Steps to Reproduce

  1. Settings > Permalinks > Choose Post name and Save Changes
  2. Visit /wp-sitemap-foo-1.xml (E.g.: http://localhost:8889/wp-sitemap-foo-1.xml)
  3. 404 page is not displayed
  4. Repeat the same for Plain to test /?sitemap=foo

Actual Results

  1. ✅ Issue resolved with patch for /wp-sitemap-foo-1.xml
  2. http://localhost:8889/wp-sitemap-foo-1.xml displays 404 page (When permalink set to Post Name)
  3. http://localhost:8889/?sitemap=foo displays 404 page (When permalink set to Plain)

Additional Notes

  • I tested both URLs with Permalinks set to Plain and Post name.
  • I didn't test other Permalink scenarios.

Supplemental Artifacts

Before After
https://files.catbox.moe/zuwgns.png https://files.catbox.moe/if0475.png
Note: See TracTickets for help on using tickets.