mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-06-28 22:30:04 +00:00
Privacy: Add cron to delete expired export files to protect privacy.
The primary means of protecting the files is the CSPRN appended to the filename, but there is no reason to keep the files after the data subject has downloaded them, so deleting them provides an additional layer of protection. Previously this was done from `wp_privacy_generate_personal_data_export_file()`, but that does not guarantee that it will be run regularly, and on smaller sites that could result in export files being exposed for much longer than necessary. `wp_privacy_delete_old_export_files()` was moved to a front end file, so that it can be called from `cron.php`. This introduces the `wp_privacy_export_expiration` filter, which allows plugins to customize how long the exports are kept before being deleted. `index.html` was added to the `$exclusions` parameter of `list_files()` to make sure that it isn't deleted. If it were, then poorly-configured servers would allow the directory to be traversed, exposing all of the exported files. Props iandunn, desrosj. See #43546. git-svn-id: https://develop.svn.wordpress.org/trunk@43046 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
@@ -6257,3 +6257,51 @@ function wp_privacy_anonymize_data( $type, $data = '' ) {
|
||||
function _wp_privacy_active_plugins_change() {
|
||||
update_option( '_wp_privacy_text_change_check', 'check' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedule a `WP_Cron` job to delete expired export files.
|
||||
*
|
||||
* @since 4.9.6
|
||||
*/
|
||||
function wp_schedule_delete_old_privacy_export_files() {
|
||||
if ( ! wp_next_scheduled( 'wp_privacy_delete_old_export_files' ) ) {
|
||||
wp_schedule_event( time(), 'hourly', 'wp_privacy_delete_old_export_files' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cleans up export files older than three days old.
|
||||
*
|
||||
* The export files are stored in `wp-content/uploads`, and are therefore publicly
|
||||
* accessible. A CSPRN is appended to the filename to mitigate the risk of an
|
||||
* unauthorized person downloading the file, but it is still possible. Deleting
|
||||
* the file after the data subject has had a chance to delete it adds an additional
|
||||
* layer of protection.
|
||||
*
|
||||
* @since 4.9.6
|
||||
*/
|
||||
function wp_privacy_delete_old_export_files() {
|
||||
$upload_dir = wp_upload_dir();
|
||||
$exports_dir = trailingslashit( $upload_dir['basedir'] . '/exports' );
|
||||
$export_files = list_files( $exports_dir, 100, array( 'index.html' ) );
|
||||
|
||||
/**
|
||||
* Filters the lifetime, in seconds, of a personal data export file.
|
||||
*
|
||||
* By default, the lifetime is 3 days. Once the file reaches that age, it will automatically
|
||||
* be deleted by a cron job.
|
||||
*
|
||||
* @since 4.9.6
|
||||
*
|
||||
* @param int $expiration The expiration age of the export, in seconds.
|
||||
*/
|
||||
$expiration = apply_filters( 'wp_privacy_export_expiration', 3 * DAY_IN_SECONDS );
|
||||
|
||||
foreach ( (array) $export_files as $export_file ) {
|
||||
$file_age_in_seconds = time() - filemtime( $export_file );
|
||||
|
||||
if ( $expiration < $file_age_in_seconds ) {
|
||||
unlink( $export_file );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user