mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-09-22 00:40:20 +00:00
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.
git-svn-id: https://develop.svn.wordpress.org/trunk@55425 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -56,6 +56,54 @@ class WP_Automatic_Updater {
|
||||
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.
|
||||
*
|
||||
@@ -102,7 +150,11 @@ class WP_Automatic_Updater {
|
||||
// Search all directories we've found for evidence of version control.
|
||||
foreach ( $vcs_dirs as $vcs_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 ) {
|
||||
break 2;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user