Make WordPress Core

Changeset 43186


Ignore:
Timestamp:
05/09/2018 02:29:25 PM (6 years ago)
Author:
SergeyBiryukov
Message:

Privacy: Reuse existing archive filenames to maintain URLs.

Whenever an admin initiates a download or email of a personal data export, a fresh copy of the file is generated. Previously, a new filename was used each time, which could lead to situations where a URL that was emailed to a data subject is broken.

That can be avoided by reusing the same filename when building fresh archives.

Props desrosj, tz-media, allendav.
Merges [43180] to the 4.9 branch.
Fixes #43905.

Location:
branches/4.9
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

  • branches/4.9/src/wp-admin/includes/file.php

    r43157 r43186  
    19911991    fclose( $file );
    19921992
    1993     // Now, generate the ZIP.
     1993    /*
     1994     * Now, generate the ZIP.
     1995     *
     1996     * If an archive has already been generated, then remove it and reuse the
     1997     * filename, to avoid breaking any URLs that may have been previously sent
     1998     * via email.
     1999     */
    19942000    $error            = false;
    1995     $archive_filename = $file_basename . '.zip';
    1996     $archive_pathname = $exports_dir . $archive_filename;
    1997     $archive_url      = $exports_url . $archive_filename;
     2001    $archive_url      = get_post_meta( $request_id, '_export_file_url', true );
     2002    $archive_pathname = get_post_meta( $request_id, '_export_file_path', true );
     2003
     2004    if ( empty( $archive_pathname ) || empty( $archive_url ) ) {
     2005        $archive_filename = $file_basename . '.zip';
     2006        $archive_pathname = $exports_dir . $archive_filename;
     2007        $archive_url      = $exports_url . $archive_filename;
     2008
     2009        update_post_meta( $request_id, '_export_file_url', $archive_url );
     2010        update_post_meta( $request_id, '_export_file_path', $archive_pathname );
     2011    }
     2012
     2013    if ( ! empty( $archive_pathname ) && file_exists( $archive_pathname ) ) {
     2014        wp_delete_file( $archive_pathname );
     2015    }
    19982016
    19992017    $zip = new ZipArchive;
     
    20272045        wp_send_json_error( $error );
    20282046    }
    2029 
    2030     // Save the export file in the request.
    2031     update_post_meta( $request_id, '_export_file_url', $archive_url );
    2032     update_post_meta( $request_id, '_export_file_path', $archive_pathname );
    20332047}
    20342048
     
    22062220    update_post_meta( $request_id, '_export_data_grouped', $groups );
    22072221
    2208     // And now, generate the export file, cleaning up any previous file
    2209     $export_path = get_post_meta( $request_id, '_export_file_path', true );
    2210     if ( ! empty( $export_path ) ) {
    2211         delete_post_meta( $request_id, '_export_file_path' );
    2212         @unlink( $export_path );
    2213     }
    2214     delete_post_meta( $request_id, '_export_file_url' );
    2215 
    22162222    // Generate the export file from the collected, grouped personal data.
    22172223    do_action( 'wp_privacy_personal_data_export_file', $request_id );
Note: See TracChangeset for help on using the changeset viewer.