Skip to content

Commit 0366f61

Browse files
Copilotswissspidy
andcommitted
Fix symlink validation with proper path normalization
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 050a066 commit 0366f61

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/Core_Command.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,9 +1737,14 @@ private function remove_old_files_from_list( $files ) {
17371737
// For symlinks, validate the symlink itself is within ABSPATH (not where it points)
17381738
// For other files, validate the real path is within ABSPATH
17391739
if ( is_link( $file_path ) ) {
1740-
// Check symlink path directly without following it
1741-
// Ensure the file path starts with ABSPATH
1742-
if ( 0 !== strpos( $file_path, ABSPATH ) ) {
1740+
// Normalize the path to handle any .. sequences
1741+
$normalized_path = realpath( dirname( $file_path ) );
1742+
if ( false === $normalized_path ) {
1743+
WP_CLI::debug( "Skipping symbolic link with invalid parent directory: {$file}", 'core' );
1744+
continue;
1745+
}
1746+
// Ensure the normalized parent directory is within ABSPATH
1747+
if ( 0 !== strpos( Utils\trailingslashit( $normalized_path ), $abspath_realpath_trailing ) && $normalized_path !== rtrim( $abspath_realpath_trailing, '/' ) ) {
17431748
WP_CLI::debug( "Skipping symbolic link outside of ABSPATH: {$file}", 'core' );
17441749
continue;
17451750
}

0 commit comments

Comments
 (0)