WordPress.org

Make WordPress Core

Changeset 43180


Ignore:
Timestamp:
05/08/2018 12:51:59 AM (7 weeks ago)
Author:
iandunn
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.
Fixes #43905.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/file.php

    r43154 r43180  
    21282128    fclose( $file );
    21292129
    2130     // Now, generate the ZIP.
     2130    /*
     2131     * Now, generate the ZIP.
     2132     *
     2133     * If an archive has already been generated, then remove it and reuse the
     2134     * filename, to avoid breaking any URLs that may have been previously sent
     2135     * via email.
     2136     */
    21312137    $error            = false;
    2132     $archive_filename = $file_basename . '.zip';
    2133     $archive_pathname = $exports_dir . $archive_filename;
    2134     $archive_url      = $exports_url . $archive_filename;
     2138    $archive_url      = get_post_meta( $request_id, '_export_file_url', true );
     2139    $archive_pathname = get_post_meta( $request_id, '_export_file_path', true );
     2140
     2141    if ( empty( $archive_pathname ) || empty( $archive_url ) ) {
     2142        $archive_filename = $file_basename . '.zip';
     2143        $archive_pathname = $exports_dir . $archive_filename;
     2144        $archive_url      = $exports_url . $archive_filename;
     2145
     2146        update_post_meta( $request_id, '_export_file_url', $archive_url );
     2147        update_post_meta( $request_id, '_export_file_path', $archive_pathname );
     2148    }
     2149
     2150    if ( ! empty( $archive_pathname ) && file_exists( $archive_pathname ) ) {
     2151        wp_delete_file( $archive_pathname );
     2152    }
    21352153
    21362154    $zip = new ZipArchive;
     
    21642182        wp_send_json_error( $error );
    21652183    }
    2166 
    2167     // Save the export file in the request.
    2168     update_post_meta( $request_id, '_export_file_url', $archive_url );
    2169     update_post_meta( $request_id, '_export_file_path', $archive_pathname );
    21702184}
    21712185
     
    23432357    update_post_meta( $request_id, '_export_data_grouped', $groups );
    23442358
    2345     // And now, generate the export file, cleaning up any previous file
    2346     $export_path = get_post_meta( $request_id, '_export_file_path', true );
    2347     if ( ! empty( $export_path ) ) {
    2348         delete_post_meta( $request_id, '_export_file_path' );
    2349         @unlink( $export_path );
    2350     }
    2351     delete_post_meta( $request_id, '_export_file_url' );
    2352 
    23532359    // Generate the export file from the collected, grouped personal data.
    23542360    do_action( 'wp_privacy_personal_data_export_file', $request_id );
Note: See TracChangeset for help on using the changeset viewer.