Upgrade/Install: Introduce `WP_Automatic_Updater::is_allowed_dir()` method.
As part of determining whether to perform automatic updates, WordPress checks if it is running within a version-controlled environment, recursively looking up the filesystem to the top of the drive, looking for a Subversion, Git, Mercurial, or Bazaar directory, erring on the side of detecting a VCS checkout somewhere. This commit avoids a PHP warning if the `open_basedir` directive is in use and any of the directories checked in the process are not allowed: {{{ is_dir(): open_basedir restriction in effect. File(/.git) is not within the allowed path(s) }}} Follow-up to [25421], [25700], [25764], [25835], [25859]. Props costdev, markjaquith, meyegui, dd32, arnolp, robin-labadie, hellofromTonya, afragen, pbiron, SergeyBiryukov. Fixes #42619. Built from https://develop.svn.wordpress.org/trunk@55425 git-svn-id: http://core.svn.wordpress.org/trunk@54958 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
325a14a3ef
commit
04967a68b6
|
@ -56,6 +56,54 @@ class WP_Automatic_Updater {
|
||||||
return apply_filters( 'automatic_updater_disabled', $disabled );
|
return apply_filters( 'automatic_updater_disabled', $disabled );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether access to a given directory is allowed.
|
||||||
|
*
|
||||||
|
* This is used when detecting version control checkouts. Takes into account
|
||||||
|
* the PHP `open_basedir` restrictions, so that WordPress does not try to access
|
||||||
|
* directories it is not allowed to.
|
||||||
|
*
|
||||||
|
* @since 6.2.0
|
||||||
|
*
|
||||||
|
* @param string $dir The directory to check.
|
||||||
|
* @return bool True if access to the directory is allowed, false otherwise.
|
||||||
|
*/
|
||||||
|
public function is_allowed_dir( $dir ) {
|
||||||
|
if ( is_string( $dir ) ) {
|
||||||
|
$dir = trim( $dir );
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! is_string( $dir ) || '' === $dir ) {
|
||||||
|
_doing_it_wrong(
|
||||||
|
__METHOD__,
|
||||||
|
sprintf(
|
||||||
|
/* translators: %s: The "$dir" argument. */
|
||||||
|
__( 'The "%s" argument must be a non-empty string.' ),
|
||||||
|
'$dir'
|
||||||
|
),
|
||||||
|
'6.2.0'
|
||||||
|
);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$open_basedir = ini_get( 'open_basedir' );
|
||||||
|
|
||||||
|
if ( empty( $open_basedir ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
$open_basedir_list = explode( PATH_SEPARATOR, $open_basedir );
|
||||||
|
|
||||||
|
foreach ( $open_basedir_list as $basedir ) {
|
||||||
|
if ( '' !== trim( $basedir ) && str_starts_with( $dir, $basedir ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks for version control checkouts.
|
* Checks for version control checkouts.
|
||||||
*
|
*
|
||||||
|
@ -102,7 +150,11 @@ class WP_Automatic_Updater {
|
||||||
// Search all directories we've found for evidence of version control.
|
// Search all directories we've found for evidence of version control.
|
||||||
foreach ( $vcs_dirs as $vcs_dir ) {
|
foreach ( $vcs_dirs as $vcs_dir ) {
|
||||||
foreach ( $check_dirs as $check_dir ) {
|
foreach ( $check_dirs as $check_dir ) {
|
||||||
$checkout = @is_dir( rtrim( $check_dir, '\\/' ) . "/$vcs_dir" );
|
if ( ! $this->is_allowed_dir( $check_dir ) ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$checkout = is_dir( rtrim( $check_dir, '\\/' ) . "/$vcs_dir" );
|
||||||
if ( $checkout ) {
|
if ( $checkout ) {
|
||||||
break 2;
|
break 2;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '6.2-beta3-55424';
|
$wp_version = '6.2-beta3-55425';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
|
Loading…
Reference in New Issue