From 617c1844f99c8a5aeab4717fe45cf9a88e18efdb Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 02:52:06 +0000 Subject: [PATCH 1/2] Initial plan From 2dd0e73bd6d86a475ab5090a6e040be074d7254a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 02:54:33 +0000 Subject: [PATCH 2/2] Limit plugin to WP_CONTENT_DIR for security Co-authored-by: dd32 <767313+dd32@users.noreply.github.com> --- class.add-from-server.php | 53 +++++++++------------------------------ readme.md | 7 +++--- 2 files changed, 15 insertions(+), 45 deletions(-) diff --git a/class.add-from-server.php b/class.add-from-server.php index b63afe5..e0031f9 100644 --- a/class.add-from-server.php +++ b/class.add-from-server.php @@ -66,35 +66,9 @@ function menu_page() { } function get_root() { - // Lock users to either - // a) The 'ADD_FROM_SERVER' constant. - // b) Their home directory. - // c) The parent directory of the current install or wp-content directory. - - if ( defined( 'ADD_FROM_SERVER' ) ) { - $root = ADD_FROM_SERVER; - } elseif ( str_starts_with( __FILE__, '/home/' ) ) { - $root = implode( '/', array_slice( explode( '/', __FILE__ ), 0, 3 ) ); - } else { - if ( str_starts_with( WP_CONTENT_DIR, ABSPATH ) ) { - $root = dirname( ABSPATH ); - } else { - $root = dirname( WP_CONTENT_DIR ); - } - } - - // Precautions. The user is using the folder placeholder code. Abort for lower-privledge users. - if ( - str_contains( get_option( 'frmsvr_root', '%' ), '%' ) - && - ! defined( 'ADD_FROM_SERVER' ) - && - ! current_user_can( 'unfiltered_html' ) - ) { - $root = false; - } - - return $root; + // Lock users to WP_CONTENT_DIR for security. + // For multisite, wp_upload_dir() will return the individual site's upload directory. + return WP_CONTENT_DIR; } function path_selection_cookie() { @@ -139,6 +113,11 @@ function handle_imports() { continue; } + // Security: Ensure the file is within WP_CONTENT_DIR + if ( ! str_starts_with( wp_normalize_path( $filename ), wp_normalize_path( $root ) ) ) { + continue; + } + $id = $this->handle_import_file( $filename ); if ( is_wp_error( $id ) ) { @@ -317,13 +296,8 @@ function handle_import_file( $file ) { } protected function get_default_dir() { - $root = $this->get_root(); - - if ( str_starts_with( WP_CONTENT_DIR, $root ) ) { - return WP_CONTENT_DIR; - } - - return $root; + // Always start at WP_CONTENT_DIR + return WP_CONTENT_DIR; } // Create the content for the page @@ -601,13 +575,11 @@ function outdated_options_notice() { $old_root && str_contains( $old_root, '%' ) - && - ! defined( 'ADD_FROM_SERVER' ) ) { printf( '
%s
%s
' . esc_html( $old_root ) . ' as your "Root Directory", ' .
'this has been changed to ' . esc_html( $this->get_root() ) . '.wp-config.php file:define( "ADD_FROM_SERVER", "' . $old_root . '" );