From c15003ed823530f573d8dd423d0c566096e61923 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Mon, 17 Nov 2008 19:01:07 +0000 Subject: [PATCH] * Add a .htaccess to deleted images directory for additional protection against exposure of deleted files with known SHA-1 hashes on default installations. Applying Tim's fixes --- RELEASE-NOTES | 4 +++- includes/filerepo/FSRepo.php | 21 ++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 5483cab585..502e4a61a5 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -349,7 +349,9 @@ The following extensions are migrated into MediaWiki 1.14: * Less verbose errors from profileinfo.php when not configured * Blacklist redirects via Special:Filepath, hard to use. * Improved input validation on Special:Import form - +* Add a .htaccess to deleted images directory for additional protection + against exposure of deleted files with known SHA-1 hashes on default + installations. === API changes in 1.14 === diff --git a/includes/filerepo/FSRepo.php b/includes/filerepo/FSRepo.php index 17f3f16447..d561e61b88 100644 --- a/includes/filerepo/FSRepo.php +++ b/includes/filerepo/FSRepo.php @@ -149,10 +149,8 @@ class FSRepo extends FileRepo { if ( !wfMkdirParents( $dstDir ) ) { return $this->newFatal( 'directorycreateerror', $dstDir ); } - // In the deleted zone, seed new directories with a blank - // index.html, to prevent crawling if ( $dstZone == 'deleted' ) { - file_put_contents( "$dstDir/index.html", '' ); + $this->initDeletedDir( $dstDir ); } } @@ -214,6 +212,20 @@ class FSRepo extends FileRepo { return $status; } + /** + * Take all available measures to prevent web accessibility of new deleted + * directories, in case the user has not configured offline storage + */ + protected function initDeletedDir( $dir ) { + // Add a .htaccess file to the root of the deleted zone + $root = $this->getZonePath( 'deleted' ); + if ( !file_exists( "$root/.htaccess" ) ) { + file_put_contents( "$root/.htaccess", "Deny from all\n" ); + } + // Seed new directories with a blank index.html, to prevent crawling + file_put_contents( "$dir/index.html", '' ); + } + /** * Pick a random name in the temp zone and store a file to it. * @param string $originalName The base name of the file as specified @@ -393,8 +405,7 @@ class FSRepo extends FileRepo { $status->fatal( 'directorycreateerror', $archiveDir ); continue; } - // Seed new directories with a blank index.html, to prevent crawling - file_put_contents( "$archiveDir/index.html", '' ); + $this->initDeletedDir( $archiveDir ); } // Check if the archive directory is writable // This doesn't appear to work on NTFS -- 2.20.1