Skip to content

Commit

Permalink
Privacy: Ensure that exported user data reports can't be found with d…
Browse files Browse the repository at this point in the history
…irectory listings.

By moving from `.html` to `.php` files, we can prevent directory listings, and ensure that WordPress can load.

Fixes #52299.

Props lucasbustamante, xkon, freewebmentor, SergeyBiryukov, whyisjake. 


git-svn-id: https://develop.svn.wordpress.org/trunk@50037 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
whyisjake committed Jan 27, 2021
1 parent 448dd9d commit a76f895
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/wp-admin/includes/privacy-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,13 @@ function wp_privacy_generate_personal_data_export_file( $request_id ) {
}

// Protect export folder from browsing.
$index_pathname = $exports_dir . 'index.html';
$index_pathname = $exports_dir . 'index.php';
if ( ! file_exists( $index_pathname ) ) {
$file = fopen( $index_pathname, 'w' );
if ( false === $file ) {
wp_send_json_error( __( 'Unable to protect personal data export folder from browsing.' ) );
}
fwrite( $file, '<!-- Silence is golden. -->' );
fwrite( $file, '<?php // Silence is golden.' );
fclose( $file );
}

Expand Down
2 changes: 1 addition & 1 deletion src/wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -7398,7 +7398,7 @@ function wp_privacy_delete_old_export_files() {
}

require_once ABSPATH . 'wp-admin/includes/file.php';
$export_files = list_files( $exports_dir, 100, array( 'index.html' ) );
$export_files = list_files( $exports_dir, 100, array( 'index.php' ) );

/**
* Filters the lifetime, in seconds, of a personal data export file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
wp_mkdir_p( $exports_dir );
}

self::$index_path = $exports_dir . 'index.html';
self::$index_path = $exports_dir . 'index.php';
self::$expired_export_file = $exports_dir . 'wp-personal-data-file-0123456789abcdef.zip';
self::$active_export_file = $exports_dir . 'wp-personal-data-file-fedcba9876543210.zip';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,15 @@ public function test_detect_cannot_create_folder() {
}

/**
* Test that an index.html file can be added to the export directory.
* Test that an index.php file can be added to the export directory.
*
* @ticket 44233
*/
public function test_creates_index_in_export_folder() {
$this->expectOutputString( '' );
wp_privacy_generate_personal_data_export_file( self::$export_request_id );

$this->assertTrue( file_exists( self::$exports_dir . 'index.html' ) );
$this->assertTrue( file_exists( self::$exports_dir . 'index.php' ) );
}

/**
Expand Down

0 comments on commit a76f895

Please sign in to comment.