fix(clone): Prevents overwriting wp-config.php when cloning a remote site with a custom public directory#462
Merged
mrrobot47 merged 3 commits intoEasyEngine:developfrom Dec 17, 2025
Conversation
…site with a custom public directory This change fixes a bug in the copy_site_files() function where the wp-config.php file from the remote site was copied and overwritten the local wp-config.php file when the remote site had a custom public directory.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in the copy_site_files() function where wp-config.php from a remote site with a custom public directory was incorrectly copied and overwrote the local wp-config.php file during cloning operations.
Key Changes
- Adds exclusion logic for
wp-config.phpin custom public directories and their parent directories - Updates uploads path handling to use source-specific and destination-specific path variables
- Fixes exclusion pattern for uploads to use the correct source-relative path
Comments suppressed due to low confidence (1)
src/clone/clone-utils.php:166
- The construction of the
rsynccommand here interpolates values derived fromsite_container_fs_path(e.g.destination_public_path,source_public_path/source_uploads_path) directly into the$excludestring, which is then passed as part of a full shell command toEE::execviarsync_command. Because these values ultimately come fromee site infoJSON on the remote host and are not re-escaped (e.g. withescapeshellarg), a compromised or malicious remote site can setsite_container_fs_path(orsite_fs_path) to include shell metacharacters and achieve command injection on the local host when cloning/syncing (e.g. via a crafted path that injects; rm -rf /). To fix this, ensure all path components used in$exclude,$source_dir, and$destination_dirare strictly validated on read and passed throughescapeshellarg, or refactorrsync_command/EE::execto avoid shell parsing by passing arguments as an array to the underlying process launcher.
$source_public_path = str_replace( '/var/www/htdocs', '', $source->site_details['site_container_fs_path'] );
$destination_public_path = str_replace( '/var/www/htdocs', '', $destination->site_details['site_container_fs_path'] );
$exclude = '--exclude \'/wp-config.php\'';
if ( ! empty( $destination_public_path ) ) {
$exclude .= ' --exclude \'' . $destination_public_path . '/wp-config.php\'';
$parent_dir = dirname( $destination_public_path );
if ( $parent_dir !== '.' && $parent_dir !== '/' ) {
$exclude .= ' --exclude \'' . $parent_dir . '/wp-config.php\'';
}
}
$source_uploads_path = $source_public_path . '/wp-content/uploads';
$destination_uploads_path = $destination_public_path . '/wp-content/uploads';
$uploads_path_share = '/shared/wp-content/uploads';
$source_dir = remove_trailing_slash( $source->get_site_root_dir() );
$destination_dir = remove_trailing_slash( $destination->get_site_root_dir() );
if ( $sync_type['uploads'] && ! $sync_type['files'] ) {
$source_dir .= $source_uploads_path;
$destination_dir .= $destination_uploads_path;
}
if ( $sync_type['files'] && ! $sync_type['uploads'] ) {
$exclude .= ' --exclude \'' . $source_uploads_path . '\'';
$exclude .= ' --exclude \'' . $uploads_path_share . '\'';
}
$rsync_command = rsync_command( trailingslashit( $source_dir ), trailingslashit( $destination_dir ), [ $exclude ] );
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
mrrobot47
approved these changes
Dec 17, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This change fixes a bug in the copy_site_files() function where the wp-config.php file from the remote site was copied and overwritten the local wp-config.php file when the remote site had a custom public directory.
Evidence:
sudo ee site clone root@192.168.100.20:custom-public.local .Problem.
The code only had
--exclude '/wp-config.php'(in the root)When the remote site had a custom
source_public_path(e.g.,/current/web),wp-config.phpwas located in/current/wp-config.phpSince the exclusion only covered the root (
/wp-config.php), rsync copiedwp-config.phpfrom the remote site, overwriting the local database settings and preventing synchronization from occurring correctly.Solution.
With the code update, it's possible to clone WordPress sites from remote servers with a customized public directory.
sudo ee site clone root@192.168.100.20:custom-public.local .Fixes #463