From 943dc631872a668b1ca86a8eb2c48e605e671acc Mon Sep 17 00:00:00 2001
From: Andreas Wolf <andreas.wolf@typo3.org>
Date: Sun, 19 Jul 2015 13:29:55 +0200
Subject: [PATCH] [BUGFIX] .htaccess created for log folder outside PATH_site
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Change-Id: I47d38033581a3ac71ee61d9607c708c01fe56743
Resolves: #68368
Releases: master, 6.2
Reviewed-on: https://review.typo3.org/41736
Reviewed-by: Oliver Eglseder <oliver.eglseder@in2code.de>
Tested-by: Bjoern Jacob <bjoern.jacob@tritum.de>
Reviewed-by: Steffen Müller <typo3@t3node.com>
Tested-by: Steffen Müller <typo3@t3node.com>
---
 .../core/Classes/Log/Writer/FileWriter.php    |  7 +++--
 .../Tests/Unit/Log/Writer/FileWriterTest.php  | 27 -------------------
 2 files changed, 5 insertions(+), 29 deletions(-)

diff --git a/typo3/sysext/core/Classes/Log/Writer/FileWriter.php b/typo3/sysext/core/Classes/Log/Writer/FileWriter.php
index 971373b82c17..891bb2c84dfa 100644
--- a/typo3/sysext/core/Classes/Log/Writer/FileWriter.php
+++ b/typo3/sysext/core/Classes/Log/Writer/FileWriter.php
@@ -191,8 +191,11 @@ class FileWriter extends AbstractWriter
         $logFileDirectory = dirname($this->logFile);
         if (!@is_dir($logFileDirectory)) {
             GeneralUtility::mkdir_deep($logFileDirectory);
-            // only create .htaccess, if we created the directory on our own
-            $this->createHtaccessFile($logFileDirectory . '/.htaccess');
+            // create .htaccess file if log file is within the site path
+            if (PathUtility::getCommonPrefix(array(PATH_site, $logFileDirectory)) === PATH_site) {
+                // only create .htaccess, if we created the directory on our own
+                $this->createHtaccessFile($logFileDirectory . '/.htaccess');
+            }
         }
         // create the log file
         GeneralUtility::writeFile($this->logFile, '');
diff --git a/typo3/sysext/core/Tests/Unit/Log/Writer/FileWriterTest.php b/typo3/sysext/core/Tests/Unit/Log/Writer/FileWriterTest.php
index 654a3c5c6063..f6bd074fc09d 100644
--- a/typo3/sysext/core/Tests/Unit/Log/Writer/FileWriterTest.php
+++ b/typo3/sysext/core/Tests/Unit/Log/Writer/FileWriterTest.php
@@ -186,31 +186,4 @@ class FileWriterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         $firstWriter->setLogFile($this->getDefaultFileName($logFilePrefix));
         $secondWriter->setLogFile($this->getDefaultFileName($logFilePrefix));
     }
-
-    /**
-     * @test
-     */
-    public function createsHtaccessForNewDirectory()
-    {
-        $this->setUpVfsStream();
-        $directory = $this->getUniqueId('Log');
-        $logFile = 'vfs://LogRoot/' . $directory . '/' . $this->logFileName;
-        $this->createWriter()->setLogFile($logFile);
-        $this->assertFileExists('vfs://LogRoot/' . $directory . '/.htaccess');
-    }
-
-    /**
-     * @test
-     */
-    public function createsNoHtaccessForExistingDirectory()
-    {
-        $this->setUpVfsStream();
-        $directory = $this->getUniqueId('Log');
-            // create a directory
-        vfsStreamWrapper::getRoot()->addChild(new vfsStreamDirectory($directory));
-        $logFile = 'vfs://LogRoot/' . $directory . '/' . $this->logFileName;
-        $this->assertTrue(is_dir('vfs://LogRoot/' . $directory));
-        $this->createWriter()->setLogFile($logFile);
-        $this->assertFileNotExists('vfs://LogRoot/' . $directory . '/.htaccess');
-    }
 }
-- 
GitLab