Ticket #8580: 8580.diff

File 8580.diff, 1.9 KB (added by DD32, 3 years ago)
  • wp-admin/includes/file.php

     
    667667        $credentials['public_key'] = defined('FTP_PUBKEY') ? FTP_PUBKEY : (!empty($_POST['public_key']) ? $_POST['public_key'] : $credentials['public_key']); 
    668668        $credentials['private_key'] = defined('FTP_PRIKEY') ? FTP_PRIKEY : (!empty($_POST['private_key']) ? $_POST['private_key'] : $credentials['private_key']); 
    669669 
    670         if ( strpos($credentials['hostname'], ':') ) 
     670        //sanitize the hostname, Some people might pass in odd-data: 
     671        $credentials['hostname'] = preg_replace('|\w+://|', '', $credentials['hostname']); //Strip any schemes off 
     672 
     673        if ( strpos($credentials['hostname'], ':') && !defined('FTP_PORT') ) { 
    671674                list( $credentials['hostname'], $credentials['port'] ) = explode(':', $credentials['hostname'], 2); 
     675        } else { 
     676                if ( defined('FTP_PORT') ) 
     677                        $credentials['port'] = FTP_PORT; 
     678                else 
     679                        unset($credentials['port']); 
     680        } 
    672681 
    673682        if ( defined('FTP_SSH') || (isset($_POST['connection_type']) && 'ssh' == $_POST['connection_type']) ) 
    674683                $credentials['connection_type'] = 'ssh'; 
     
    679688 
    680689        if ( ! $error && !empty($credentials['password']) && !empty($credentials['username']) && !empty($credentials['hostname']) ) { 
    681690                $stored_credentials = $credentials; 
    682                 unset($stored_credentials['password'], $stored_credentials['private_key'], $stored_credentials['public_key']); 
     691                if ( !empty($stored_credentials['port']) ) //save port as part of hostname to simplify above code. 
     692                        $stored_credentials['hostname'] .= ':' . $stored_credentials['port']; 
     693 
     694                unset($stored_credentials['password'], $stored_credentials['port'], $stored_credentials['private_key'], $stored_credentials['public_key']); 
    683695                update_option('ftp_credentials', $stored_credentials); 
    684696                return $credentials; 
    685697        }