Filesystem API: Prevent directory travelersals when creating new folders.

Reject file paths that contain sub-directory paths.

Backports [46476] to the 5.2 branch.

Props iandunn, xknown, sstoqnov, whyisjake.

Built from https://develop.svn.wordpress.org/branches/5.2@46482


git-svn-id: http://core.svn.wordpress.org/branches/5.2@46280 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
whyisjake 2019-10-14 16:13:53 +00:00
parent c4a25f9386
commit e5e18e9b15
2 changed files with 6 additions and 1 deletions

View File

@ -1787,6 +1787,11 @@ function wp_mkdir_p( $target ) {
return @is_dir( $target );
}
// Do not allow path traversals.
if ( false !== strpos( $target, '../' ) || false !== strpos( $target, '..' . DIRECTORY_SEPARATOR ) ) {
return false;
}
// We need to find the permissions of the parent folder that exists and inherit that.
$target_parent = dirname( $target );
while ( '.' != $target_parent && ! is_dir( $target_parent ) && dirname( $target_parent ) !== $target_parent ) {

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.2.4-alpha-46481';
$wp_version = '5.2.4-alpha-46482';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.