Make WordPress Core


Ignore:
Timestamp:
07/05/2018 02:50:26 PM (6 years ago)
Author:
johnbillion
Message:

Media: Limit thumbnail file deletions to the same directory as the original file.

Merges [43393] into the 4.7 branch.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/4.7/src/wp-includes/functions.php

    r42275 r43395  
    17001700 * @since 4.4.0 Ensures upper-case drive letters on Windows systems.
    17011701 * @since 4.5.0 Allows for Windows network shares.
     1702 * @since 4.9.7 Allows for PHP file wrappers.
    17021703 *
    17031704 * @param string $path Path to normalize.
     
    17051706 */
    17061707function wp_normalize_path( $path ) {
     1708    $wrapper = '';
     1709    if ( wp_is_stream( $path ) ) {
     1710        list( $wrapper, $path ) = explode( '://', $path, 2 );
     1711        $wrapper .= '://';
     1712    }
     1713
     1714    // Standardise all paths to use /
    17071715    $path = str_replace( '\\', '/', $path );
     1716
     1717    // Replace multiple slashes down to a singular, allowing for network shares having two slashes.
    17081718    $path = preg_replace( '|(?<=.)/+|', '/', $path );
     1719
     1720    // Windows paths should uppercase the drive letter
    17091721    if ( ':' === substr( $path, 1, 1 ) ) {
    17101722        $path = ucfirst( $path );
    17111723    }
    1712     return $path;
     1724
     1725    return $wrapper . $path;
    17131726}
    17141727
     
    54475460
    54485461/**
     5462 * Deletes a file if its path is within the given directory.
     5463 *
     5464 * @since 4.9.7
     5465 *
     5466 * @param string $file      Absolute path to the file to delete.
     5467 * @param string $directory Absolute path to a directory.
     5468 * @return bool True on success, false on failure.
     5469 */
     5470function wp_delete_file_from_directory( $file, $directory ) {
     5471    $real_file = realpath( wp_normalize_path( $file ) );
     5472    $real_directory = realpath( wp_normalize_path( $directory ) );
     5473
     5474    if ( false === $real_file || false === $real_directory || strpos( wp_normalize_path( $real_file ), trailingslashit( wp_normalize_path( $real_directory ) ) ) !== 0 ) {
     5475        return false;
     5476    }
     5477
     5478    wp_delete_file( $file );
     5479
     5480    return true;
     5481}
     5482
     5483/**
    54495484 * Outputs a small JS snippet on preview tabs/windows to remove `window.name` on unload.
    54505485 *
Note: See TracChangeset for help on using the changeset viewer.