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 . '" );