From 2524ba3aec743601ba78ba6fe7fcaeacce633701 Mon Sep 17 00:00:00 2001 From: whyisjake Date: Mon, 14 Oct 2019 15:31:04 +0000 Subject: [PATCH] Filesystem API: Prevent directory travelersals when creating new folders. Reject file paths that contain sub-directory paths. Props iandunn, xknown, sstoqnov, whyisjake. Built from https://develop.svn.wordpress.org/trunk@46476 git-svn-id: http://core.svn.wordpress.org/trunk@46274 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 5 +++++ wp-includes/version.php | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 979536f751..7db3bbafd9 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -1923,6 +1923,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 ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 8805c87052..e53607b467 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.3-beta3-46475'; +$wp_version = '5.3-beta3-46476'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.