Make WordPress Core

Opened 3 weeks ago

Last modified 3 weeks ago

#66167 new defect (bug)

REST API Themes Endpoint Allows Directory Traversal to Read style.css Outside the Themes Directory

Reported by: truonghuuphuc Owned by:
Priority: normal Milestone: Awaiting Review
Component: REST API Version:
Severity: normal Keywords: has-patch has-unit-tests
Cc: Focuses:

Description

Detailed description at the attached link:
​https://drive.google.com/file/d/1Zf6yDNCW6pjN4iW6Uxtt6I2Iia4EuUUz/view
Thank you, everyone, for taking the time to read the report.

Change History (3)

#1 @sainathpoojary
3 weeks ago

Welcome to Trac, @truonghuuphuc, and thanks for reporting this!

I was able to reproduce this locally.

Using the stylesheet query parameter, I could point the themes endpoint at a style.css file outside the themes directory. The request returned the theme header values from that file, such as its name and description.

One small clarification from my testing: I did not see the complete contents of the file returned. Only the values WordPress normally reads from a theme’s stylesheet header were included in the REST response.

It looks like the query parameter can override the stylesheet value captured from the URL, and that value is URL decoded before it reaches wp_get_theme(). A validation check on the final stylesheet value would likely address this, including the query parameter case.

https://hgeisrmuxslkxkhhewgj.supabase.co/storage/v1/object/public/uploads/Screenshot%202026-09-24%20at%207.19.59%20PM.png

https://hgeisrmuxslkxkhhewgj.supabase.co/storage/v1/object/public/uploads/Screenshot%202026-09-24%20at%207.28.11%20PM.png

#2 @truonghuuphuc
3 weeks ago

Thanks @sainathpoojary

This ticket was mentioned in ​PR #13717 on ​WordPress/wordpress-develop by ​@sainathpoojary.


3 weeks ago
#3

  • Keywords has-patch has-unit-tests added

Description

When requesting a single theme through the themes REST endpoint (/wp/v2/themes/<stylesheet>), providing a stylesheet query parameter or encoded route path with directory traversal sequences (..) could allow wp_get_theme() to read theme headers from a style.css file outside the wp-content/themes directory.

This PR updates WP_REST_Themes_Controller::_sanitize_stylesheet_callback() to normalize path separators with wp_normalize_path() and check for .. segments after URL decoding. If directory traversal is detected, a WP_Error (rest_invalid_stylesheet) is returned, causing the REST API parameter validation to reject the request with HTTP 400 (rest_invalid_param) before theme resolution or permission checks run.

Unit tests have been added to verify that traversal variations are rejected while legitimate stylesheet identifiers containing dots or special characters continue to work.

Trac ticket: https://core.trac.wordpress.org/ticket/66167

Use of AI Tools

AI assistance: Yes
Tool(s): Github Copilot
Model(s): Claude Sonnet 4.6
Used for: Initial code suggestions and tests, final implementation and tests were verified and edited by me.

Note: See TracTickets for help on using tickets.