diff --git a/.htaccess b/.htaccess index c0f14582b368..3642f88858d1 100644 --- a/.htaccess +++ b/.htaccess @@ -4,7 +4,12 @@ # Protect files and directories from prying eyes. - Order allow,deny + + Require all denied + + + Order allow,deny + # Don't show directory listings for URLs which map to a directory. diff --git a/core/lib/Drupal/Component/PhpStorage/FileStorage.php b/core/lib/Drupal/Component/PhpStorage/FileStorage.php index 67399ab8831a..33604f1b20be 100644 --- a/core/lib/Drupal/Component/PhpStorage/FileStorage.php +++ b/core/lib/Drupal/Component/PhpStorage/FileStorage.php @@ -97,7 +97,18 @@ SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006 EOF; if ($private) { - $lines = "Deny from all\n\n" . $lines; + $lines = << + Require all denied + + +# Deny all requests from Apache 2.0-2.2. + + Deny from all + +EOF + . $lines; } return $lines; diff --git a/core/modules/system/lib/Drupal/system/Tests/File/HtaccessUnitTest.php b/core/modules/system/lib/Drupal/system/Tests/File/HtaccessUnitTest.php index 4bc7f92a2895..66438b766e62 100644 --- a/core/modules/system/lib/Drupal/system/Tests/File/HtaccessUnitTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/File/HtaccessUnitTest.php @@ -44,6 +44,8 @@ class HtaccessUnitTest extends DrupalUnitTestBase { $this->assertTrue(file_save_htaccess($public, FALSE)); $content = file_get_contents($public . '/.htaccess'); $this->assertTrue(strpos($content, "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006") !== FALSE); + $this->assertFalse(strpos($content, "Require all denied") !== FALSE); + $this->assertFalse(strpos($content, "Deny from all") !== FALSE); $this->assertTrue(strpos($content, "Options None") !== FALSE); $this->assertTrue(strpos($content, "Options +FollowSymLinks") !== FALSE); $this->assertTrue(strpos($content, "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2013_003") !== FALSE); @@ -56,6 +58,7 @@ class HtaccessUnitTest extends DrupalUnitTestBase { $this->assertTrue(file_save_htaccess($private)); $content = file_get_contents($private . '/.htaccess'); $this->assertTrue(strpos($content, "SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006") !== FALSE); + $this->assertTrue(strpos($content, "Require all denied") !== FALSE); $this->assertTrue(strpos($content, "Deny from all") !== FALSE); $this->assertTrue(strpos($content, "Options None") !== FALSE); $this->assertTrue(strpos($content, "Options +FollowSymLinks") !== FALSE); @@ -69,6 +72,7 @@ class HtaccessUnitTest extends DrupalUnitTestBase { $this->assertTrue(file_save_htaccess($stream)); $content = file_get_contents($stream . '/.htaccess'); $this->assertTrue(strpos($content,"SetHandler Drupal_Security_Do_Not_Remove_See_SA_2006_006") !== FALSE); + $this->assertTrue(strpos($content, "Require all denied") !== FALSE); $this->assertTrue(strpos($content,"Deny from all") !== FALSE); $this->assertTrue(strpos($content,"Options None") !== FALSE); $this->assertTrue(strpos($content,"Options +FollowSymLinks") !== FALSE);