Skip to content

Commit 366c8e5

Browse files
committed
Filesystem: Normalize allowed_files so comparison is apples to apples.
In [58470] a change was made to normalize the filename in validate_file, however this leads to instances where the list of files that are allowed aren't normalized such as in the theme editor. By normalizing the array, the comparison is apples to apples. Reviewed by hellofromTonya. Merges 58570 to the 6.5 branch. Fixes #61488. Props jorbin, hellofromtonya, swissspidy, misulicus, script2see, Presskopp, audrasjb, peterwilsoncc, siliconforks, littler.chicken, paulkevan, git-svn-id: https://develop.svn.wordpress.org/branches/6.5@58808 602fd350-edb4-49c9-b593-d223f7449a82
1 parent c26d2a3 commit 366c8e5

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/wp-includes/functions.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6192,8 +6192,10 @@ function validate_file( $file, $allowed_files = array() ) {
61926192
return 0;
61936193
}
61946194

6195-
// Normalize path for Windows servers
6195+
// Normalize path for Windows servers.
61966196
$file = wp_normalize_path( $file );
6197+
// Normalize path for $allowed_files as well so it's an apples to apples comparison.
6198+
$allowed_files = array_map( 'wp_normalize_path', $allowed_files );
61976199

61986200
// `../` on its own is not allowed:
61996201
if ( '../' === $file ) {

tests/phpunit/tests/functions.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,6 +1793,7 @@ static function ( $mimes ) use ( $woff_mime_type ) {
17931793
* Test file path validation
17941794
*
17951795
* @ticket 42016
1796+
* @ticket 61488
17961797
* @dataProvider data_validate_file
17971798
*
17981799
* @param string $file File path.
@@ -1913,6 +1914,13 @@ public function data_validate_file() {
19131914
2,
19141915
),
19151916

1917+
// Windows Path with allowed file
1918+
array(
1919+
'Apache24\htdocs\wordpress/wp-content/themes/twentyten/style.css',
1920+
array( 'Apache24\htdocs\wordpress/wp-content/themes/twentyten/style.css' ),
1921+
0,
1922+
),
1923+
19161924
// Disallowed files:
19171925
array(
19181926
'foo.ext',

0 commit comments

Comments
 (0)