Make WordPress Core


Ignore:
Timestamp:
07/05/2018 02:44:35 PM (7 years ago)
Author:
johnbillion
Message:

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

File:
1 edited

Legend:

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

    r43285 r43393  
    17051705 * @since 4.4.0 Ensures upper-case drive letters on Windows systems.
    17061706 * @since 4.5.0 Allows for Windows network shares.
     1707 * @since 4.9.7 Allows for PHP file wrappers.
    17071708 *
    17081709 * @param string $path Path to normalize.
     
    17101711 */
    17111712function wp_normalize_path( $path ) {
     1713    $wrapper = '';
     1714    if ( wp_is_stream( $path ) ) {
     1715        list( $wrapper, $path ) = explode( '://', $path, 2 );
     1716        $wrapper .= '://';
     1717    }
     1718
     1719    // Standardise all paths to use /
    17121720    $path = str_replace( '\\', '/', $path );
     1721
     1722    // Replace multiple slashes down to a singular, allowing for network shares having two slashes.
    17131723    $path = preg_replace( '|(?<=.)/+|', '/', $path );
     1724
     1725    // Windows paths should uppercase the drive letter
    17141726    if ( ':' === substr( $path, 1, 1 ) ) {
    17151727        $path = ucfirst( $path );
    17161728    }
    1717     return $path;
     1729
     1730    return $wrapper . $path;
    17181731}
    17191732
     
    55055518
    55065519/**
     5520 * Deletes a file if its path is within the given directory.
     5521 *
     5522 * @since 4.9.7
     5523 *
     5524 * @param string $file      Absolute path to the file to delete.
     5525 * @param string $directory Absolute path to a directory.
     5526 * @return bool True on success, false on failure.
     5527 */
     5528function wp_delete_file_from_directory( $file, $directory ) {
     5529    $real_file = realpath( wp_normalize_path( $file ) );
     5530    $real_directory = realpath( wp_normalize_path( $directory ) );
     5531
     5532    if ( false === $real_file || false === $real_directory || strpos( wp_normalize_path( $real_file ), trailingslashit( wp_normalize_path( $real_directory ) ) ) !== 0 ) {
     5533        return false;
     5534    }
     5535
     5536    wp_delete_file( $file );
     5537
     5538    return true;
     5539}
     5540
     5541/**
    55075542 * Outputs a small JS snippet on preview tabs/windows to remove `window.name` on unload.
    55085543 *
Note: See TracChangeset for help on using the changeset viewer.