Skip to content

Commit bde11b2

Browse files
REST API: Reject directory traversal in themes endpoint.
1 parent a507a18 commit bde11b2

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

‎src/wp-includes/rest-api/endpoints/class-wp-rest-themes-controller.php‎

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,26 @@ public function register_routes() {
7878
}
7979

8080
/**
81-
* Sanitize the stylesheet to decode endpoint.
81+
* Decodes the stylesheet and rejects directory traversal.
8282
*
8383
* @since 5.9.0
84+
* @since 7.2.0 Rejects directory traversal.
8485
*
8586
* @param string $stylesheet The stylesheet name.
86-
* @return string Sanitized stylesheet.
87+
* @return string|WP_Error Sanitized stylesheet, or an error for directory traversal.
8788
*/
8889
public function _sanitize_stylesheet_callback( $stylesheet ) {
89-
return urldecode( $stylesheet );
90+
$stylesheet = urldecode( $stylesheet );
91+
92+
// Normalize separators for the check without changing the returned identifier.
93+
if ( in_array( '..', explode( '/', wp_normalize_path( $stylesheet ) ), true ) ) {
94+
return new WP_Error(
95+
'rest_invalid_stylesheet',
96+
__( 'Invalid theme stylesheet.' )
97+
);
98+
}
99+
100+
return $stylesheet;
90101
}
91102

92103
/**

0 commit comments

Comments
 (0)